|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection
org.compass.core.util.backport.java.util.AbstractCollection
org.compass.core.util.backport.java.util.AbstractQueue
org.compass.core.util.backport.java.util.concurrent.LinkedBlockingDeque
public class LinkedBlockingDeque
An optionally-bounded 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 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.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 Collection and Iterator interfaces.
This class is a member of the Java Collections Framework.
| Nested Class Summary | |
|---|---|
(package private) static class |
LinkedBlockingDeque.Node
Doubly-linked list node class |
| Constructor Summary | |
|---|---|
LinkedBlockingDeque()
Creates a LinkedBlockingDeque with a capacity of Integer.MAX_VALUE. |
|
LinkedBlockingDeque(Collection c)
Creates a LinkedBlockingDeque with a capacity of 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 |
add(Object e)
Inserts the specified element at the end of this deque unless it would violate capacity restrictions. |
void |
addFirst(Object e)
Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available. |
void |
addLast(Object e)
Inserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available. |
void |
clear()
Atomically removes all of the elements from this deque. |
boolean |
contains(Object o)
Returns true if this deque contains the specified element. |
Iterator |
descendingIterator()
Returns an iterator over the elements in this deque in reverse sequential order. |
int |
drainTo(Collection c)
Removes all available elements from this queue and adds them to the given collection. |
int |
drainTo(Collection c,
int maxElements)
Removes at most the given number of available elements from this queue and adds them to the given collection. |
Object |
element()
Retrieves, but does not remove, the head of the queue represented by this deque. |
Object |
getFirst()
Retrieves, but does not remove, the first element of this deque. |
Object |
getLast()
Retrieves, but does not remove, the last element of this deque. |
Iterator |
iterator()
Returns an iterator over the elements in this deque in proper sequence. |
boolean |
offer(Object e)
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 true upon success and false if no space is currently available. |
boolean |
offer(Object e,
long timeout,
TimeUnit unit)
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. |
boolean |
offerFirst(Object e)
Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions, returning true upon success and false if no space is currently available. |
boolean |
offerFirst(Object e,
long timeout,
TimeUnit unit)
Inserts the specified element at the front of this deque, waiting up to the specified wait time if necessary for space to become available. |
boolean |
offerLast(Object e)
Inserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions, returning true upon success and false if no space is currently available. |
boolean |
offerLast(Object e,
long timeout,
TimeUnit unit)
Inserts the specified element at the end of this deque, waiting up to the specified wait time if necessary for space to become available. |
Object |
peek()
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 null if this deque is empty. |
Object |
peekFirst()
Retrieves, but does not remove, the first element of this deque, or returns null if this deque is empty. |
Object |
peekLast()
Retrieves, but does not remove, the last element of this deque, or returns null if this deque is empty. |
Object |
poll()
Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returns null if this deque is empty. |
Object |
poll(long timeout,
TimeUnit unit)
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. |
Object |
pollFirst()
Retrieves and removes the first element of this deque, or returns null if this deque is empty. |
Object |
pollFirst(long timeout,
TimeUnit unit)
Retrieves and removes the first element of this deque, waiting up to the specified wait time if necessary for an element to become available. |
Object |
pollLast()
Retrieves and removes the last element of this deque, or returns null if this deque is empty. |
Object |
pollLast(long timeout,
TimeUnit unit)
Retrieves and removes the last element of this deque, waiting up to the specified wait time if necessary for an element to become available. |
Object |
pop()
Pops an element from the stack represented by this deque. |
void |
push(Object e)
Pushes an element onto the stack represented by this deque. |
void |
put(Object e)
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. |
void |
putFirst(Object e)
Inserts the specified element at the front of this deque, waiting if necessary for space to become available. |
void |
putLast(Object e)
Inserts the specified element at the end of this deque, waiting if necessary for space to become available. |
int |
remainingCapacity()
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 |
remove(Object o)
Removes the first occurrence of the specified element from this deque. |
Object |
removeFirst()
Retrieves and removes the first element of this deque. |
boolean |
removeFirstOccurrence(Object o)
Removes the first occurrence of the specified element from this deque. |
Object |
removeLast()
Retrieves and removes the last element of this deque. |
boolean |
removeLastOccurrence(Object o)
Removes the last occurrence of the specified element from this deque. |
(package private) boolean |
removeNode(LinkedBlockingDeque.Node e)
Variant of removeFirstOccurrence needed by iterator.remove. |
int |
size()
Returns the number of elements in this deque. |
Object |
take()
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. |
Object |
takeFirst()
Retrieves and removes the first element of this deque, waiting if necessary until an element becomes available. |
Object |
takeLast()
Retrieves and removes the last element of this deque, waiting if necessary until an element becomes available. |
Object[] |
toArray()
Returns an array containing all of the elements in this deque, in proper sequence (from first to last element). |
Object[] |
toArray(Object[] a)
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()
|
| Methods inherited from class org.compass.core.util.backport.java.util.AbstractQueue |
|---|
addAll |
| Methods inherited from class java.util.AbstractCollection |
|---|
containsAll, isEmpty, removeAll, retainAll |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
|---|
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll |
| Methods inherited from interface java.util.Collection |
|---|
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll |
| Constructor Detail |
|---|
public LinkedBlockingDeque()
Integer.MAX_VALUE.
public LinkedBlockingDeque(int capacity)
capacity - the capacity of this deque
IllegalArgumentException - if capacity is less than 1public LinkedBlockingDeque(Collection c)
Integer.MAX_VALUE, initially containing the elements of
the given collection, added in traversal order of the
collection's iterator.
c - the collection of elements to initially contain
NullPointerException - if the specified collection or any
of its elements are null| Method Detail |
|---|
public void addFirst(Object e)
BlockingDequeofferFirst.
addFirst in interface BlockingDequeaddFirst in interface Dequee - the element to add
IllegalStateException - if the element cannot be added at this
time due to capacity restrictions
NullPointerException - if the specified element is nullpublic void addLast(Object e)
BlockingDequeofferLast.
addLast in interface BlockingDequeaddLast in interface Dequee - the element to add
IllegalStateException - if the element cannot be added at this
time due to capacity restrictions
NullPointerException - if the specified element is nullpublic boolean offerFirst(Object e)
BlockingDequeaddFirst method, which can
fail to insert an element only by throwing an exception.
offerFirst in interface BlockingDequeofferFirst in interface Dequee - the element to add
NullPointerException - if the specified element is nullpublic boolean offerLast(Object e)
BlockingDequeaddLast method, which can
fail to insert an element only by throwing an exception.
offerLast in interface BlockingDequeofferLast in interface Dequee - the element to add
NullPointerException - if the specified element is null
public void putFirst(Object e)
throws InterruptedException
BlockingDeque
putFirst in interface BlockingDequee - the element to add
NullPointerException - if the specified element is null
InterruptedException - if interrupted while waiting
public void putLast(Object e)
throws InterruptedException
BlockingDeque
putLast in interface BlockingDequee - the element to add
NullPointerException - if the specified element is null
InterruptedException - if interrupted while waiting
public boolean offerFirst(Object e,
long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDeque
offerFirst in interface BlockingDequee - the element to addtimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameter
NullPointerException - if the specified element is null
InterruptedException - if interrupted while waiting
public boolean offerLast(Object e,
long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDeque
offerLast in interface BlockingDequee - the element to addtimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameter
NullPointerException - if the specified element is null
InterruptedException - if interrupted while waitingpublic Object removeFirst()
DequepollFirst only in that it throws an
exception if this deque is empty.
removeFirst in interface DequeNoSuchElementExceptionpublic Object removeLast()
DequepollLast only in that it throws an
exception if this deque is empty.
removeLast in interface DequeNoSuchElementExceptionpublic Object pollFirst()
Deque
pollFirst in interface Dequepublic Object pollLast()
Deque
pollLast in interface Deque
public Object takeFirst()
throws InterruptedException
BlockingDeque
takeFirst in interface BlockingDequeInterruptedException - if interrupted while waiting
public Object takeLast()
throws InterruptedException
BlockingDeque
takeLast in interface BlockingDequeInterruptedException - if interrupted while waiting
public Object pollFirst(long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDeque
pollFirst in interface BlockingDequetimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameter
InterruptedException - if interrupted while waiting
public Object pollLast(long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDeque
pollLast in interface BlockingDequetimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameter
InterruptedException - if interrupted while waitingpublic Object getFirst()
DequepeekFirst only in that it
throws an exception if this deque is empty.
getFirst in interface DequeNoSuchElementExceptionpublic Object getLast()
DequepeekLast only in that it
throws an exception if this deque is empty.
getLast in interface DequeNoSuchElementExceptionpublic Object peekFirst()
Deque
peekFirst in interface Dequepublic Object peekLast()
Deque
peekLast in interface Dequepublic boolean removeFirstOccurrence(Object o)
BlockingDeque
removeFirstOccurrence in interface BlockingDequeremoveFirstOccurrence in interface Dequeo - element to be removed from this deque, if present
public boolean removeLastOccurrence(Object o)
BlockingDeque
removeLastOccurrence in interface BlockingDequeremoveLastOccurrence in interface Dequeo - element to be removed from this deque, if present
public boolean add(Object e)
offer.
This method is equivalent to addLast(java.lang.Object).
add in interface Collectionadd in interface BlockingDequeadd in interface BlockingQueueadd in interface Dequeadd in interface Queueadd in class AbstractQueuee - the element to add
Collection.add(E))
IllegalStateException - if the element cannot be added at this
time due to capacity restrictions
NullPointerException - if the specified element is nullpublic boolean offer(Object e)
BlockingDequeBlockingDeque.add(java.lang.Object) method, which can fail to
insert an element only by throwing an exception.
This method is equivalent to offerLast.
offer in interface BlockingDequeoffer in interface BlockingQueueoffer in interface Dequeoffer in interface Queuee - the element to add
NullPointerException - if the specified element is null
public void put(Object e)
throws InterruptedException
BlockingDequeThis method is equivalent to putLast.
put in interface BlockingDequeput in interface BlockingQueuee - the element to add
NullPointerException - if the specified element is null
InterruptedException - if interrupted while waiting
public boolean offer(Object e,
long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDequeThis method is equivalent to
offerLast.
offer in interface BlockingDequeoffer in interface BlockingQueuee - the element to addtimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameter
NullPointerException - if the specified element is null
InterruptedException - if interrupted while waitingpublic Object remove()
poll only in that it throws an
exception if this deque is empty.
This method is equivalent to removeFirst.
remove in interface BlockingDequeremove in interface Dequeremove in interface Queueremove in class AbstractQueueNoSuchElementException - if this deque is emptypublic Object poll()
BlockingDequeThis method is equivalent to Deque.pollFirst().
poll in interface BlockingDequepoll in interface Dequepoll in interface Queue
public Object take()
throws InterruptedException
BlockingDequeThis method is equivalent to takeFirst.
take in interface BlockingDequetake in interface BlockingQueueInterruptedException - if interrupted while waiting
public Object poll(long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDequeThis method is equivalent to
pollFirst.
poll in interface BlockingDequepoll in interface BlockingQueuetimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameter
InterruptedException - if interrupted while waitingpublic Object element()
peek only in that
it throws an exception if this deque is empty.
This method is equivalent to getFirst.
element in interface BlockingDequeelement in interface Dequeelement in interface Queueelement in class AbstractQueueNoSuchElementException - if this deque is emptypublic Object peek()
BlockingDequeThis method is equivalent to peekFirst.
peek in interface BlockingDequepeek in interface Dequepeek in interface Queuepublic 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.
remainingCapacity in interface BlockingQueuepublic int drainTo(Collection c)
BlockingQueue
drainTo in interface BlockingQueuec - the collection to transfer elements into
UnsupportedOperationException - if addition of elements
is not supported by the specified collection
ClassCastException - if the class of an element of this queue
prevents it from being added to the specified collection
NullPointerException - if the specified collection is null
IllegalArgumentException - if the specified collection is this
queue, or some property of an element of this queue prevents
it from being added to the specified collection
public int drainTo(Collection c,
int maxElements)
BlockingQueue
drainTo in interface BlockingQueuec - the collection to transfer elements intomaxElements - the maximum number of elements to transfer
UnsupportedOperationException - if addition of elements
is not supported by the specified collection
ClassCastException - if the class of an element of this queue
prevents it from being added to the specified collection
NullPointerException - if the specified collection is null
IllegalArgumentException - if the specified collection is this
queue, or some property of an element of this queue prevents
it from being added to the specified collectionpublic void push(Object e)
BlockingDequeThis method is equivalent to addFirst.
push in interface BlockingDequepush in interface Dequee - the element to push
IllegalStateException - if the element cannot be added at this
time due to capacity restrictions
NullPointerException - if the specified element is nullpublic Object pop()
DequeThis method is equivalent to Deque.removeFirst().
pop in interface DequeNoSuchElementExceptionpublic boolean remove(Object o)
This method is equivalent to
removeFirstOccurrence.
remove in interface Collectionremove in interface BlockingDequeremove in interface BlockingQueueremove in interface Dequeremove in class AbstractCollectiono - element to be removed from this deque, if present
public int size()