--- jsr166/src/main/java/util/Deque.java 2017/05/06 06:49:45 1.36 +++ jsr166/src/main/java/util/Deque.java 2018/04/05 00:03:34 1.41 @@ -27,41 +27,44 @@ package java.util; *

The twelve methods described above are summarized in the * following table: * - * + *
* + * * - * - * - * + * + * + * * * - * - * - * - * - * + * + * + * + * * + * + * * - * + * * * * * * * - * + * * * * * * * - * + * * * * * * + * *
Summary of Deque methods
First Element (Head) Last Element (Tail) First Element (Head) Last Element (Tail)
Throws exceptionSpecial valueThrows exceptionSpecial valueThrows exceptionSpecial valueThrows exceptionSpecial value
InsertInsert{@link #addFirst(Object) addFirst(e)}{@link #offerFirst(Object) offerFirst(e)}{@link #addLast(Object) addLast(e)}{@link #offerLast(Object) offerLast(e)}
RemoveRemove{@link #removeFirst() removeFirst()}{@link #pollFirst() pollFirst()}{@link #removeLast() removeLast()}{@link #pollLast() pollLast()}
ExamineExamine{@link #getFirst() getFirst()}{@link #peekFirst() peekFirst()}{@link #getLast() getLast()}{@link #peekLast() peekLast()}
* *

This interface extends the {@link Queue} interface. When a deque is @@ -70,62 +73,70 @@ package java.util; * inherited from the {@code Queue} interface are precisely equivalent to * {@code Deque} methods as indicated in the following table: * - * + *
* + * * - * - * + * + * * + * + * * - * + * * * * - * + * * * * - * + * * * * - * + * * * * - * + * * * * - * + * * * + * *
Comparison of Queue and Deque methods
{@code Queue} Method Equivalent {@code Deque} Method {@code Queue} Method Equivalent {@code Deque} Method
{@link #add(Object) add(e)}{@link #add(Object) add(e)}{@link #addLast(Object) addLast(e)}
{@link #offer(Object) offer(e)}{@link #offer(Object) offer(e)}{@link #offerLast(Object) offerLast(e)}
{@link #remove() remove()}{@link #remove() remove()}{@link #removeFirst() removeFirst()}
{@link #poll() poll()}{@link #poll() poll()}{@link #pollFirst() pollFirst()}
{@link #element() element()}{@link #element() element()}{@link #getFirst() getFirst()}
{@link #peek() peek()}{@link #peek() peek()}{@link #peekFirst() peekFirst()}
* *

Deques can also be used as LIFO (Last-In-First-Out) stacks. This * interface should be used in preference to the legacy {@link Stack} class. * When a deque is used as a stack, elements are pushed and popped from the - * beginning of the deque. Stack methods are precisely equivalent to - * {@code Deque} methods as indicated in the table below: + * beginning of the deque. Stack methods are equivalent to {@code Deque} + * methods as indicated in the table below: * - * + *
* + * * - * - * + * + * * + * + * * - * + * * * * - * + * * * * - * - * + * + * * + * *
Comparison of Stack and Deque methods
Stack Method Equivalent {@code Deque} Method Stack Method Equivalent {@code Deque} Method
{@link #push(Object) push(e)}{@link #push(Object) push(e)}{@link #addFirst(Object) addFirst(e)}
{@link #pop() pop()}{@link #pop() pop()}{@link #removeFirst() removeFirst()}
{@link #peek() peek()}{@link #peekFirst() peekFirst()}{@link #peek() peek()}{@link #getFirst() getFirst()}
* *

Note that the {@link #peek peek} method works equally well when @@ -448,6 +459,31 @@ public interface Deque extends Queue< */ E peek(); + /** + * Adds all of the elements in the specified collection at the end + * of this deque, as if by calling {@link #addLast} on each one, + * in the order that they are returned by the collection's iterator. + * + *

When using a capacity-restricted deque, it is generally preferable + * to call {@link #offer(Object) offer} separately on each element. + * + *

An exception encountered while trying to add an element may result + * in only some of the elements having been successfully added when + * the associated exception is thrown. + * + * @param c the elements to be inserted into this deque + * @return {@code true} if this deque changed as a result of the call + * @throws IllegalStateException if not all the elements can be added at + * this time due to insertion restrictions + * @throws ClassCastException if the class of an element of the specified + * collection prevents it from being added to this deque + * @throws NullPointerException if the specified collection contains a + * null element and this deque does not permit null elements, + * or if the specified collection is null + * @throws IllegalArgumentException if some property of an element of the + * specified collection prevents it from being added to this deque + */ + boolean addAll(Collection c); // *** Stack methods ***