16232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson/*
22f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * Written by Doug Lea and Josh Bloch with assistance from members of
32f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * JCP JSR-166 Expert Group and released to the public domain, as explained
4a807b4d808d2591894daf13aab179b2e9c46a2f5Jesse Wilson * at http://creativecommons.org/publicdomain/zero/1.0/
56232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */
66232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
76232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilsonpackage java.util;
86232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
92f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson// BEGIN android-note
102f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson// removed link to collections framework docs
112f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson// END android-note
122f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
136232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson/**
142f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * A linear collection that supports element insertion and removal at
152f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * both ends.  The name <i>deque</i> is short for "double ended queue"
162f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * and is usually pronounced "deck".  Most <tt>Deque</tt>
172f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * implementations place no fixed limits on the number of elements
182f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * they may contain, but this interface supports capacity-restricted
192f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * deques as well as those with no fixed size limit.
202f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *
212f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>This interface defines methods to access the elements at both
222f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * ends of the deque.  Methods are provided to insert, remove, and
232f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * examine the element.  Each of these methods exists in two forms:
242f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * one throws an exception if the operation fails, the other returns a
252f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * special value (either <tt>null</tt> or <tt>false</tt>, depending on
262f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * the operation).  The latter form of the insert operation is
272f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * designed specifically for use with capacity-restricted
282f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <tt>Deque</tt> implementations; in most implementations, insert
292f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * operations cannot fail.
302f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *
312f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>The twelve methods described above are summarized in the
322f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * following table:
332f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *
342f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>
352f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <table BORDER CELLPADDING=3 CELLSPACING=1>
362f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
372f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td></td>
382f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td ALIGN=CENTER COLSPAN = 2> <b>First Element (Head)</b></td>
392f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td ALIGN=CENTER COLSPAN = 2> <b>Last Element (Tail)</b></td>
402f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
412f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
422f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td></td>
432f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td ALIGN=CENTER><em>Throws exception</em></td>
442f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td ALIGN=CENTER><em>Special value</em></td>
452f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td ALIGN=CENTER><em>Throws exception</em></td>
462f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td ALIGN=CENTER><em>Special value</em></td>
472f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
482f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
492f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td><b>Insert</b></td>
502f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #addFirst addFirst(e)}</td>
512f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #offerFirst offerFirst(e)}</td>
522f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #addLast addLast(e)}</td>
532f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #offerLast offerLast(e)}</td>
542f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
552f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
562f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td><b>Remove</b></td>
572f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #removeFirst removeFirst()}</td>
582f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #pollFirst pollFirst()}</td>
592f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #removeLast removeLast()}</td>
602f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #pollLast pollLast()}</td>
612f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
622f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
632f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td><b>Examine</b></td>
642f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #getFirst getFirst()}</td>
652f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #peekFirst peekFirst()}</td>
662f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #getLast getLast()}</td>
672f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #peekLast peekLast()}</td>
682f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
692f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * </table>
702f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *
712f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>This interface extends the {@link Queue} interface.  When a deque is
722f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * used as a queue, FIFO (First-In-First-Out) behavior results.  Elements are
732f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * added at the end of the deque and removed from the beginning.  The methods
742f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * inherited from the <tt>Queue</tt> interface are precisely equivalent to
752f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <tt>Deque</tt> methods as indicated in the following table:
762f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *
772f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>
782f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <table BORDER CELLPADDING=3 CELLSPACING=1>
792f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
802f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td ALIGN=CENTER> <b><tt>Queue</tt> Method</b></td>
812f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
822f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
832f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
842f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link java.util.Queue#add add(e)}</td>
852f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #addLast addLast(e)}</td>
862f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
872f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
882f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link java.util.Queue#offer offer(e)}</td>
892f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #offerLast offerLast(e)}</td>
902f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
912f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
922f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link java.util.Queue#remove remove()}</td>
932f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #removeFirst removeFirst()}</td>
942f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
952f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
962f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link java.util.Queue#poll poll()}</td>
972f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #pollFirst pollFirst()}</td>
982f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
992f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
1002f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link java.util.Queue#element element()}</td>
1012f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #getFirst getFirst()}</td>
1022f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
1032f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
1042f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link java.util.Queue#peek peek()}</td>
1052f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #peek peekFirst()}</td>
1062f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
1072f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * </table>
1082f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *
1092f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>Deques can also be used as LIFO (Last-In-First-Out) stacks.  This
1102f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * interface should be used in preference to the legacy {@link Stack} class.
1112f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * When a deque is used as a stack, elements are pushed and popped from the
1122f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * beginning of the deque.  Stack methods are precisely equivalent to
1132f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <tt>Deque</tt> methods as indicated in the table below:
1146232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson *
1152f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>
1162f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <table BORDER CELLPADDING=3 CELLSPACING=1>
1172f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
1182f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td ALIGN=CENTER> <b>Stack Method</b></td>
1192f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
1202f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
1212f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
1222f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #push push(e)}</td>
1232f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #addFirst addFirst(e)}</td>
1242f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
1252f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
1262f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #pop pop()}</td>
1272f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #removeFirst removeFirst()}</td>
1282f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
1292f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  <tr>
1302f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #peek peek()}</td>
1312f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *    <td>{@link #peekFirst peekFirst()}</td>
1322f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *  </tr>
1332f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * </table>
1346232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson *
1352f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>Note that the {@link #peek peek} method works equally well when
1362f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * a deque is used as a queue or a stack; in either case, elements are
1372f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * drawn from the beginning of the deque.
1386232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson *
1392f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>This interface provides two methods to remove interior
1402f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * elements, {@link #removeFirstOccurrence removeFirstOccurrence} and
1412f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * {@link #removeLastOccurrence removeLastOccurrence}.
1426232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson *
1432f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>Unlike the {@link List} interface, this interface does not
1442f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * provide support for indexed access to elements.
1452f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *
1462f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p>While <tt>Deque</tt> implementations are not strictly required
1472f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * to prohibit the insertion of null elements, they are strongly
1482f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * encouraged to do so.  Users of any <tt>Deque</tt> implementations
1492f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * that do allow null elements are strongly encouraged <i>not</i> to
1502f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * take advantage of the ability to insert nulls.  This is so because
1512f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <tt>null</tt> is used as a special return value by various methods
1522f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * to indicated that the deque is empty.
1532f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *
1542f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <p><tt>Deque</tt> implementations generally do not define
1552f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * element-based versions of the <tt>equals</tt> and <tt>hashCode</tt>
1562f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * methods, but instead inherit the identity-based versions from class
1572f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * <tt>Object</tt>.
1582f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson *
1592f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @author Doug Lea
1602f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @author Josh Bloch
1612f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @since  1.6
1622f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson * @param <E> the type of elements held in this collection
1636232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson */
1646232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
1652f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilsonpublic interface Deque<E> extends Queue<E> {
1666232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
1672f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Inserts the specified element at the front of this deque if it is
1682f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * possible to do so immediately without violating capacity restrictions.
1692f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * When using a capacity-restricted deque, it is generally preferable to
1702f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * use method {@link #offerFirst}.
1716232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
1722f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @param e the element to add
1732f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws IllegalStateException if the element cannot be added at this
1742f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         time due to capacity restrictions
1752f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws ClassCastException if the class of the specified element
1762f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         prevents it from being added to this deque
1772f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NullPointerException if the specified element is null and this
1782f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         deque does not permit null elements
1792f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws IllegalArgumentException if some property of the specified
1802f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         element prevents it from being added to this deque
1816232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
1826232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    void addFirst(E e);
1836232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
1846232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
1852f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Inserts the specified element at the end of this deque if it is
1862f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * possible to do so immediately without violating capacity restrictions.
1872f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * When using a capacity-restricted deque, it is generally preferable to
1882f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * use method {@link #offerLast}.
1896232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
1902f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <p>This method is equivalent to {@link #add}.
1912f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
1922f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @param e the element to add
1932f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws IllegalStateException if the element cannot be added at this
1942f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         time due to capacity restrictions
1952f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws ClassCastException if the class of the specified element
1962f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         prevents it from being added to this deque
1972f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NullPointerException if the specified element is null and this
1982f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         deque does not permit null elements
1992f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws IllegalArgumentException if some property of the specified
2002f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         element prevents it from being added to this deque
2016232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
2026232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    void addLast(E e);
2036232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
2046232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
2052f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Inserts the specified element at the front of this deque unless it would
2062f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * violate capacity restrictions.  When using a capacity-restricted deque,
2072f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * this method is generally preferable to the {@link #addFirst} method,
2082f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * which can fail to insert an element only by throwing an exception.
2096232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
2102f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @param e the element to add
2112f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return <tt>true</tt> if the element was added to this deque, else
2122f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         <tt>false</tt>
2132f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws ClassCastException if the class of the specified element
2142f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         prevents it from being added to this deque
2152f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NullPointerException if the specified element is null and this
2162f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         deque does not permit null elements
2172f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws IllegalArgumentException if some property of the specified
2182f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         element prevents it from being added to this deque
2196232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
2206232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    boolean offerFirst(E e);
2216232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
2226232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
2232f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Inserts the specified element at the end of this deque unless it would
2242f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * violate capacity restrictions.  When using a capacity-restricted deque,
2252f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * this method is generally preferable to the {@link #addLast} method,
2262f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * which can fail to insert an element only by throwing an exception.
2276232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
2282f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @param e the element to add
2292f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return <tt>true</tt> if the element was added to this deque, else
2302f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         <tt>false</tt>
2312f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws ClassCastException if the class of the specified element
2322f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         prevents it from being added to this deque
2332f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NullPointerException if the specified element is null and this
2342f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         deque does not permit null elements
2352f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws IllegalArgumentException if some property of the specified
2362f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         element prevents it from being added to this deque
2376232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
2386232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    boolean offerLast(E e);
2396232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
2406232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
2412f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves and removes the first element of this deque.  This method
2422f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * differs from {@link #pollFirst pollFirst} only in that it throws an
2432f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * exception if this deque is empty.
2446232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
2452f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the head of this deque
2462f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NoSuchElementException if this deque is empty
2476232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
2486232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    E removeFirst();
2496232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
2506232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
2512f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves and removes the last element of this deque.  This method
2522f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * differs from {@link #pollLast pollLast} only in that it throws an
2532f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * exception if this deque is empty.
2546232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
2552f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the tail of this deque
2562f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NoSuchElementException if this deque is empty
2576232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
2586232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    E removeLast();
2596232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
2606232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
2612f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves and removes the first element of this deque,
2622f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * or returns <tt>null</tt> if this deque is empty.
2636232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
2642f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the head of this deque, or <tt>null</tt> if this deque is empty
2656232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
2666232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    E pollFirst();
2676232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
2686232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
2692f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves and removes the last element of this deque,
2702f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * or returns <tt>null</tt> if this deque is empty.
2716232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
2722f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
2736232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
2746232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    E pollLast();
2756232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
2766232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
2772f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves, but does not remove, the first element of this deque.
2782f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
2792f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * This method differs from {@link #peekFirst peekFirst} only in that it
2802f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * throws an exception if this deque is empty.
2816232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
2822f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the head of this deque
2832f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NoSuchElementException if this deque is empty
2846232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
2856232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    E getFirst();
2866232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
2876232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
2882f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves, but does not remove, the last element of this deque.
2892f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * This method differs from {@link #peekLast peekLast} only in that it
2902f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * throws an exception if this deque is empty.
2916232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
2922f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the tail of this deque
2932f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NoSuchElementException if this deque is empty
2946232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
2956232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    E getLast();
2966232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
2976232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
2982f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves, but does not remove, the first element of this deque,
2992f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * or returns <tt>null</tt> if this deque is empty.
3006232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
3012f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the head of this deque, or <tt>null</tt> if this deque is empty
3026232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
3036232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    E peekFirst();
3046232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
3056232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
3062f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves, but does not remove, the last element of this deque,
3072f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * or returns <tt>null</tt> if this deque is empty.
3086232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
3092f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
3106232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
3116232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    E peekLast();
3126232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
3136232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
3142f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Removes the first occurrence of the specified element from this deque.
3152f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * If the deque does not contain the element, it is unchanged.
3162f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * More formally, removes the first element <tt>e</tt> such that
3172f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
3182f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * (if such an element exists).
3192f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Returns <tt>true</tt> if this deque contained the specified element
3202f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * (or equivalently, if this deque changed as a result of the call).
3216232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
3222f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @param o element to be removed from this deque, if present
3232f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return <tt>true</tt> if an element was removed as a result of this call
3242f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws ClassCastException if the class of the specified element
3252f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         is incompatible with this deque (optional)
3262f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NullPointerException if the specified element is null and this
3272f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         deque does not permit null elements (optional)
3286232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
3296232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    boolean removeFirstOccurrence(Object o);
3306232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
3316232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
3322f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Removes the last occurrence of the specified element from this deque.
3332f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * If the deque does not contain the element, it is unchanged.
3342f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * More formally, removes the last element <tt>e</tt> such that
3352f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
3362f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * (if such an element exists).
3372f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Returns <tt>true</tt> if this deque contained the specified element
3382f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * (or equivalently, if this deque changed as a result of the call).
3396232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
3402f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @param o element to be removed from this deque, if present
3412f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return <tt>true</tt> if an element was removed as a result of this call
3422f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws ClassCastException if the class of the specified element
3432f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         is incompatible with this deque (optional)
3442f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NullPointerException if the specified element is null and this
3452f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         deque does not permit null elements (optional)
3466232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
3476232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    boolean removeLastOccurrence(Object o);
3486232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
3492f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    // *** Queue methods ***
3502f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
3512f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    /**
3522f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Inserts the specified element into the queue represented by this deque
3532f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * (in other words, at the tail of this deque) if it is possible to do so
3542f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * immediately without violating capacity restrictions, returning
3552f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <tt>true</tt> upon success and throwing an
3562f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <tt>IllegalStateException</tt> if no space is currently available.
3572f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * When using a capacity-restricted deque, it is generally preferable to
358a807b4d808d2591894daf13aab179b2e9c46a2f5Jesse Wilson     * use {@link #offer(Object) offer}.
3592f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
3602f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <p>This method is equivalent to {@link #addLast}.
3612f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
3622f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @param e the element to add
3632f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return <tt>true</tt> (as specified by {@link Collection#add})
3642f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws IllegalStateException if the element cannot be added at this
3652f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         time due to capacity restrictions
3662f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws ClassCastException if the class of the specified element
3672f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         prevents it from being added to this deque
3682f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NullPointerException if the specified element is null and this
3692f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         deque does not permit null elements
3702f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws IllegalArgumentException if some property of the specified
3712f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         element prevents it from being added to this deque
3722f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     */
3732f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    boolean add(E e);
3742f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
3752f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    /**
3762f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Inserts the specified element into the queue represented by this deque
3772f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * (in other words, at the tail of this deque) if it is possible to do so
3782f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * immediately without violating capacity restrictions, returning
3792f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <tt>true</tt> upon success and <tt>false</tt> if no space is currently
3802f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * available.  When using a capacity-restricted deque, this method is
3812f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * generally preferable to the {@link #add} method, which can fail to
3822f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * insert an element only by throwing an exception.
3832f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
3842f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <p>This method is equivalent to {@link #offerLast}.
3852f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
3862f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @param e the element to add
3872f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return <tt>true</tt> if the element was added to this deque, else
3882f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         <tt>false</tt>
3892f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws ClassCastException if the class of the specified element
3902f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         prevents it from being added to this deque
3912f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NullPointerException if the specified element is null and this
3922f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         deque does not permit null elements
3932f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws IllegalArgumentException if some property of the specified
3942f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         element prevents it from being added to this deque
3952f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     */
3962f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    boolean offer(E e);
3972f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
3986232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
3992f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves and removes the head of the queue represented by this deque
4002f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * (in other words, the first element of this deque).
4012f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * This method differs from {@link #poll poll} only in that it throws an
4022f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * exception if this deque is empty.
4036232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
4042f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <p>This method is equivalent to {@link #removeFirst()}.
4052f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
4062f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the head of the queue represented by this deque
4072f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NoSuchElementException if this deque is empty
4082f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     */
4092f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    E remove();
4102f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
4112f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    /**
4122f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves and removes the head of the queue represented by this deque
4132f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * (in other words, the first element of this deque), or returns
4142f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <tt>null</tt> if this deque is empty.
4152f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
4162f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <p>This method is equivalent to {@link #pollFirst()}.
4172f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
4182f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the first element of this deque, or <tt>null</tt> if
4192f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         this deque is empty
4202f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     */
4212f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    E poll();
4222f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
4232f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    /**
4242f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves, but does not remove, the head of the queue represented by
4252f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * this deque (in other words, the first element of this deque).
4262f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * This method differs from {@link #peek peek} only in that it throws an
4272f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * exception if this deque is empty.
4282f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
4292f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <p>This method is equivalent to {@link #getFirst()}.
4302f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
4312f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the head of the queue represented by this deque
4322f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NoSuchElementException if this deque is empty
4332f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     */
4342f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    E element();
4352f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
4362f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    /**
4372f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Retrieves, but does not remove, the head of the queue represented by
4382f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * this deque (in other words, the first element of this deque), or
4392f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * returns <tt>null</tt> if this deque is empty.
4402f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
4412f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <p>This method is equivalent to {@link #peekFirst()}.
4422f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
4432f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the head of the queue represented by this deque, or
4442f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         <tt>null</tt> if this deque is empty
4452f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     */
4462f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    E peek();
4472f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
4482f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
4492f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    // *** Stack methods ***
4502f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
4512f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    /**
4522f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Pushes an element onto the stack represented by this deque (in other
4532f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * words, at the head of this deque) if it is possible to do so
4542f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * immediately without violating capacity restrictions, returning
4552f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <tt>true</tt> upon success and throwing an
4562f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <tt>IllegalStateException</tt> if no space is currently available.
4572f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
4582f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <p>This method is equivalent to {@link #addFirst}.
4592f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
4602f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @param e the element to push
4612f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws IllegalStateException if the element cannot be added at this
4622f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         time due to capacity restrictions
4632f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws ClassCastException if the class of the specified element
4642f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         prevents it from being added to this deque
4652f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NullPointerException if the specified element is null and this
4662f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         deque does not permit null elements
4672f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws IllegalArgumentException if some property of the specified
4682f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         element prevents it from being added to this deque
4696232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
4706232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    void push(E e);
4716232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
4726232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
4732f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Pops an element from the stack represented by this deque.  In other
4742f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * words, removes and returns the first element of this deque.
4756232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
4762f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <p>This method is equivalent to {@link #removeFirst()}.
4772f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
4782f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the element at the front of this deque (which is the top
4792f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         of the stack represented by this deque)
4802f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NoSuchElementException if this deque is empty
4816232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
4826232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    E pop();
4836232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson
4842f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
4852f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    // *** Collection methods ***
4862f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
4876232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    /**
4882f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Removes the first occurrence of the specified element from this deque.
4892f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * If the deque does not contain the element, it is unchanged.
4902f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * More formally, removes the first element <tt>e</tt> such that
4912f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
4922f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * (if such an element exists).
4932f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Returns <tt>true</tt> if this deque contained the specified element
4942f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * (or equivalently, if this deque changed as a result of the call).
4952f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
4962f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <p>This method is equivalent to {@link #removeFirstOccurrence}.
4976232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     *
4982f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @param o element to be removed from this deque, if present
4992f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return <tt>true</tt> if an element was removed as a result of this call
5002f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws ClassCastException if the class of the specified element
5012f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         is incompatible with this deque (optional)
5022f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NullPointerException if the specified element is null and this
5032f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         deque does not permit null elements (optional)
5042f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     */
5052f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    boolean remove(Object o);
5062f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
5072f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    /**
5082f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Returns <tt>true</tt> if this deque contains the specified element.
5092f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * More formally, returns <tt>true</tt> if and only if this deque contains
5102f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * at least one element <tt>e</tt> such that
5112f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
5122f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
5132f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @param o element whose presence in this deque is to be tested
5142f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return <tt>true</tt> if this deque contains the specified element
5152f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws ClassCastException if the type of the specified element
5162f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         is incompatible with this deque (optional)
5172f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @throws NullPointerException if the specified element is null and this
5182f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *         deque does not permit null elements (optional)
5192f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     */
5202f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    boolean contains(Object o);
5212f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
5222f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    /**
5232f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Returns the number of elements in this deque.
5242f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
5252f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return the number of elements in this deque
5262f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     */
5272f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    public int size();
5282f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
5292f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    /**
5302f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Returns an iterator over the elements in this deque in proper sequence.
5312f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * The elements will be returned in order from first (head) to last (tail).
5322f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
5332f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return an iterator over the elements in this deque in proper sequence
5342f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     */
5352f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    Iterator<E> iterator();
5362f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
5372f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson    /**
5382f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * Returns an iterator over the elements in this deque in reverse
5392f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * sequential order.  The elements will be returned in order from
5402f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * last (tail) to first (head).
5412f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     *
5422f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * @return an iterator over the elements in this deque in reverse
5432f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson     * sequence
5446232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson     */
5456232a5efed0ea103e35aec73206e5e03a8b82e0cJesse Wilson    Iterator<E> descendingIterator();
5462f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson
5472f03027aaa09158ac70ebf9c6b53f7bb8c495541Jesse Wilson}
548