| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
LinkedBlockingDeque q = new LinkedBlockingDeque(2);
Based on 146 examples
public class LinkedBlockingDeque extends AbstractQueue implements BlockingDeque, Serializable
An optionally-bounded {@linkplain BlockingDeque blocking deque} based on linked nodes.
The optional capacity bound constructor argument serves as a way to prevent excessive expansion. The capacity, if unspecified, is equal to {@link 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 {@link #remove(Object) remove}, {@link #removeFirstOccurrence removeFirstOccurrence}, {@link #removeLastOccurrence removeLastOccurrence}, {@link #contains contains}, {@link #iterator iterator.remove()}, and the bulk operations, all of which run in linear time.
This class and its iterator implement all of the optional methods of the {@link Collection} and {@link Iterator} interfaces.
This class is a member of the Java Collections Framework.
Constructor Summary | |
---|---|
Creates a LinkedBlockingDeque with a capacity of java.lang.Integer.MAX_VALUE. |
|
Creates a LinkedBlockingDeque with a capacity of java.lang.Integer.MAX_VALUE, initially containing the elements of the given collection, added in traversal order of the collection's iterator. |
|
LinkedBlockingDeque(int capacity) Creates a LinkedBlockingDeque with the given (fixed) capacity. |
Method Summary | |
---|---|
boolean |
Inserts the specified element at the end of this deque unless it would violate capacity restrictions. |
void |
|
void |
|
void |
clear() Atomically removes all of the elements from this deque. |
boolean |
Returns true if this deque contains the specified element. |
Iterator |
Returns an iterator over the elements in this deque in reverse sequential order. |
int |
|
int |
drainTo(Collection c, int maxElements) |
Object |
element() Retrieves, but does not remove, the head of the queue represented by this deque. |
Object |
getFirst() |
Object |
getLast() |
Iterator |
iterator() Returns an iterator over the elements in this deque in proper sequence. |
boolean |
|
boolean |
|
boolean |
offerFirst(Object e) |
boolean |
offerFirst(Object e, long timeout, TimeUnit unit) |
boolean |
|
boolean |
|
Object |
peek() |
Object |
|
Object |
peekLast() |
Object |
poll() |
Object |
|
Object |
|
Object |
|
Object |
pollLast() |
Object |
|
Object |
pop() |
void |
|
void |
|
void |
|
void |
|
int |
Returns the number of additional elements that this deque can ideally (in the absence of memory or resource constraints) accept without blocking. |
Object |
remove() Retrieves and removes the head of the queue represented by this deque. |
boolean |
Removes the first occurrence of the specified element from this deque. |
Object |
|
boolean |
|
Object |
|
boolean |
|
int |
size() Returns the number of elements in this deque. |
Object |
take() |
Object |
|
Object |
takeLast() |
Object[] |
toArray() Returns an array containing all of the elements in this deque, in proper sequence (from first to last element). |
Object[] |
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. |
String |
toString() Returns a string representation of this collection. |
Methods inherited from class java.util.AbstractQueue |
---|
add, addAll, clear, element, remove |
Methods inherited from class java.util.AbstractCollection |
---|
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LinkedBlockingDeque()
public LinkedBlockingDeque(Collection c)
c
- the collection of elements to initially containpublic LinkedBlockingDeque(int capacity)
capacity
- the capacity of this dequeMethod Detail |
---|
public boolean add(Object e)
This method is equivalent to {@link #addLast}.
add
in class AbstractQueue
e
public void addFirst(Object e)
e
public void addLast(Object e)
e
public void clear()
clear
in class AbstractQueue
public boolean contains(Object o)
contains
in class AbstractCollection
o
- object to be checked for containment in this dequepublic Iterator descendingIterator()
public int drainTo(Collection c)
c
public int drainTo(Collection c, int maxElements)
c
maxElements
public Object element()
This method is equivalent to {@link #getFirst() getFirst}.
element
in class AbstractQueue
public Object getFirst()
public Object getLast()
public Iterator iterator()
iterator
in class AbstractCollection
public boolean offer(Object e)
e
public boolean offer(Object e, long timeout, TimeUnit unit) throws InterruptedException
e
timeout
unit
InterruptedException
- {@inheritDoc}public boolean offerFirst(Object e)
e
public boolean offerFirst(Object e, long timeout, TimeUnit unit) throws InterruptedException
e
timeout
unit
InterruptedException
- {@inheritDoc}public boolean offerLast(Object e)
e
public boolean offerLast(Object e, long timeout, TimeUnit unit) throws InterruptedException
e
timeout
unit
InterruptedException
- {@inheritDoc}public Object peek()
public Object peekFirst()
public Object peekLast()
public Object poll()
public Object poll(long timeout, TimeUnit unit) throws InterruptedException
timeout
unit
InterruptedException
public Object pollFirst()
public Object pollFirst(long timeout, TimeUnit unit) throws InterruptedException
timeout
unit
InterruptedException
public Object pollLast()
public Object pollLast(long timeout, TimeUnit unit) throws InterruptedException
timeout
unit
InterruptedException
public Object pop()
public void push(Object e)
e
public void put(Object e) throws InterruptedException
e
InterruptedException
- {@inheritDoc}public void putFirst(Object e) throws InterruptedException
e
InterruptedException
- {@inheritDoc}public void putLast(Object e) throws InterruptedException
e
InterruptedException
- {@inheritDoc}public int remainingCapacity()
Note that you cannot always tell if an attempt to insert an element will succeed by inspecting remainingCapacity because it may be the case that another thread is about to insert or remove an element.
public Object remove()
This method is equivalent to {@link #removeFirst() removeFirst}.
remove
in class AbstractQueue
public boolean remove(Object o)
This method is equivalent to {@link #removeFirstOccurrence(Object) removeFirstOccurrence}.
remove
in class AbstractCollection
o
- element to be removed from this deque, if presentpublic Object removeFirst()
public boolean removeFirstOccurrence(Object o)
o
public Object removeLast()
public boolean removeLastOccurrence(Object o)
o
public int size()
size
in class AbstractCollection
public Object take() throws InterruptedException
InterruptedException
public Object takeFirst() throws InterruptedException
InterruptedException
public Object takeLast() throws InterruptedException
InterruptedException
public Object[] toArray()
The returned array will be "safe" in that no references to it are maintained by this deque. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
toArray
in class AbstractCollection
public Object[] toArray(Object[] a)
If this deque fits in the specified array with room to spare (i.e., the array has more elements than this deque), the element in the array immediately following the end of the deque is set to null.
Like the {@link #toArray()} method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.
Suppose x is a deque known to contain only strings. The following code can be used to dump the deque into a newly allocated array of String:
String[] y = x.toArray(new String[0]);Note that toArray(new Object[0]) is identical in function to toArray().
toArray
in class AbstractCollection
a
- the 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 purposepublic String toString()
toString
in class AbstractCollection
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |