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, iterator., 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 Iterators for LinkedBlockingDeque |
| private class | LinkedBlockingDeque.
Descending iterator |
| private class | LinkedBlockingDeque.
Forward iterator |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final int | capacity
Maximum number of items in the deque |
| private transient int | count
Number of items in the deque |
| private transient LinkedBlockingDeque. | first
Pointer to first node. |
| private transient LinkedBlockingDeque. | last
Pointer to last node. |
| private final InterruptibleReentrantLock | lock
Main lock guarding all access |
| private final Condition | notEmpty
Condition for waiting takes |
| private final Condition | notFull
Condition for waiting puts |
| private static final long |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | LinkedBlockingDeque(final boolean
true means threads waiting on the deque should be served
as if waiting in a FIFO request queue fairness)Creates a |
| pack-priv | LinkedBlockingDeque(final Collection<? extends E>
the collection of elements to initially contain c)Creates a |
| pack-priv | LinkedBlockingDeque(final int
the capacity of this deque capacity)Creates a |
| pack-priv | LinkedBlockingDeque(final int
the capacity of this deque capacity, final boolean true means threads waiting on the deque should be served
as if waiting in a FIFO request queue fairness)Creates a |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(final E e)
Overrides java. 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 void | addFirst(final 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(final 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 |
| 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 | descendingIterator()
Implements java. Returns an iterator over the elements in this deque in reverse sequential order. |
| public int | Returns: number of elements added to the collectionThe collection to add the elements to c)Implements java. Drains the queue to the specified collection. |
| public int | Returns: number of elements added to the collectioncollection to add the elements to collection, final int maximum number of elements to remove from the queue maxElements)Implements java. Drains no more than the specified number of elements from the queue to the specified 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 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. |
| pack-priv int | Returns: number of threads waiting on this deque's notEmpty condition.Gets the length of the queue of threads waiting to take instances from this deque. |
| pack-priv boolean | Returns: true if there is at least one thread waiting on this deque's notEmpty condition.Returns true if there are threads waiting to take instances from this deque. |
| pack-priv void | |
| 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 successful, otherwise falseThe element to link as the first element. e)Links provided element as first element, or returns false if full. |
| private boolean | Returns: true if successful, otherwise falseThe element to link as the last element. e)Links provided element as last element, or returns false if full. |
| public boolean | offer(final 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
|
| pack-priv boolean | |
| public boolean | Returns: true if successful, otherwise falseelement to link e, final long length of time to wait timeout, final TimeUnit units that timeout is expressed in unit)Implements java. Links the provided element as the last in the queue, waiting up to the specified time to do so if the queue is full. |
| public boolean | offerFirst(final 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 |
| pack-priv boolean | Returns: true if successful, otherwise falseelement to link e, final Duration length of time to wait timeout)Links the provided element as the first in the queue, waiting up to the specified time to do so if the queue is full. |
| public boolean | Returns: true if successful, otherwise falseelement to link e, final long length of time to wait timeout, final TimeUnit units that timeout is expressed in unit)Implements java. Links the provided element as the first in the queue, waiting up to the specified time to do so if the queue is full. |
| public boolean | offerLast(final 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 |
| pack-priv boolean | |
| public boolean | Returns: true if successful, otherwise falseelement to link e, final long length of time to wait timeout, final TimeUnit units that timeout is expressed in unit)Implements java. Links the provided element as the last in the queue, waiting up to the specified time to do so if the queue is full. |
| 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
|
| pack-priv E | |
| public E | Returns: the unlinked elementlength of time to wait timeout, final TimeUnit units that timeout is expressed in unit)Implements java. Unlinks the first element in the queue, waiting up to the specified time to do so if the queue is empty. |
| public E | pollFirst()
Implements java. Retrieves and removes the first element of this deque,
or returns |
| pack-priv E | |
| public E | Returns: the unlinked elementlength of time to wait timeout, final TimeUnit units that timeout is expressed in unit)Implements java. Unlinks the first element in the queue, waiting up to the specified time to do so if the queue is empty. |
| public E | pollLast()
Implements java. Retrieves and removes the last element of this deque,
or returns |
| pack-priv E | |
| public E | Returns: the unlinked elementlength of time to wait timeout, final TimeUnit units that timeout is expressed in unit)Implements java. Unlinks the last element in the queue, waiting up to the specified time to do so if the queue is empty. |
| public E | |
| public void | push(final 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(final E
element to link e)Implements java. Links the provided element as the last in the queue, waiting until there is space to do so if the queue is full. |
| public void | putFirst(final E
element to link e)Implements java. Links the provided element as the first in the queue, waiting until there is space to do so if the queue is full. |
| public void | putLast(final E
element to link e)Implements java. Links the provided element as the last in the queue, waiting until there is space to do so if the queue is full. |
| private void | readObject(final ObjectInputStream
the stream s)Reconstitutes this deque from a stream (that is, deserialize it). |
| public int | Returns: The number of additional elements the queue is able to acceptImplements 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 E | removeFirst()
Implements java. Retrieves and removes the first element of this deque. |
| public boolean | removeFirstOccurrence(final Object o)
Implements java. Removes the first occurrence of the specified element from this deque. |
| public E | removeLast()
Implements java. Retrieves and removes the last element of this deque. |
| public boolean | removeLastOccurrence(final Object o)
Implements java. Removes the last occurrence of the specified element from this deque. |
| public int | Returns: the number of elements in this dequeImplements abstract java. Implements java. Returns the number of elements in this deque. |
| public E | Returns: the unlinked elementImplements java. Unlinks the first element in the queue, waiting until there is an element to unlink if the queue is empty. |
| public E | Returns: the unlinked elementImplements java. Unlinks the first element in the queue, waiting until there is an element to unlink if the queue is empty. |
| public E | Returns: the unlinked elementImplements java. Unlinks the last element in the queue, waiting until there is an element to unlink if the queue is empty. |
| 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[] | toArray(T[] a)
Overrides java. Implements java. Returns an array containing all of the elements in this collection; 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. |
| private void | |
| private E | Returns: The first element ornull if emptyRemoves and returns the first element, or null if empty. |
| private E | Returns: The first element ornull if emptyRemoves and returns the last element, or null if empty. |
| private void | writeObject(final ObjectOutputStream
the stream s)Saves the state of this deque to a stream (that is, serialize it). |