|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractQueue<E>
org.jboss.messaging.utils.concurrent.LinkedBlockingDeque<E>
E
- the type of elements held in this collectionpublic class LinkedBlockingDeque<E>
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.
Constructor Summary | |
---|---|
LinkedBlockingDeque()
Creates a LinkedBlockingDeque with a capacity of Integer.MAX_VALUE . |
|
LinkedBlockingDeque(java.util.Collection<? extends E> 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(E e)
Inserts the specified element into the queue represented by this deque unless it would violate capacity restrictions. |
|
void |
addFirst(E e)
Inserts the specified element to the front of this deque unless it would violate capacity restrictions. |
|
void |
addLast(E e)
Inserts the specified element to the end of this deque unless it would violate capacity restrictions. |
|
void |
clear()
Atomically removes all of the elements from this deque. |
|
boolean |
contains(java.lang.Object o)
|
|
int |
drainTo(java.util.Collection<? super E> c)
|
|
int |
drainTo(java.util.Collection<? super E> c,
int maxElements)
|
|
E |
element()
Retrieves, but does not remove, the head of the queue represented by this deque. |
|
E |
getFirst()
Retrieves, but does not remove, the first element of this deque. |
|
E |
getLast()
Retrieves, but does not remove, the last element of this deque. |
|
java.util.Iterator<E> |
iterator()
Returns an iterator over the elements in this deque in proper sequence. |
|
boolean |
offer(E e)
Inserts the specified element into the queue represented by this deque unless it would violate capacity restrictions. |
|
boolean |
offer(E o,
long timeout,
java.util.concurrent.TimeUnit unit)
Inserts the specified element as the lest element of this deque, if possible. |
|
boolean |
offerFirst(E o)
Inserts the specified element to the front this deque unless it would violate capacity restrictions. |
|
boolean |
offerFirst(E o,
long timeout,
java.util.concurrent.TimeUnit unit)
Inserts the specified element as the first element of this deque, waiting if necessary up to the specified wait time for space to become available. |
|
boolean |
offerLast(E o)
Inserts the specified element to the end of this deque unless it would violate capacity restrictions. |
|
boolean |
offerLast(E o,
long timeout,
java.util.concurrent.TimeUnit unit)
Inserts the specified element as the last element of this deque, waiting if necessary up to the specified wait time for space to become available. |
|
E |
peek()
Retrieves, but does not remove, the head of the queue represented by this deque, returning null if this deque is empty. |
|
E |
peekFirst()
Retrieves, but does not remove, the first element of this deque, returning null if this deque is empty. |
|
E |
peekLast()
Retrieves, but does not remove, the last element of this deque, returning null if this deque is empty. |
|
E |
poll()
Retrieves and removes the head of the queue represented by this deque, or null if this deque is empty. |
|
E |
poll(long timeout,
java.util.concurrent.TimeUnit unit)
Retrieves and removes the first element of this deque, waiting if necessary up to the specified wait time if no elements are present on this deque. |
|
E |
pollFirst()
Retrieves and removes the first element of this deque, or null if this deque is empty. |
|
E |
pollFirst(long timeout,
java.util.concurrent.TimeUnit unit)
Retrieves and removes the first element of this deque, waiting if necessary up to the specified wait time if no elements are present on this deque. |
|
E |
pollLast()
Retrieves and removes the last element of this deque, or null if this deque is empty. |
|
E |
pollLast(long timeout,
java.util.concurrent.TimeUnit unit)
Retrieves and removes the last element of this deque, waiting if necessary up to the specified wait time if no elements are present on this deque. |
|
E |
pop()
Pops an element from the stack represented by this deque. |
|
void |
push(E e)
Pushes an element onto the stack represented by this deque. |
|
void |
put(E o)
Adds the specified element as the last element of this deque, waiting if necessary for space to become available. |
|
void |
putFirst(E o)
Adds the specified element as the first element of this deque, waiting if necessary for space to become available. |
|
void |
putLast(E o)
Adds the specified element as the last element of this deque, waiting if necessary for space to become available. |
|
int |
remainingCapacity()
Returns the number of elements that this deque can ideally (in the absence of memory or resource constraints) accept without blocking. |
|
E |
remove()
Retrieves and removes the head of the queue represented by this deque. |
|
boolean |
remove(java.lang.Object o)
|
|
E |
removeFirst()
Removes and returns the first element of this deque. |
|
boolean |
removeFirstOccurrence(java.lang.Object e)
Removes the first occurrence of the specified element in this deque. |
|
E |
removeLast()
Retrieves and removes the last element of this deque. |
|
boolean |
removeLastOccurrence(java.lang.Object e)
Removes the last occurrence of the specified element in this deque. |
|
int |
size()
Returns the number of elements in this deque. |
|
E |
take()
Retrieves and removes the first element of this deque, waiting if no elements are present on this deque. |
|
E |
takeFirst()
Retrieves and removes the first element of this deque, waiting if no elements are present on this deque. |
|
E |
takeLast()
Retrieves and removes the last element of this deque, waiting if no elements are present on this deque. |
|
java.lang.Object[] |
toArray()
|
|
|
toArray(T[] a)
|
|
java.lang.String |
toString()
|
Methods inherited from class 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
java.lang.IllegalArgumentException
- if capacity is less than 1public LinkedBlockingDeque(java.util.Collection<? extends E> 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
java.lang.NullPointerException
- if c or any element within it
is nullMethod Detail |
---|
public boolean offerFirst(E o)
Deque
offerFirst
in interface Deque<E>
o
- the element to insert
public boolean offerLast(E o)
Deque
offerLast
in interface Deque<E>
o
- the element to insert
public void addFirst(E e)
Deque
addFirst
in interface Deque<E>
e
- the element to insertpublic void addLast(E e)
Deque
addLast
in interface Deque<E>
e
- the element to insertpublic E pollFirst()
Deque
pollFirst
in interface Deque<E>
public E pollLast()
Deque
pollLast
in interface Deque<E>
public E removeFirst()
Deque
removeFirst
in interface Deque<E>
public E removeLast()
Deque
removeLast
in interface Deque<E>
public E peekFirst()
Deque
peekFirst
in interface Deque<E>
public E peekLast()
Deque
peekLast
in interface Deque<E>
public E getFirst()
Deque
getFirst
in interface Deque<E>
public E getLast()
Deque
getLast
in interface Deque<E>
public void putFirst(E o) throws java.lang.InterruptedException
BlockingDeque
putFirst
in interface BlockingDeque<E>
o
- the element to add
java.lang.InterruptedException
- if interrupted while waiting.public void putLast(E o) throws java.lang.InterruptedException
BlockingDeque
putLast
in interface BlockingDeque<E>
o
- the element to add
java.lang.InterruptedException
- if interrupted while waiting.public E takeFirst() throws java.lang.InterruptedException
BlockingDeque
takeFirst
in interface BlockingDeque<E>
java.lang.InterruptedException
- if interrupted while waiting.public E takeLast() throws java.lang.InterruptedException
BlockingDeque
takeLast
in interface BlockingDeque<E>
java.lang.InterruptedException
- if interrupted while waiting.public boolean offerFirst(E o, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
BlockingDeque
offerFirst
in interface BlockingDeque<E>
o
- the element to addtimeout
- how long to wait before giving up, in units of
unitunit
- a TimeUnit determining how to interpret the
timeout parameter
java.lang.InterruptedException
- if interrupted while waiting.public boolean offerLast(E o, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
BlockingDeque
offerLast
in interface BlockingDeque<E>
o
- the element to addtimeout
- how long to wait before giving up, in units of
unitunit
- a TimeUnit determining how to interpret the
timeout parameter
java.lang.InterruptedException
- if interrupted while waiting.public E pollFirst(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
BlockingDeque
pollFirst
in interface BlockingDeque<E>
timeout
- how long to wait before giving up, in units of
unitunit
- a TimeUnit determining how to interpret the
timeout parameter
java.lang.InterruptedException
- if interrupted while waiting.public E pollLast(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
BlockingDeque
pollLast
in interface BlockingDeque<E>
timeout
- how long to wait before giving up, in units of
unitunit
- a TimeUnit determining how to interpret the
timeout parameter
java.lang.InterruptedException
- if interrupted while waiting.public boolean offer(E e)
Deque
Deque.add(E)
method, which can fail to insert an element only by
throwing an exception.
This method is equivalent to Deque.offerLast(E)
.
offer
in interface java.util.concurrent.BlockingQueue<E>
offer
in interface java.util.Queue<E>
offer
in interface Deque<E>
e
- the element to insert
public boolean add(E e)
Deque
This method is equivalent to Deque.addLast(E)
.
add
in interface java.util.Collection<E>
add
in interface java.util.concurrent.BlockingQueue<E>
add
in interface Deque<E>
add
in class java.util.AbstractQueue<E>
e
- the element to insert
Collection.add(E)
)public void push(E e)
Deque
This method is equivalent to Deque.addFirst(E)
.
push
in interface Deque<E>
public E poll()
Deque
This method is equivalent to Deque.pollFirst()
.
poll
in interface java.util.Queue<E>
poll
in interface Deque<E>
public E remove()
Deque
This method is equivalent to Deque.removeFirst()
.
remove
in interface java.util.Queue<E>
remove
in interface Deque<E>
remove
in class java.util.AbstractQueue<E>
public E pop()
Deque
This method is equivalent to Deque.removeFirst()
.
pop
in interface Deque<E>
public E peek()
Deque
This method is equivalent to Deque.peekFirst()
peek
in interface java.util.Queue<E>
peek
in interface Deque<E>
public E element()
Deque
This method is equivalent to Deque.getFirst()
element
in interface java.util.Queue<E>
element
in interface Deque<E>
element
in class java.util.AbstractQueue<E>
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection<E>
remove
in class java.util.AbstractCollection<E>
public void put(E o) throws java.lang.InterruptedException
BlockingDeque
put
in interface java.util.concurrent.BlockingQueue<E>
put
in interface BlockingDeque<E>
o
- the element to add
java.lang.InterruptedException
- if interrupted while waiting.public E take() throws java.lang.InterruptedException
BlockingDeque
take
in interface java.util.concurrent.BlockingQueue<E>
take
in interface BlockingDeque<E>
java.lang.InterruptedException
- if interrupted while waiting.public boolean offer(E o, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
BlockingDeque
Collection.add(E)
, which can fail to insert an element only by
throwing an exception. This method is equivalent to to
offerLast
offer
in interface java.util.concurrent.BlockingQueue<E>
offer
in interface BlockingDeque<E>
o
- the element to add.
java.lang.InterruptedException
public E poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
BlockingDeque
poll
in interface java.util.concurrent.BlockingQueue<E>
poll
in interface BlockingDeque<E>
timeout
- how long to wait before giving up, in units of
unitunit
- a TimeUnit determining how to interpret the
timeout parameter
java.lang.InterruptedException
- if interrupted while waiting.public int size()
size
in interface java.util.Collection<E>
size
in class java.util.AbstractCollection<E>
public int remainingCapacity()
Note that you cannot always tell if an attempt to add an element will succeed by inspecting remainingCapacity because it may be the case that a waiting consumer is ready to take an element out of an otherwise full deque.
remainingCapacity
in interface java.util.concurrent.BlockingQueue<E>
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<E>
contains
in class java.util.AbstractCollection<E>
public boolean removeFirstOccurrence(java.lang.Object e)
Deque
removeFirstOccurrence
in interface Deque<E>
e
- element to be removed from this deque, if present
public boolean removeLastOccurrence(java.lang.Object e)
Deque
removeLastOccurrence
in interface Deque<E>
e
- element to be removed from this deque, if present
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<E>
toArray
in class java.util.AbstractCollection<E>
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<E>
toArray
in class java.util.AbstractCollection<E>
public java.lang.String toString()
toString
in class java.util.AbstractCollection<E>
public void clear()
clear
in interface java.util.Collection<E>
clear
in class java.util.AbstractQueue<E>
public int drainTo(java.util.Collection<? super E> c)
drainTo
in interface java.util.concurrent.BlockingQueue<E>
public int drainTo(java.util.Collection<? super E> c, int maxElements)
drainTo
in interface java.util.concurrent.BlockingQueue<E>
public java.util.Iterator<E> iterator()
ConcurrentModificationException
,
and guarantees to traverse elements as they existed upon
construction of the iterator, and may (but is not guaranteed to)
reflect any modifications subsequent to construction.
iterator
in interface java.lang.Iterable<E>
iterator
in interface java.util.Collection<E>
iterator
in interface Deque<E>
iterator
in class java.util.AbstractCollection<E>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |