src/share/classes/java/util/Deque.java

Print this page
rev 3977 : 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.


 334     /**
 335      * Retrieves, but does not remove, the last element of this deque,
 336      * or returns <tt>null</tt> if this deque is empty.
 337      *
 338      * @return the tail of this deque, or <tt>null</tt> if this deque is empty
 339      */
 340     E peekLast();
 341 
 342     /**
 343      * Removes the first occurrence of the specified element from this deque.
 344      * If the deque does not contain the element, it is unchanged.
 345      * More formally, removes the first element <tt>e</tt> such that
 346      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
 347      * (if such an element exists).
 348      * Returns <tt>true</tt> if this deque contained the specified element
 349      * (or equivalently, if this deque changed as a result of the call).
 350      *
 351      * @param o element to be removed from this deque, if present
 352      * @return <tt>true</tt> if an element was removed as a result of this call
 353      * @throws ClassCastException if the class of the specified element
 354      *         is incompatible with this deque (optional)

 355      * @throws NullPointerException if the specified element is null and this
 356      *         deque does not permit null elements (optional)

 357      */
 358     boolean removeFirstOccurrence(Object o);
 359 
 360     /**
 361      * Removes the last occurrence of the specified element from this deque.
 362      * If the deque does not contain the element, it is unchanged.
 363      * More formally, removes the last element <tt>e</tt> such that
 364      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
 365      * (if such an element exists).
 366      * Returns <tt>true</tt> if this deque contained the specified element
 367      * (or equivalently, if this deque changed as a result of the call).
 368      *
 369      * @param o element to be removed from this deque, if present
 370      * @return <tt>true</tt> if an element was removed as a result of this call
 371      * @throws ClassCastException if the class of the specified element
 372      *         is incompatible with this deque (optional)

 373      * @throws NullPointerException if the specified element is null and this
 374      *         deque does not permit null elements (optional)

 375      */
 376     boolean removeLastOccurrence(Object o);
 377 
 378     // *** Queue methods ***
 379 
 380     /**
 381      * Inserts the specified element into the queue represented by this deque
 382      * (in other words, at the tail of this deque) if it is possible to do so
 383      * immediately without violating capacity restrictions, returning
 384      * <tt>true</tt> upon success and throwing an
 385      * <tt>IllegalStateException</tt> if no space is currently available.
 386      * When using a capacity-restricted deque, it is generally preferable to
 387      * use {@link #offer(Object) offer}.
 388      *
 389      * <p>This method is equivalent to {@link #addLast}.
 390      *
 391      * @param e the element to add
 392      * @return <tt>true</tt> (as specified by {@link Collection#add})
 393      * @throws IllegalStateException if the element cannot be added at this
 394      *         time due to capacity restrictions


 510      */
 511     E pop();
 512 
 513 
 514     // *** Collection methods ***
 515 
 516     /**
 517      * Removes the first occurrence of the specified element from this deque.
 518      * If the deque does not contain the element, it is unchanged.
 519      * More formally, removes the first element <tt>e</tt> such that
 520      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
 521      * (if such an element exists).
 522      * Returns <tt>true</tt> if this deque contained the specified element
 523      * (or equivalently, if this deque changed as a result of the call).
 524      *
 525      * <p>This method is equivalent to {@link #removeFirstOccurrence}.
 526      *
 527      * @param o element to be removed from this deque, if present
 528      * @return <tt>true</tt> if an element was removed as a result of this call
 529      * @throws ClassCastException if the class of the specified element
 530      *         is incompatible with this deque (optional)

 531      * @throws NullPointerException if the specified element is null and this
 532      *         deque does not permit null elements (optional)

 533      */
 534     boolean remove(Object o);
 535 
 536     /**
 537      * Returns <tt>true</tt> if this deque contains the specified element.
 538      * More formally, returns <tt>true</tt> if and only if this deque contains
 539      * at least one element <tt>e</tt> such that
 540      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 541      *
 542      * @param o element whose presence in this deque is to be tested
 543      * @return <tt>true</tt> if this deque contains the specified element
 544      * @throws ClassCastException if the type of the specified element
 545      *         is incompatible with this deque (optional)

 546      * @throws NullPointerException if the specified element is null and this
 547      *         deque does not permit null elements (optional)

 548      */
 549     boolean contains(Object o);
 550 
 551     /**
 552      * Returns the number of elements in this deque.
 553      *
 554      * @return the number of elements in this deque
 555      */
 556     public int size();
 557 
 558     /**
 559      * Returns an iterator over the elements in this deque in proper sequence.
 560      * The elements will be returned in order from first (head) to last (tail).
 561      *
 562      * @return an iterator over the elements in this deque in proper sequence
 563      */
 564     Iterator<E> iterator();
 565 
 566     /**
 567      * Returns an iterator over the elements in this deque in reverse


 334     /**
 335      * Retrieves, but does not remove, the last element of this deque,
 336      * or returns <tt>null</tt> if this deque is empty.
 337      *
 338      * @return the tail of this deque, or <tt>null</tt> if this deque is empty
 339      */
 340     E peekLast();
 341 
 342     /**
 343      * Removes the first occurrence of the specified element from this deque.
 344      * If the deque does not contain the element, it is unchanged.
 345      * More formally, removes the first element <tt>e</tt> such that
 346      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
 347      * (if such an element exists).
 348      * Returns <tt>true</tt> if this deque contained the specified element
 349      * (or equivalently, if this deque changed as a result of the call).
 350      *
 351      * @param o element to be removed from this deque, if present
 352      * @return <tt>true</tt> if an element was removed as a result of this call
 353      * @throws ClassCastException if the class of the specified element
 354      *         is incompatible with this deque
 355      * (<a href="Collection.html#optional-restrictions">optional</a>)
 356      * @throws NullPointerException if the specified element is null and this
 357      *         deque does not permit null elements
 358      * (<a href="Collection.html#optional-restrictions">optional</a>)
 359      */
 360     boolean removeFirstOccurrence(Object o);
 361 
 362     /**
 363      * Removes the last occurrence of the specified element from this deque.
 364      * If the deque does not contain the element, it is unchanged.
 365      * More formally, removes the last element <tt>e</tt> such that
 366      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
 367      * (if such an element exists).
 368      * Returns <tt>true</tt> if this deque contained the specified element
 369      * (or equivalently, if this deque changed as a result of the call).
 370      *
 371      * @param o element to be removed from this deque, if present
 372      * @return <tt>true</tt> if an element was removed as a result of this call
 373      * @throws ClassCastException if the class of the specified element
 374      *         is incompatible with this deque
 375      * (<a href="Collection.html#optional-restrictions">optional</a>)
 376      * @throws NullPointerException if the specified element is null and this
 377      *         deque does not permit null elements
 378      * (<a href="Collection.html#optional-restrictions">optional</a>)
 379      */
 380     boolean removeLastOccurrence(Object o);
 381 
 382     // *** Queue methods ***
 383 
 384     /**
 385      * Inserts the specified element into the queue represented by this deque
 386      * (in other words, at the tail of this deque) if it is possible to do so
 387      * immediately without violating capacity restrictions, returning
 388      * <tt>true</tt> upon success and throwing an
 389      * <tt>IllegalStateException</tt> if no space is currently available.
 390      * When using a capacity-restricted deque, it is generally preferable to
 391      * use {@link #offer(Object) offer}.
 392      *
 393      * <p>This method is equivalent to {@link #addLast}.
 394      *
 395      * @param e the element to add
 396      * @return <tt>true</tt> (as specified by {@link Collection#add})
 397      * @throws IllegalStateException if the element cannot be added at this
 398      *         time due to capacity restrictions


 514      */
 515     E pop();
 516 
 517 
 518     // *** Collection methods ***
 519 
 520     /**
 521      * Removes the first occurrence of the specified element from this deque.
 522      * If the deque does not contain the element, it is unchanged.
 523      * More formally, removes the first element <tt>e</tt> such that
 524      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
 525      * (if such an element exists).
 526      * Returns <tt>true</tt> if this deque contained the specified element
 527      * (or equivalently, if this deque changed as a result of the call).
 528      *
 529      * <p>This method is equivalent to {@link #removeFirstOccurrence}.
 530      *
 531      * @param o element to be removed from this deque, if present
 532      * @return <tt>true</tt> if an element was removed as a result of this call
 533      * @throws ClassCastException if the class of the specified element
 534      *         is incompatible with this deque
 535      * (<a href="Collection.html#optional-restrictions">optional</a>)
 536      * @throws NullPointerException if the specified element is null and this
 537      *         deque does not permit null elements
 538      * (<a href="Collection.html#optional-restrictions">optional</a>)
 539      */
 540     boolean remove(Object o);
 541 
 542     /**
 543      * Returns <tt>true</tt> if this deque contains the specified element.
 544      * More formally, returns <tt>true</tt> if and only if this deque contains
 545      * at least one element <tt>e</tt> such that
 546      * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
 547      *
 548      * @param o element whose presence in this deque is to be tested
 549      * @return <tt>true</tt> if this deque contains the specified element
 550      * @throws ClassCastException if the type of the specified element
 551      *         is incompatible with this deque
 552      * (<a href="Collection.html#optional-restrictions">optional</a>)
 553      * @throws NullPointerException if the specified element is null and this
 554      *         deque does not permit null elements
 555      * (<a href="Collection.html#optional-restrictions">optional</a>)
 556      */
 557     boolean contains(Object o);
 558 
 559     /**
 560      * Returns the number of elements in this deque.
 561      *
 562      * @return the number of elements in this deque
 563      */
 564     public int size();
 565 
 566     /**
 567      * 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).
 569      *
 570      * @return an iterator over the elements in this deque in proper sequence
 571      */
 572     Iterator<E> iterator();
 573 
 574     /**
 575      * Returns an iterator over the elements in this deque in reverse