E - the type of elements held in this collectionpublic interface BlockingDeque<E> extends Deque<E>, BlockingQueue<E>
Deque that additionally supports operations that wait for
the deque to become non-empty when retrieving an element, and wait
for space to become available in the deque when storing an
element. These methods are summarized in the following table:
| First Element (Head) | Last Element (Tail) | |||
| Block | Time out | Block | Time out | |
| Insert | putFirst(e) |
offerFirst(e, time, unit) |
putLast(e) |
offerLast(e, time, unit) |
| Remove | takeFirst() |
pollFirst(time, unit) |
takeLast() |
pollLast(time, unit) |
Like any BlockingQueue, a BlockingDeque is
thread safe and may (or may not) be capacity-constrained. A
BlockingDeque implementation may be used directly as a
FIFO BlockingQueue. The blocking methods inherited from
the BlockingQueue interface are precisely equivalent to
BlockingDeque methods as indicated in the following table:
| BlockingQueue Method | Equivalent BlockingDeque Method |
put(e) |
putLast(e) |
take() |
takeFirst() |
offer(e, time. unit) |
offerLast(e, time, unit) |
poll(time, unit) |
pollFirst(time, unit) |
This interface is a member of the Java Collections Framework.
| Modifier and Type | Method and Description |
|---|---|
boolean |
offer(E o,
long timeout,
TimeUnit unit)
Inserts the specified element as the lest element of this
deque, if possible.
|
boolean |
offerFirst(E o,
long timeout,
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,
long timeout,
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 |
poll(long timeout,
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(long timeout,
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(long timeout,
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.
|
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.
|
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.
|
add, addFirst, addLast, element, getFirst, getLast, iterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrenceadd, contains, drainTo, drainTo, offer, remainingCapacity, removevoid putFirst(E o) throws InterruptedException
o - the element to addInterruptedException - if interrupted while waiting.NullPointerException - if the specified element is null.void putLast(E o) throws InterruptedException
o - the element to addInterruptedException - if interrupted while waiting.NullPointerException - if the specified element is null.E takeFirst() throws InterruptedException
InterruptedException - if interrupted while waiting.E takeLast() throws InterruptedException
InterruptedException - if interrupted while waiting.boolean offerFirst(E o, long timeout, TimeUnit unit) throws InterruptedException
o - the element to addtimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameterInterruptedException - if interrupted while waiting.NullPointerException - if the specified element is null.boolean offerLast(E o, long timeout, TimeUnit unit) throws InterruptedException
o - the element to addtimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameterInterruptedException - if interrupted while waiting.NullPointerException - if the specified element is null.E pollFirst(long timeout, TimeUnit unit) throws InterruptedException
timeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameterInterruptedException - if interrupted while waiting.E pollLast(long timeout, TimeUnit unit) throws InterruptedException
timeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameterInterruptedException - if interrupted while waiting.void put(E o) throws InterruptedException
put in interface BlockingQueue<E>o - the element to addInterruptedException - if interrupted while waiting.NullPointerException - if the specified element is null.boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException
Collection.add(E), which can fail to insert an element only by
throwing an exception. This method is equivalent to
offerLastoffer in interface BlockingQueue<E>o - the element to add.timeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameterNullPointerException - if the specified element is nullInterruptedException - if interrupted while waitingE take() throws InterruptedException
take in interface BlockingQueue<E>InterruptedException - if interrupted while waiting.E poll(long timeout, TimeUnit unit) throws InterruptedException
poll in interface BlockingQueue<E>timeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameterInterruptedException - if interrupted while waiting.