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 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 | capacity
Maximum number of items in the deque |
private transient 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 | 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(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
the element to add 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
the element to add 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
the element to add 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>
the collection to transfer elements into c)Implements java. Removes all available elements from this queue and adds them to the given collection. |
public int | drainTo(Collection<? super E>
the collection to transfer elements into c, int the maximum number of elements to transfer 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>
The action to be performed for each element 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 | |
private boolean | |
public boolean | offer(E
the element to add 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
the element to add e, long how long to wait before giving up, in units of
timeout, TimeUnit unit a unit)TimeUnit determining how to interpret the
timeout parameterImplements 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
the element to add 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
the element to add e, long how long to wait before giving up, in units of
timeout, TimeUnit unit a unit)TimeUnit determining how to interpret the
timeout parameterImplements 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
the element to add 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
the element to add e, long how long to wait before giving up, in units of
timeout, TimeUnit unit a unit)TimeUnit determining how to interpret the
timeout parameterImplements 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 | Returns: the head of this deque, ornull if this deque is emptyImplements 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 | Returns: the head of this deque, ornull if this deque is emptyImplements 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
how long to wait before giving up, in units of
timeout, TimeUnit unit a unit)TimeUnit determining how to interpret the
timeout parameterImplements 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
how long to wait before giving up, in units of
timeout, TimeUnit unit a unit)TimeUnit determining how to interpret the
timeout parameterImplements 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
how long to wait before giving up, in units of
timeout, TimeUnit unit a unit)TimeUnit determining how to interpret the
timeout parameterImplements 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
the element to push 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
the element to add 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
the element to add 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
the element to add 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<?>
collection containing elements to be removed from this 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
element to be removed from this deque, if present o)Implements java. Removes the first occurrence of the specified element from this deque. |
public boolean | removeIf(Predicate<? super E>
a predicate which returns filter)true for elements to be
removedOverrides 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
element to be removed from this deque, if present o)Implements java. Removes the last occurrence of the specified element from this deque. |
public boolean | retainAll(Collection<?>
collection containing elements to be retained in this 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 |