jdk/src/java.base/share/classes/java/util/Deque.java
author mchung
Fri, 22 May 2015 16:43:39 -0700
changeset 30789 9eca83469588
parent 25859 3317bb8137f4
child 32991 b27c76b82713
permissions -rw-r--r--
8074431: Remove native2ascii tool Reviewed-by: erikj, alanb, okutsu, mfang, naoto
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * questions.
2
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
9242
ef138d47df58 7034657: Update Creative Commons license URL in legal notices
dl
parents: 5506
diff changeset
    33
 * at http://creativecommons.org/publicdomain/zero/1.0/
2
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"
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    41
 * and is usually pronounced "deck".  Most {@code Deque}
2
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
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    50
 * special value (either {@code null} or {@code false}, depending on
2
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
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    53
 * {@code Deque} implementations; in most implementations, insert
2
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
 * <table BORDER CELLPADDING=3 CELLSPACING=1>
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    60
 * <caption>Summary of Deque methods</caption>
2
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>
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    75
 *    <td>{@link Deque#addFirst addFirst(e)}</td>
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    76
 *    <td>{@link Deque#offerFirst offerFirst(e)}</td>
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    77
 *    <td>{@link Deque#addLast addLast(e)}</td>
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    78
 *    <td>{@link Deque#offerLast offerLast(e)}</td>
2
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>
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    82
 *    <td>{@link Deque#removeFirst removeFirst()}</td>
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    83
 *    <td>{@link Deque#pollFirst pollFirst()}</td>
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    84
 *    <td>{@link Deque#removeLast removeLast()}</td>
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    85
 *    <td>{@link Deque#pollLast pollLast()}</td>
2
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>
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    89
 *    <td>{@link Deque#getFirst getFirst()}</td>
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    90
 *    <td>{@link Deque#peekFirst peekFirst()}</td>
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    91
 *    <td>{@link Deque#getLast getLast()}</td>
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    92
 *    <td>{@link Deque#peekLast peekLast()}</td>
2
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
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
    99
 * inherited from the {@code Queue} interface are precisely equivalent to
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   100
 * {@code Deque} methods as indicated in the following table:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <table BORDER CELLPADDING=3 CELLSPACING=1>
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   103
 * <caption>Comparison of Queue and Deque methods</caption>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *  <tr>
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   105
 *    <td ALIGN=CENTER> <b>{@code Queue} Method</b></td>
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   106
 *    <td ALIGN=CENTER> <b>Equivalent {@code Deque} Method</b></td>
2
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
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   138
 * {@code Deque} methods as indicated in the table below:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <table BORDER CELLPADDING=3 CELLSPACING=1>
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   141
 * <caption>Comparison of Stack and Deque methods</caption>
2
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>
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   144
 *    <td ALIGN=CENTER> <b>Equivalent {@code Deque} Method</b></td>
2
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
 *
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   171
 * <p>While {@code Deque} implementations are not strictly required
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * to prohibit the insertion of null elements, they are strongly
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   173
 * encouraged to do so.  Users of any {@code Deque} implementations
2
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
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   176
 * {@code null} is used as a special return value by various methods
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * to indicated that the deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   179
 * <p>{@code Deque} implementations generally do not define
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   180
 * element-based versions of the {@code equals} and {@code hashCode}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * methods, but instead inherit the identity-based versions from class
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   182
 * {@code Object}.
2
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
public interface Deque<E> extends Queue<E> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Inserts the specified element at the front of this deque if it is
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   196
     * possible to do so immediately without violating capacity restrictions,
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   197
     * throwing an {@code IllegalStateException} if no space is currently
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   198
     * available.  When using a capacity-restricted deque, it is generally
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   199
     * preferable to use method {@link #offerFirst}.
2
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
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   215
     * possible to do so immediately without violating capacity restrictions,
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   216
     * throwing an {@code IllegalStateException} if no space is currently
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   217
     * available.  When using a capacity-restricted deque, it is generally
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   218
     * preferable to use method {@link #offerLast}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <p>This method is equivalent to {@link #add}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param e the element to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @throws IllegalStateException if the element cannot be added at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *         time due to capacity restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    void addLast(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Inserts the specified element at the front of this deque unless it would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * violate capacity restrictions.  When using a capacity-restricted deque,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * this method is generally preferable to the {@link #addFirst} method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * which can fail to insert an element only by throwing an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param e the element to add
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   241
     * @return {@code true} if the element was added to this deque, else
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   242
     *         {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    boolean offerFirst(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Inserts the specified element at the end of this deque unless it would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * violate capacity restrictions.  When using a capacity-restricted deque,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * this method is generally preferable to the {@link #addLast} method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * which can fail to insert an element only by throwing an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param e the element to add
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   259
     * @return {@code true} if the element was added to this deque, else
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   260
     *         {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    boolean offerLast(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Retrieves and removes the first element of this deque.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * differs from {@link #pollFirst pollFirst} only in that it throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return the head of this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    E removeFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Retrieves and removes the last element of this deque.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * differs from {@link #pollLast pollLast} only in that it throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @return the tail of this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    E removeLast();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Retrieves and removes the first element of this deque,
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   292
     * or returns {@code null} if this deque is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   294
     * @return the head of this deque, or {@code null} if this deque is empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    E pollFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Retrieves and removes the last element of this deque,
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   300
     * or returns {@code null} if this deque is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   302
     * @return the tail of this deque, or {@code null} if this deque is empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    E pollLast();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * Retrieves, but does not remove, the first element of this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * This method differs from {@link #peekFirst peekFirst} only in that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * throws an exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @return the head of this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    E getFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Retrieves, but does not remove, the last element of this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * This method differs from {@link #peekLast peekLast} only in that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * throws an exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @return the tail of this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    E getLast();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Retrieves, but does not remove, the first element of this deque,
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   329
     * or returns {@code null} if this deque is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   331
     * @return the head of this deque, or {@code null} if this deque is empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    E peekFirst();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Retrieves, but does not remove, the last element of this deque,
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   337
     * or returns {@code null} if this deque is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   339
     * @return the tail of this deque, or {@code null} if this deque is empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    E peekLast();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Removes the first occurrence of the specified element from this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * If the deque does not contain the element, it is unchanged.
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   346
     * More formally, removes the first element {@code e} such that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * (if such an element exists).
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   349
     * Returns {@code true} if this deque contained the specified element
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * (or equivalently, if this deque changed as a result of the call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @param o element to be removed from this deque, if present
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   353
     * @return {@code true} if an element was removed as a result of this call
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @throws ClassCastException if the class of the specified element
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   355
     *         is incompatible with this deque
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   356
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @throws NullPointerException if the specified element is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   358
     *         deque does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   359
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    boolean removeFirstOccurrence(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Removes the last occurrence of the specified element from this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * If the deque does not contain the element, it is unchanged.
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   366
     * More formally, removes the last element {@code e} such that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * (if such an element exists).
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   369
     * Returns {@code true} if this deque contained the specified element
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * (or equivalently, if this deque changed as a result of the call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @param o element to be removed from this deque, if present
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   373
     * @return {@code true} if an element was removed as a result of this call
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @throws ClassCastException if the class of the specified element
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   375
     *         is incompatible with this deque
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   376
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @throws NullPointerException if the specified element is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   378
     *         deque does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   379
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    boolean removeLastOccurrence(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    // *** Queue methods ***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Inserts the specified element into the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * (in other words, at the tail of this deque) if it is possible to do so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * immediately without violating capacity restrictions, returning
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   389
     * {@code true} upon success and throwing an
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   390
     * {@code IllegalStateException} if no space is currently available.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * When using a capacity-restricted deque, it is generally preferable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * use {@link #offer(Object) offer}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * <p>This method is equivalent to {@link #addLast}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @param e the element to add
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   397
     * @return {@code true} (as specified by {@link Collection#add})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @throws IllegalStateException if the element cannot be added at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *         time due to capacity restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    boolean add(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Inserts the specified element into the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * (in other words, at the tail of this deque) if it is possible to do so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * immediately without violating capacity restrictions, returning
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   413
     * {@code true} upon success and {@code false} if no space is currently
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * available.  When using a capacity-restricted deque, this method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * generally preferable to the {@link #add} method, which can fail to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * insert an element only by throwing an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * <p>This method is equivalent to {@link #offerLast}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @param e the element to add
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   421
     * @return {@code true} if the element was added to this deque, else
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   422
     *         {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    boolean offer(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Retrieves and removes the head of the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * (in other words, the first element of this deque).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * This method differs from {@link #poll poll} only in that it throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * <p>This method is equivalent to {@link #removeFirst()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @return the head of the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    E remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * Retrieves and removes the head of the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * (in other words, the first element of this deque), or returns
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   448
     * {@code null} if this deque is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * <p>This method is equivalent to {@link #pollFirst()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   452
     * @return the first element of this deque, or {@code null} if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *         this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    E poll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * Retrieves, but does not remove, the head of the queue represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * this deque (in other words, the first element of this deque).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * This method differs from {@link #peek peek} only in that it throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * exception if this deque is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * <p>This method is equivalent to {@link #getFirst()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @return the head of the queue represented by this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    E element();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * Retrieves, but does not remove, the head of the queue represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * this deque (in other words, the first element of this deque), or
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   473
     * returns {@code null} if this deque is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * <p>This method is equivalent to {@link #peekFirst()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * @return the head of the queue represented by this deque, or
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   478
     *         {@code null} if this deque is empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    E peek();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    // *** Stack methods ***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * Pushes an element onto the stack represented by this deque (in other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * words, at the head of this deque) if it is possible to do so
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   488
     * immediately without violating capacity restrictions, throwing an
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   489
     * {@code IllegalStateException} if no space is currently available.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * <p>This method is equivalent to {@link #addFirst}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @param e the element to push
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @throws IllegalStateException if the element cannot be added at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *         time due to capacity restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *         prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *         deque does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *         element prevents it from being added to this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    void push(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Pops an element from the stack represented by this deque.  In other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * words, removes and returns the first element of this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * <p>This method is equivalent to {@link #removeFirst()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @return the element at the front of this deque (which is the top
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *         of the stack represented by this deque)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @throws NoSuchElementException if this deque is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    E pop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    // *** Collection methods ***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * Removes the first occurrence of the specified element from this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * If the deque does not contain the element, it is unchanged.
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   523
     * More formally, removes the first element {@code e} such that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * (if such an element exists).
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   526
     * Returns {@code true} if this deque contained the specified element
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * (or equivalently, if this deque changed as a result of the call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     *
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   529
     * <p>This method is equivalent to {@link #removeFirstOccurrence(Object)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @param o element to be removed from this deque, if present
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   532
     * @return {@code true} if an element was removed as a result of this call
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @throws ClassCastException if the class of the specified element
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   534
     *         is incompatible with this deque
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   535
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @throws NullPointerException if the specified element is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   537
     *         deque does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   538
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    boolean remove(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    /**
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   543
     * Returns {@code true} if this deque contains the specified element.
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   544
     * More formally, returns {@code true} if and only if this deque contains
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   545
     * at least one element {@code e} such that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * @param o element whose presence in this deque is to be tested
19187
5aa85bc92303 8022087: Fix doclint issues in j.u.Deque & Queue
chegar
parents: 9503
diff changeset
   549
     * @return {@code true} if this deque contains the specified element
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @throws ClassCastException if the type of the specified element
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   551
     *         is incompatible with this deque
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   552
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @throws NullPointerException if the specified element is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   554
     *         deque does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 9242
diff changeset
   555
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    boolean contains(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * Returns the number of elements in this deque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @return the number of elements in this deque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public int size();
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 proper sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * The elements will be returned in order from first (head) to last (tail).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @return an iterator over the elements in this deque in proper sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    Iterator<E> iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * Returns an iterator over the elements in this deque in reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * sequential order.  The elements will be returned in order from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * last (tail) to first (head).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @return an iterator over the elements in this deque in reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    Iterator<E> descendingIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
}