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.AbstractItr
Base class for Iterators for LinkedBlockingDeque |
| private class | LinkedBlockingDeque.DescendingItr
Descending iterator |
| private class | LinkedBlockingDeque.Itr
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 |
|---|---|
| public | |
| public | LinkedBlockingDeque(final boolean
true means threads waiting on the deque should be served
as if waiting in a FIFO request queue fairness)Creates a |
| public | LinkedBlockingDeque(final Collection<? extends E>
the collection of elements to initially contain c)Creates a |
| public | LinkedBlockingDeque(final int
the capacity of this deque capacity)Creates a |
| public | 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
the element to add e)Overrides java. Implements java. true upon success and throwing an
IllegalStateException if no space is currently available.
|
| public void | addFirst(final E
the element to add e)Implements java. IllegalStateException if no space is currently
available.
|
| public void | addLast(final E
the element to add e)Implements java. IllegalStateException if no space is currently
available.
|
| public void | clear()
Overrides java. Implements java. |
| public boolean | Returns: true if this deque contains the specified elementobject to be checked for containment in this deque o)Overrides java. Implements java. true if this deque contains the specified element.
|
| public Iterator | descendingIterator()
Implements java. |
| public int | Returns: number of elements added to the collectionThe collection to add the elements to c)Drains the queue to the specified collection. |
| public int | Returns: number of elements added to the collectioncollection to add the elements to c, final int maximum number of elements to remove from the queue maxElements)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. |
| public E | getFirst()
Implements java. |
| public E | getLast()
Implements java. |
| public 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. |
| public 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. |
| public void | |
| public Iterator | Returns: an iterator over the elements in this deque in proper sequenceImplements abstract java. Implements java. |
| 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
the element to add e)Implements java. true upon success and false if no space is currently
available.
|
| pack-priv boolean | |
| public boolean | |
| public boolean | offerFirst(final E
the element to add e)Implements java. |
| public 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)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
the element to add e)Implements java. |
| pack-priv boolean | |
| public boolean | |
| public E | peek()
Implements java. null if this deque is empty.
|
| public E | peekFirst()
Implements java. null if this deque is empty.
|
| public E | peekLast()
Implements java. null if this deque is empty.
|
| public E | poll()
Implements java. null if this deque is empty.
|
| pack-priv E | |
| public E | |
| public E | pollFirst()
Implements java. null if this deque is empty.
|
| pack-priv E | |
| public E | |
| public E | pollLast()
Implements java. null if this deque is empty.
|
| public E | |
| public E | |
| public E | |
| public void | push(final E
the element to push e)Implements java. IllegalStateException if no space is currently available.
|
| public void | put(final E
element to link e)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)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)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 acceptReturns 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. |
| 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. |
| public E | removeFirst()
Implements java. |
| public boolean | removeFirstOccurrence(final Object
element to be removed from this deque, if present o)Implements java. |
| public E | removeLast()
Implements java. |
| public boolean | removeLastOccurrence(final Object
element to be removed from this deque, if present o)Implements java. |
| public int | Returns: the number of elements in this dequeImplements abstract java. Implements java. |
| public E | Returns: the unlinked elementUnlinks the first element in the queue, waiting until there is an element to unlink if the queue is empty. |
| public E | Returns: the unlinked elementUnlinks the first element in the queue, waiting until there is an element to unlink if the queue is empty. |
| public E | Returns: the unlinked elementUnlinks 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. |
| public <T> T[] | toArray(T[]
the array into which the elements of this collection 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. |
| public String | toString()
Overrides java. |
| 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). |