The optional capacity bound constructor argument serves as a
way to prevent excessive expansion. The capacity, if unspecified,
is equal to Integer#MAX_VALUE. Linked nodes are
dynamically created upon each insertion unless this would bring the
deque above capacity.
Most operations run in constant time (ignoring time spent
blocking). Exceptions include remove,
removeFirstOccurrence, removeLastOccurrence, contains, and the bulk operations, all of which run in linear
time.
This class and its iterator implement all of the optional
methods of the Collection and Iterator interfaces.
This class is a member of the Java Collections Framework.
| Modifier and Type | Class and Description |
|---|---|
| private abstract class | LinkedBlockingDeque.
Base class for LinkedBlockingDeque iterators. |
| private class | LinkedBlockingDeque.
Descending iterator |
| private class | LinkedBlockingDeque.
Forward iterator |
| private class | LinkedBlockingDeque.
A customized variant of Spliterators.IteratorSpliterator. |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| private transient volatile int | count
Number of items in the deque |
| pack-priv transient LinkedBlockingDeque. | first
Pointer to first node. |
| pack-priv transient LinkedBlockingDeque. | last
Pointer to last node. |
| pack-priv final ReentrantLock | |
| private final Condition | |
| private final Condition | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | |
| public | LinkedBlockingDeque(int
the capacity of this deque capacity)Creates a |
| public | LinkedBlockingDeque(Collection<? extends E>
the collection of elements to initially contain c)Creates a |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(E e)
Overrides java. Implements java. Inserts the specified element at the end of this deque unless it would violate capacity restrictions. |
| public boolean | Returns: true if this deque changed as a result of the callthe elements to be inserted into this deque c)Overrides java. Implements java. Appends all of the elements in the specified collection to the end of this deque, in the order that they are returned by the specified collection's iterator. |
| public void | addFirst(E e)
Implements java. Inserts the specified element at the front of this deque if it is
possible to do so immediately without violating capacity restrictions,
throwing an |
| public void | addLast(E e)
Implements java. Inserts the specified element at the end of this deque if it is
possible to do so immediately without violating capacity restrictions,
throwing an |
| private boolean | |
| pack-priv void | |
| public void | clear()
Overrides java. Implements java. Atomically removes all of the elements from this deque. |
| public boolean | Returns: true if this deque contains the specified elementobject to be checked for containment in this deque o)Overrides java. Implements java. Returns |
| public Iterator | Returns: an iterator over the elements in this deque in reverse orderImplements java. Returns an iterator over the elements in this deque in reverse sequential order. |
| public int | drainTo(Collection<? super E> c)
Implements java. Removes all available elements from this queue and adds them to the given collection. |
| public int | drainTo(Collection<? super E> c, int maxElements)
Implements java. Removes at most the given number of available elements from this queue and adds them to the given collection. |
| public E | Returns: the head of the queue represented by this dequeOverrides java. Implements java. Retrieves, but does not remove, the head of the queue represented by this deque. |
| public void | forEach(Consumer<? super E> action)
Overrides default java. Performs the given action for each element of the |
| pack-priv void | forEachFrom(Consumer<? super E> action, LinkedBlockingDeque.
Runs action on each element found during a traversal starting at p. |
| public E | getFirst()
Implements java. Retrieves, but does not remove, the first element of this deque. |
| public E | getLast()
Implements java. Retrieves, but does not remove, the last element of this deque. |
| public Iterator | Returns: an iterator over the elements in this deque in proper sequenceImplements abstract java. Implements java. Returns an iterator over the elements in this deque in proper sequence. |
| private boolean | Returns: true if the node was added; false otherwiseLinks node as first element, or returns false if full. |
| private boolean | Returns: true if the node was added; false otherwiseLinks node as last element, or returns false if full. |
| public boolean | offer(E e)
Implements java. Inserts the specified element into the queue represented by this deque
(in other words, at the tail of this deque) if it is possible to do so
immediately without violating capacity restrictions, returning
|
| public boolean | offer(E e, long timeout, TimeUnit unit)
Implements java. Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque), waiting up to the specified wait time if necessary for space to become available. |
| public boolean | offerFirst(E e)
Implements java. Inserts the specified element at the front of this deque if it is
possible to do so immediately without violating capacity restrictions,
returning |
| public boolean | offerFirst(E e, long timeout, TimeUnit unit)
Implements java. Inserts the specified element at the front of this deque, waiting up to the specified wait time if necessary for space to become available. |
| public boolean | offerLast(E e)
Implements java. Inserts the specified element at the end of this deque if it is
possible to do so immediately without violating capacity restrictions,
returning |
| public boolean | offerLast(E e, long timeout, TimeUnit unit)
Implements java. Inserts the specified element at the end of this deque, waiting up to the specified wait time if necessary for space to become available. |
| public E | peek()
Implements java. Retrieves, but does not remove, the head of the queue represented by
this deque (in other words, the first element of this deque), or
returns |
| public E | peekFirst()
Implements java. Retrieves, but does not remove, the first element of this deque,
or returns |
| public E | peekLast()
Implements java. Retrieves, but does not remove, the last element of this deque,
or returns |
| public E | poll()
Implements java. Retrieves and removes the head of the queue represented by this deque
(in other words, the first element of this deque), or returns
|
| public E | poll(long timeout, TimeUnit unit)
Implements java. Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), waiting up to the specified wait time if necessary for an element to become available. |
| public E | pollFirst()
Implements java. Retrieves and removes the first element of this deque,
or returns |
| public E | pollFirst(long timeout, TimeUnit unit)
Implements java. Retrieves and removes the first element of this deque, waiting up to the specified wait time if necessary for an element to become available. |
| public E | pollLast()
Implements java. Retrieves and removes the last element of this deque,
or returns |
| public E | pollLast(long timeout, TimeUnit unit)
Implements java. Retrieves and removes the last element of this deque, waiting up to the specified wait time if necessary for an element to become available. |
| public E | |
| public void | push(E e)
Implements java. Pushes an element onto the stack represented by this deque (in other
words, at the head of this deque) if it is possible to do so
immediately without violating capacity restrictions, throwing an
|
| public void | put(E e)
Implements java. Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque), waiting if necessary for space to become available. |
| public void | putFirst(E e)
Implements java. Inserts the specified element at the front of this deque, waiting if necessary for space to become available. |
| public void | putLast(E e)
Implements java. Inserts the specified element at the end of this deque, waiting if necessary for space to become available. |
| private void | readObject(ObjectInputStream
the stream s)Reconstitutes this deque from a stream (that is, deserializes it). |
| public int | remainingCapacity()
Implements java. Returns the number of additional elements that this deque can ideally (in the absence of memory or resource constraints) accept without blocking. |
| public E | Returns: the head of the queue represented by this dequeOverrides java. Implements java. Retrieves and removes the head of the queue represented by this deque. |
| public boolean | Returns: true if this deque changed as a result of the callelement to be removed from this deque, if present o)Overrides java. Implements java. Removes the first occurrence of the specified element from this deque. |
| public boolean | removeAll(Collection<?> c)
Overrides java. Implements java. Removes all of this collection's elements that are also contained in the specified collection (optional operation). |
| public E | removeFirst()
Implements java. Retrieves and removes the first element of this deque. |
| public boolean | removeFirstOccurrence(Object o)
Implements java. Removes the first occurrence of the specified element from this deque. |
| public boolean | removeIf(Predicate<? super E> filter)
Overrides default java. Removes all of the elements of this collection that satisfy the given predicate (optional operation). |
| public E | removeLast()
Implements java. Retrieves and removes the last element of this deque. |
| public boolean | removeLastOccurrence(Object o)
Implements java. Removes the last occurrence of the specified element from this deque. |
| public boolean | retainAll(Collection<?> c)
Overrides java. Implements java. Retains only the elements in this collection that are contained in the specified collection (optional operation). |
| public int | Returns: the number of elements in this dequeImplements abstract java. Implements java. Returns the number of elements in this deque. |
| public Spliterator | Returns: aSpliterator over the elements in this dequeOverrides default java. Returns a |
| pack-priv LinkedBlockingDeque. | |
| public E | take()
Implements java. Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), waiting if necessary until an element becomes available. |
| public E | takeFirst()
Implements java. Retrieves and removes the first element of this deque, waiting if necessary until an element becomes available. |
| public E | takeLast()
Implements java. Retrieves and removes the last element of this deque, waiting if necessary until an element becomes available. |
| public Object[] | Returns: an array containing all of the elements in this dequeOverrides java. Implements java. Returns an array containing all of the elements in this deque, in proper sequence (from first to last element). |
| public <T> T[] | Returns: an array containing all of the elements in this dequethe array into which the elements of the deque are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose a)Overrides java. Implements java. Returns an array containing all of the elements in this deque, in proper sequence; the runtime type of the returned array is that of the specified array. |
| public String | toString()
Overrides java. Returns a string representation of this collection. |
| pack-priv void | |
| private E | |
| private E | |
| private void |