jdk/src/java.base/share/classes/java/util/Deque.java
changeset 32991 b27c76b82713
parent 25859 3317bb8137f4
child 36955 737dcba2ba50
equal deleted inserted replaced
32990:299a81977f48 32991:b27c76b82713
   186  * Framework</a>.
   186  * Framework</a>.
   187  *
   187  *
   188  * @author Doug Lea
   188  * @author Doug Lea
   189  * @author Josh Bloch
   189  * @author Josh Bloch
   190  * @since  1.6
   190  * @since  1.6
   191  * @param <E> the type of elements held in this collection
   191  * @param <E> the type of elements held in this deque
   192  */
   192  */
   193 public interface Deque<E> extends Queue<E> {
   193 public interface Deque<E> extends Queue<E> {
   194     /**
   194     /**
   195      * Inserts the specified element at the front of this deque if it is
   195      * Inserts the specified element at the front of this deque if it is
   196      * possible to do so immediately without violating capacity restrictions,
   196      * possible to do so immediately without violating capacity restrictions,
   342 
   342 
   343     /**
   343     /**
   344      * Removes the first occurrence of the specified element from this deque.
   344      * Removes the first occurrence of the specified element from this deque.
   345      * If the deque does not contain the element, it is unchanged.
   345      * If the deque does not contain the element, it is unchanged.
   346      * More formally, removes the first element {@code e} such that
   346      * More formally, removes the first element {@code e} such that
   347      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
   347      * {@code Objects.equals(o, e)} (if such an element exists).
   348      * (if such an element exists).
       
   349      * Returns {@code true} if this deque contained the specified element
   348      * Returns {@code true} if this deque contained the specified element
   350      * (or equivalently, if this deque changed as a result of the call).
   349      * (or equivalently, if this deque changed as a result of the call).
   351      *
   350      *
   352      * @param o element to be removed from this deque, if present
   351      * @param o element to be removed from this deque, if present
   353      * @return {@code true} if an element was removed as a result of this call
   352      * @return {@code true} if an element was removed as a result of this call
   354      * @throws ClassCastException if the class of the specified element
   353      * @throws ClassCastException if the class of the specified element
   355      *         is incompatible with this deque
   354      *         is incompatible with this deque
   356      * (<a href="Collection.html#optional-restrictions">optional</a>)
   355      * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
   357      * @throws NullPointerException if the specified element is null and this
   356      * @throws NullPointerException if the specified element is null and this
   358      *         deque does not permit null elements
   357      *         deque does not permit null elements
   359      * (<a href="Collection.html#optional-restrictions">optional</a>)
   358      * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
   360      */
   359      */
   361     boolean removeFirstOccurrence(Object o);
   360     boolean removeFirstOccurrence(Object o);
   362 
   361 
   363     /**
   362     /**
   364      * Removes the last occurrence of the specified element from this deque.
   363      * Removes the last occurrence of the specified element from this deque.
   365      * If the deque does not contain the element, it is unchanged.
   364      * If the deque does not contain the element, it is unchanged.
   366      * More formally, removes the last element {@code e} such that
   365      * More formally, removes the last element {@code e} such that
   367      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
   366      * {@code Objects.equals(o, e)} (if such an element exists).
   368      * (if such an element exists).
       
   369      * Returns {@code true} if this deque contained the specified element
   367      * Returns {@code true} if this deque contained the specified element
   370      * (or equivalently, if this deque changed as a result of the call).
   368      * (or equivalently, if this deque changed as a result of the call).
   371      *
   369      *
   372      * @param o element to be removed from this deque, if present
   370      * @param o element to be removed from this deque, if present
   373      * @return {@code true} if an element was removed as a result of this call
   371      * @return {@code true} if an element was removed as a result of this call
   374      * @throws ClassCastException if the class of the specified element
   372      * @throws ClassCastException if the class of the specified element
   375      *         is incompatible with this deque
   373      *         is incompatible with this deque
   376      * (<a href="Collection.html#optional-restrictions">optional</a>)
   374      * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
   377      * @throws NullPointerException if the specified element is null and this
   375      * @throws NullPointerException if the specified element is null and this
   378      *         deque does not permit null elements
   376      *         deque does not permit null elements
   379      * (<a href="Collection.html#optional-restrictions">optional</a>)
   377      * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
   380      */
   378      */
   381     boolean removeLastOccurrence(Object o);
   379     boolean removeLastOccurrence(Object o);
   382 
   380 
   383     // *** Queue methods ***
   381     // *** Queue methods ***
   384 
   382 
   519 
   517 
   520     /**
   518     /**
   521      * Removes the first occurrence of the specified element from this deque.
   519      * Removes the first occurrence of the specified element from this deque.
   522      * If the deque does not contain the element, it is unchanged.
   520      * If the deque does not contain the element, it is unchanged.
   523      * More formally, removes the first element {@code e} such that
   521      * More formally, removes the first element {@code e} such that
   524      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
   522      * {@code Objects.equals(o, e)} (if such an element exists).
   525      * (if such an element exists).
       
   526      * Returns {@code true} if this deque contained the specified element
   523      * Returns {@code true} if this deque contained the specified element
   527      * (or equivalently, if this deque changed as a result of the call).
   524      * (or equivalently, if this deque changed as a result of the call).
   528      *
   525      *
   529      * <p>This method is equivalent to {@link #removeFirstOccurrence(Object)}.
   526      * <p>This method is equivalent to {@link #removeFirstOccurrence(Object)}.
   530      *
   527      *
   531      * @param o element to be removed from this deque, if present
   528      * @param o element to be removed from this deque, if present
   532      * @return {@code true} if an element was removed as a result of this call
   529      * @return {@code true} if an element was removed as a result of this call
   533      * @throws ClassCastException if the class of the specified element
   530      * @throws ClassCastException if the class of the specified element
   534      *         is incompatible with this deque
   531      *         is incompatible with this deque
   535      * (<a href="Collection.html#optional-restrictions">optional</a>)
   532      * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
   536      * @throws NullPointerException if the specified element is null and this
   533      * @throws NullPointerException if the specified element is null and this
   537      *         deque does not permit null elements
   534      *         deque does not permit null elements
   538      * (<a href="Collection.html#optional-restrictions">optional</a>)
   535      * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
   539      */
   536      */
   540     boolean remove(Object o);
   537     boolean remove(Object o);
   541 
   538 
   542     /**
   539     /**
   543      * Returns {@code true} if this deque contains the specified element.
   540      * Returns {@code true} if this deque contains the specified element.
   544      * More formally, returns {@code true} if and only if this deque contains
   541      * More formally, returns {@code true} if and only if this deque contains
   545      * at least one element {@code e} such that
   542      * at least one element {@code e} such that {@code Objects.equals(o, e)}.
   546      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
       
   547      *
   543      *
   548      * @param o element whose presence in this deque is to be tested
   544      * @param o element whose presence in this deque is to be tested
   549      * @return {@code true} if this deque contains the specified element
   545      * @return {@code true} if this deque contains the specified element
   550      * @throws ClassCastException if the type of the specified element
   546      * @throws ClassCastException if the class of the specified element
   551      *         is incompatible with this deque
   547      *         is incompatible with this deque
   552      * (<a href="Collection.html#optional-restrictions">optional</a>)
   548      * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
   553      * @throws NullPointerException if the specified element is null and this
   549      * @throws NullPointerException if the specified element is null and this
   554      *         deque does not permit null elements
   550      *         deque does not permit null elements
   555      * (<a href="Collection.html#optional-restrictions">optional</a>)
   551      * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
   556      */
   552      */
   557     boolean contains(Object o);
   553     boolean contains(Object o);
   558 
   554 
   559     /**
   555     /**
   560      * Returns the number of elements in this deque.
   556      * Returns the number of elements in this deque.
   561      *
   557      *
   562      * @return the number of elements in this deque
   558      * @return the number of elements in this deque
   563      */
   559      */
   564     public int size();
   560     int size();
   565 
   561 
   566     /**
   562     /**
   567      * Returns an iterator over the elements in this deque in proper sequence.
   563      * Returns an iterator over the elements in this deque in proper sequence.
   568      * The elements will be returned in order from first (head) to last (tail).
   564      * The elements will be returned in order from first (head) to last (tail).
   569      *
   565      *