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 waitingNullPointerException - if the specified element is nullvoid putLast(E o) throws InterruptedException
o - the element to addInterruptedException - if interrupted while waitingNullPointerException - if the specified element is nullE takeFirst() throws InterruptedException
InterruptedException - if interrupted while waitingE takeLast() throws InterruptedException
InterruptedException - if interrupted while waitingboolean 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 parametertrue if successful, or false if
the specified waiting time elapses before space is availableInterruptedException - if interrupted while waitingNullPointerException - if the specified element is nullboolean 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 parametertrue if successful, or false if
the specified waiting time elapses before space is availableInterruptedException - if interrupted while waitingNullPointerException - if the specified element is nullE 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 parameternull if the
specified waiting time elapses before an element is presentInterruptedException - if interrupted while waitingE 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 parameternull if the
specified waiting time elapses before an element is presentInterruptedException - if interrupted while waitingvoid put(E o) throws InterruptedException
put in interface BlockingQueue<E>o - the element to addInterruptedException - if interrupted while waitingNullPointerException - if the specified element is nullboolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException
offer is generally preferable to method Collection.add(E), which can fail to insert an element only by
throwing an exception. This method is equivalent to
offerLast.offer in interface BlockingQueue<E>o - the element to addtrue if it was possible to add the element to
this deque, else falseNullPointerException - if the specified element is nullInterruptedExceptionE take() throws InterruptedException
take in interface BlockingQueue<E>InterruptedException - if interrupted while waitingE 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 parameternull if the
specified waiting time elapses before an element is presentInterruptedException - if interrupted while waiting