jdk/src/share/classes/java/util/Deque.java
author jjb
Wed, 29 Jul 2009 14:24:19 -0700
changeset 3420 bba8035eebfa
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6804124: Replace "modified mergesort" in java.util.Arrays.sort with timsort Summary: Easy port of timsort from android Reviewed-by: martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Written by Doug Lea and Josh Bloch with assistance from members of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * JCP JSR-166 Expert Group and released to the public domain, as explained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * at http://creativecommons.org/licenses/publicdomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * A linear collection that supports element insertion and removal at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * both ends.  The name <i>deque</i> is short for "double ended queue"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * and is usually pronounced "deck".  Most <tt>Deque</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * implementations place no fixed limits on the number of elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * they may contain, but this interface supports capacity-restricted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * deques as well as those with no fixed size limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>This interface defines methods to access the elements at both
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * ends of the deque.  Methods are provided to insert, remove, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * examine the element.  Each of these methods exists in two forms:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * one throws an exception if the operation fails, the other returns a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * special value (either <tt>null</tt> or <tt>false</tt>, depending on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the operation).  The latter form of the insert operation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * designed specifically for use with capacity-restricted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <tt>Deque</tt> implementations; in most implementations, insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * operations cannot fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>The twelve methods described above are summarized in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * following table:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <table BORDER CELLPADDING=3 CELLSPACING=1>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *    <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *    <td ALIGN=CENTER COLSPAN = 2> <b>First Element (Head)</b></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *    <td ALIGN=CENTER COLSPAN = 2> <b>Last Element (Tail)</b></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *    <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *    <td ALIGN=CENTER><em>Throws exception</em></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *    <td ALIGN=CENTER><em>Special value</em></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *    <td ALIGN=CENTER><em>Throws exception</em></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *    <td ALIGN=CENTER><em>Special value</em></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *    <td><b>Insert</b></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *    <td>{@link #addFirst addFirst(e)}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *    <td>{@link #offerFirst offerFirst(e)}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *    <td>{@link #addLast addLast(e)}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *    <td>{@link #offerLast offerLast(e)}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *    <td><b>Remove</b></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *    <td>{@link #removeFirst removeFirst()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *    <td>{@link #pollFirst pollFirst()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *    <td>{@link #removeLast removeLast()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *    <td>{@link #pollLast pollLast()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *    <td><b>Examine</b></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *    <td>{@link #getFirst getFirst()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *    <td>{@link #peekFirst peekFirst()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *    <td>{@link #getLast getLast()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *    <td>{@link #peekLast peekLast()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <p>This interface extends the {@link Queue} interface.  When a deque is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * used as a queue, FIFO (First-In-First-Out) behavior results.  Elements are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * added at the end of the deque and removed from the beginning.  The methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * inherited from the <tt>Queue</tt> interface are precisely equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <tt>Deque</tt> methods as indicated in the following table:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * <table BORDER CELLPADDING=3 CELLSPACING=1>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *    <td ALIGN=CENTER> <b><tt>Queue</tt> Method</b></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *    <td>{@link java.util.Queue#add add(e)}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *    <td>{@link #addLast addLast(e)}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *    <td>{@link java.util.Queue#offer offer(e)}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *    <td>{@link #offerLast offerLast(e)}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *    <td>{@link java.util.Queue#remove remove()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *    <td>{@link #removeFirst removeFirst()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *    <td>{@link java.util.Queue#poll poll()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *    <td>{@link #pollFirst pollFirst()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *    <td>{@link java.util.Queue#element element()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *    <td>{@link #getFirst getFirst()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *    <td>{@link java.util.Queue#peek peek()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *    <td>{@link #peek peekFirst()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * <p>Deques can also be used as LIFO (Last-In-First-Out) stacks.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * interface should be used in preference to the legacy {@link Stack} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * When a deque is used as a stack, elements are pushed and popped from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * beginning of the deque.  Stack methods are precisely equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * <tt>Deque</tt> methods as indicated in the table below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <table BORDER CELLPADDING=3 CELLSPACING=1>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 *    <td ALIGN=CENTER> <b>Stack Method</b></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *    <td>{@link #push push(e)}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *    <td>{@link #addFirst addFirst(e)}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *    <td>{@link #pop pop()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *    <td>{@link #removeFirst removeFirst()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *    <td>{@link #peek peek()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *    <td>{@link #peekFirst peekFirst()}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * <p>Note that the {@link #peek peek} method works equally well when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * a deque is used as a queue or a stack; in either case, elements are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * drawn from the beginning of the deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * <p>This interface provides two methods to remove interior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * elements, {@link #removeFirstOccurrence removeFirstOccurrence} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * {@link #removeLastOccurrence removeLastOccurrence}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * <p>Unlike the {@link List} interface, this interface does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * provide support for indexed access to elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * <p>While <tt>Deque</tt> implementations are not strictly required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * to prohibit the insertion of null elements, they are strongly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * encouraged to do so.  Users of any <tt>Deque</tt> implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * that do allow null elements are strongly encouraged <i>not</i> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * take advantage of the ability to insert nulls.  This is so because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * <tt>null</tt> is used as a special return value by various methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * to indicated that the deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * <p><tt>Deque</tt> implementations generally do not define
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * element-based versions of the <tt>equals</tt> and <tt>hashCode</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * methods, but instead inherit the identity-based versions from class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * <tt>Object</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * <p>This interface is a member of the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * Framework</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * @author Doug Lea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * @author Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * @since  1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * @param <E> the type of elements held in this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
public interface Deque<E> extends Queue<E> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Inserts the specified element at the front of this deque if it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * possible to do so immediately without violating capacity restrictions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * When using a capacity-restricted deque, it is generally preferable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * use method {@link #offerFirst}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param e the element to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @throws IllegalStateException if the element cannot be added at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *         time due to capacity restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    void addFirst(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Inserts the specified element at the end of this deque if it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * possible to do so immediately without violating capacity restrictions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * When using a capacity-restricted deque, it is generally preferable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * use method {@link #offerLast}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <p>This method is equivalent to {@link #add}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param e the element to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @throws IllegalStateException if the element cannot be added at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *         time due to capacity restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    void addLast(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Inserts the specified element at the front of this deque unless it would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * violate capacity restrictions.  When using a capacity-restricted deque,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * this method is generally preferable to the {@link #addFirst} method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * which can fail to insert an element only by throwing an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param e the element to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @return <tt>true</tt> if the element was added to this deque, else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *         <tt>false</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    boolean offerFirst(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Inserts the specified element at the end of this deque unless it would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * violate capacity restrictions.  When using a capacity-restricted deque,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * this method is generally preferable to the {@link #addLast} method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * which can fail to insert an element only by throwing an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param e the element to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return <tt>true</tt> if the element was added to this deque, else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *         <tt>false</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    boolean offerLast(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Retrieves and removes the first element of this deque.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * differs from {@link #pollFirst pollFirst} only in that it throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @return the head of this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    E removeFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Retrieves and removes the last element of this deque.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * differs from {@link #pollLast pollLast} only in that it throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @return the tail of this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    E removeLast();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Retrieves and removes the first element of this deque,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * or returns <tt>null</tt> if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @return the head of this deque, or <tt>null</tt> if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    E pollFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Retrieves and removes the last element of this deque,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * or returns <tt>null</tt> if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    E pollLast();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Retrieves, but does not remove, the first element of this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * This method differs from {@link #peekFirst peekFirst} only in that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * throws an exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @return the head of this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    E getFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Retrieves, but does not remove, the last element of this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * This method differs from {@link #peekLast peekLast} only in that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * throws an exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @return the tail of this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    E getLast();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Retrieves, but does not remove, the first element of this deque,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * or returns <tt>null</tt> if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @return the head of this deque, or <tt>null</tt> if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    E peekFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Retrieves, but does not remove, the last element of this deque,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * or returns <tt>null</tt> if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    E peekLast();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Removes the first occurrence of the specified element from this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * If the deque does not contain the element, it is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * More formally, removes the first element <tt>e</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * (if such an element exists).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Returns <tt>true</tt> if this deque contained the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * (or equivalently, if this deque changed as a result of the call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param o element to be removed from this deque, if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @return <tt>true</tt> if an element was removed as a result of this call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *         is incompatible with this deque (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *         deque does not permit null elements (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    boolean removeFirstOccurrence(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Removes the last occurrence of the specified element from this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * If the deque does not contain the element, it is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * More formally, removes the last element <tt>e</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * (if such an element exists).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Returns <tt>true</tt> if this deque contained the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * (or equivalently, if this deque changed as a result of the call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @param o element to be removed from this deque, if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @return <tt>true</tt> if an element was removed as a result of this call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *         is incompatible with this deque (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *         deque does not permit null elements (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    boolean removeLastOccurrence(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    // *** Queue methods ***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * Inserts the specified element into the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * (in other words, at the tail of this deque) if it is possible to do so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * immediately without violating capacity restrictions, returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * <tt>true</tt> upon success and throwing an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * <tt>IllegalStateException</tt> if no space is currently available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * When using a capacity-restricted deque, it is generally preferable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * use {@link #offer(Object) offer}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * <p>This method is equivalent to {@link #addLast}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param e the element to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @return <tt>true</tt> (as specified by {@link Collection#add})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @throws IllegalStateException if the element cannot be added at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *         time due to capacity restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    boolean add(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Inserts the specified element into the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * (in other words, at the tail of this deque) if it is possible to do so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * immediately without violating capacity restrictions, returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * <tt>true</tt> upon success and <tt>false</tt> if no space is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * available.  When using a capacity-restricted deque, this method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * generally preferable to the {@link #add} method, which can fail to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * insert an element only by throwing an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * <p>This method is equivalent to {@link #offerLast}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @param e the element to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @return <tt>true</tt> if the element was added to this deque, else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *         <tt>false</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    boolean offer(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * Retrieves and removes the head of the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * (in other words, the first element of this deque).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * This method differs from {@link #poll poll} only in that it throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <p>This method is equivalent to {@link #removeFirst()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @return the head of the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    E remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Retrieves and removes the head of the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * (in other words, the first element of this deque), or returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * <tt>null</tt> if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * <p>This method is equivalent to {@link #pollFirst()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @return the first element of this deque, or <tt>null</tt> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *         this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    E poll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Retrieves, but does not remove, the head of the queue represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * this deque (in other words, the first element of this deque).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * This method differs from {@link #peek peek} only in that it throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * <p>This method is equivalent to {@link #getFirst()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @return the head of the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    E element();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * Retrieves, but does not remove, the head of the queue represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * this deque (in other words, the first element of this deque), or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * returns <tt>null</tt> if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * <p>This method is equivalent to {@link #peekFirst()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @return the head of the queue represented by this deque, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *         <tt>null</tt> if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    E peek();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    // *** Stack methods ***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Pushes an element onto the stack represented by this deque (in other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * words, at the head of this deque) if it is possible to do so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * immediately without violating capacity restrictions, returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * <tt>true</tt> upon success and throwing an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * <tt>IllegalStateException</tt> if no space is currently available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * <p>This method is equivalent to {@link #addFirst}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @param e the element to push
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @throws IllegalStateException if the element cannot be added at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *         time due to capacity restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    void push(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * Pops an element from the stack represented by this deque.  In other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * words, removes and returns the first element of this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * <p>This method is equivalent to {@link #removeFirst()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @return the element at the front of this deque (which is the top
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *         of the stack represented by this deque)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    E pop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    // *** Collection methods ***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Removes the first occurrence of the specified element from this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * If the deque does not contain the element, it is unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * More formally, removes the first element <tt>e</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * (if such an element exists).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * Returns <tt>true</tt> if this deque contained the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * (or equivalently, if this deque changed as a result of the call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * <p>This method is equivalent to {@link #removeFirstOccurrence}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @param o element to be removed from this deque, if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @return <tt>true</tt> if an element was removed as a result of this call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *         is incompatible with this deque (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *         deque does not permit null elements (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    boolean remove(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * Returns <tt>true</tt> if this deque contains the specified element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * More formally, returns <tt>true</tt> if and only if this deque contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * at least one element <tt>e</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @param o element whose presence in this deque is to be tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @return <tt>true</tt> if this deque contains the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @throws ClassCastException if the type of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *         is incompatible with this deque (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     *         deque does not permit null elements (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    boolean contains(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * Returns the number of elements in this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @return the number of elements in this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    public int size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * Returns an iterator over the elements in this deque in proper sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * The elements will be returned in order from first (head) to last (tail).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @return an iterator over the elements in this deque in proper sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    Iterator<E> iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * Returns an iterator over the elements in this deque in reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * sequential order.  The elements will be returned in order from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * last (tail) to first (head).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @return an iterator over the elements in this deque in reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    Iterator<E> descendingIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
}