public class PriorityBlockingDeque<E> extends AbstractQueue<E> implements BlockingDeque<E>, Serializable
The optional capacity bound constructor argument serves as a
way to prevent excessive expansion. The capacity, if unspecified,
is equal to Integer.MAX_VALUE
.
This class and its iterator implement all of the
optional methods of the Collection
and Iterator
interfaces.
Constructor and Description |
---|
PriorityBlockingDeque()
Creates a PriorityBlockingDeque with a capacity of
Integer.MAX_VALUE . |
PriorityBlockingDeque(Comparator<E> comparator,
int capacity) |
PriorityBlockingDeque(int capacity)
Creates a PriorityBlockingDeque with the given (fixed) capacity.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e)
Inserts the specified element to the deque unless it would
violate capacity restrictions.
|
void |
addFirst(E e) |
void |
addLast(E e) |
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<E> |
descendingIterator() |
int |
drainTo(Collection<? super E> c) |
int |
drainTo(Collection<? super E> c,
int maxElements) |
E |
element()
Retrieves, but does not remove, the head of the queue represented by
this deque.
|
E |
getFirst() |
E |
getLast() |
Iterator<E> |
iterator() |
boolean |
offer(E e) |
boolean |
offer(E e,
long timeout,
TimeUnit unit) |
boolean |
offerFirst(E e) |
boolean |
offerFirst(E e,
long timeout,
TimeUnit unit) |
boolean |
offerLast(E e) |
boolean |
offerLast(E e,
long timeout,
TimeUnit unit) |
E |
peek() |
E |
peekFirst() |
E |
peekLast() |
E |
poll() |
E |
poll(long timeout,
TimeUnit unit) |
E |
pollFirst() |
E |
pollFirst(long timeout,
TimeUnit unit) |
E |
pollLast() |
E |
pollLast(long timeout,
TimeUnit unit) |
E |
pop() |
void |
push(E e) |
void |
put(E e) |
void |
putFirst(E e) |
void |
putLast(E e) |
int |
remainingCapacity()
Returns the number of additional 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(Object o)
Removes the first occurrence of the specified element from this deque.
|
E |
removeFirst() |
boolean |
removeFirstOccurrence(Object o) |
E |
removeLast() |
boolean |
removeLastOccurrence(Object o) |
int |
size()
Returns the number of elements in this deque.
|
E |
take() |
E |
takeFirst() |
E |
takeLast() |
Object[] |
toArray()
Returns an array containing all of the elements in this deque, in
proper sequence (from first to last element).
|
<T> T[] |
toArray(T[] 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() |
addAll
containsAll, isEmpty, removeAll, retainAll
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addAll, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream
public PriorityBlockingDeque()
Integer.MAX_VALUE
.public PriorityBlockingDeque(int capacity)
capacity
- the capacity of this dequeIllegalArgumentException
- if capacity is less than 1public PriorityBlockingDeque(Comparator<E> comparator, int capacity)
public void addFirst(E e)
addFirst
in interface BlockingDeque<E>
addFirst
in interface Deque<E>
IllegalStateException
NullPointerException
public void addLast(E e)
addLast
in interface BlockingDeque<E>
addLast
in interface Deque<E>
IllegalStateException
NullPointerException
public boolean offerFirst(E e)
offerFirst
in interface BlockingDeque<E>
offerFirst
in interface Deque<E>
NullPointerException
public boolean offerLast(E e)
offerLast
in interface BlockingDeque<E>
offerLast
in interface Deque<E>
NullPointerException
public void putFirst(E e) throws InterruptedException
putFirst
in interface BlockingDeque<E>
NullPointerException
InterruptedException
public void putLast(E e) throws InterruptedException
putLast
in interface BlockingDeque<E>
NullPointerException
InterruptedException
public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException
offerFirst
in interface BlockingDeque<E>
NullPointerException
InterruptedException
public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException
offerLast
in interface BlockingDeque<E>
NullPointerException
InterruptedException
public E removeFirst()
removeFirst
in interface Deque<E>
NoSuchElementException
public E removeLast()
removeLast
in interface Deque<E>
NoSuchElementException
public E takeFirst() throws InterruptedException
takeFirst
in interface BlockingDeque<E>
InterruptedException
public E takeLast() throws InterruptedException
takeLast
in interface BlockingDeque<E>
InterruptedException
public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException
pollFirst
in interface BlockingDeque<E>
InterruptedException
public E pollLast(long timeout, TimeUnit unit) throws InterruptedException
pollLast
in interface BlockingDeque<E>
InterruptedException
public E getFirst()
getFirst
in interface Deque<E>
NoSuchElementException
public E getLast()
getLast
in interface Deque<E>
NoSuchElementException
public boolean removeFirstOccurrence(Object o)
removeFirstOccurrence
in interface BlockingDeque<E>
removeFirstOccurrence
in interface Deque<E>
public boolean removeLastOccurrence(Object o)
removeLastOccurrence
in interface BlockingDeque<E>
removeLastOccurrence
in interface Deque<E>
public boolean add(E e)
offer
.
This method is equivalent to addLast(E)
.
add
in interface Collection<E>
add
in interface BlockingDeque<E>
add
in interface BlockingQueue<E>
add
in interface Deque<E>
add
in interface Queue<E>
add
in class AbstractQueue<E>
IllegalStateException
- if the element cannot be added at this
time due to capacity restrictionsNullPointerException
- if the specified element is nullpublic boolean offer(E e)
offer
in interface BlockingDeque<E>
offer
in interface BlockingQueue<E>
offer
in interface Deque<E>
offer
in interface Queue<E>
NullPointerException
- if the specified element is nullpublic void put(E e) throws InterruptedException
put
in interface BlockingDeque<E>
put
in interface BlockingQueue<E>
NullPointerException
InterruptedException
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
offer
in interface BlockingDeque<E>
offer
in interface BlockingQueue<E>
NullPointerException
InterruptedException
public E remove()
poll
only in that it throws an
exception if this deque is empty.
This method is equivalent to removeFirst
.
remove
in interface BlockingDeque<E>
remove
in interface Deque<E>
remove
in interface Queue<E>
remove
in class AbstractQueue<E>
NoSuchElementException
- if this deque is emptypublic E poll()
public E take() throws InterruptedException
take
in interface BlockingDeque<E>
take
in interface BlockingQueue<E>
InterruptedException
public E poll(long timeout, TimeUnit unit) throws InterruptedException
poll
in interface BlockingDeque<E>
poll
in interface BlockingQueue<E>
InterruptedException
public E element()
peek
only in that
it throws an exception if this deque is empty.
This method is equivalent to getFirst
.
element
in interface BlockingDeque<E>
element
in interface Deque<E>
element
in interface Queue<E>
element
in class AbstractQueue<E>
NoSuchElementException
- if this deque is emptypublic E peek()
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.
remainingCapacity
in interface BlockingQueue<E>
public int drainTo(Collection<? super E> c)
drainTo
in interface BlockingQueue<E>
UnsupportedOperationException
ClassCastException
NullPointerException
IllegalArgumentException
public int drainTo(Collection<? super E> c, int maxElements)
drainTo
in interface BlockingQueue<E>
UnsupportedOperationException
ClassCastException
NullPointerException
IllegalArgumentException
public void push(E e)
push
in interface BlockingDeque<E>
push
in interface Deque<E>
IllegalStateException
NullPointerException
public E pop()
pop
in interface Deque<E>
NoSuchElementException
public boolean remove(Object o)
This method is equivalent to
removeFirstOccurrence
.
remove
in interface Collection<E>
remove
in interface BlockingDeque<E>
remove
in interface BlockingQueue<E>
remove
in interface Deque<E>
remove
in class AbstractCollection<E>
o
- element to be removed from this deque, if presentpublic int size()
size
in interface Collection<E>
size
in interface BlockingDeque<E>
size
in interface Deque<E>
size
in class AbstractCollection<E>
public boolean contains(Object o)
contains
in interface Collection<E>
contains
in interface BlockingDeque<E>
contains
in interface BlockingQueue<E>
contains
in interface Deque<E>
contains
in class AbstractCollection<E>
o
- object to be checked for containment in this dequepublic 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 interface Collection<E>
toArray
in class AbstractCollection<E>
public <T> T[] toArray(T[] 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 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 interface Collection<E>
toArray
in class AbstractCollection<E>
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 purposeArrayStoreException
- if the runtime type of the specified array
is not a supertype of the runtime type of every element in
this dequeNullPointerException
- if the specified array is nullpublic String toString()
toString
in class AbstractCollection<E>
public void clear()
clear
in interface Collection<E>
clear
in class AbstractQueue<E>
public Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in interface BlockingDeque<E>
iterator
in interface Deque<E>
iterator
in class AbstractCollection<E>
public Iterator<E> descendingIterator()
descendingIterator
in interface Deque<E>
Copyright © 2016 The Apache Software Foundation. All rights reserved.