Known Direct Subclasses
ArrayBlockingQueue<E> |
A bounded {@linkplain BlockingQueue blocking queue} backed by an
array. |
ConcurrentLinkedQueue<E> |
An unbounded thread-safe {@linkplain Queue queue} based on linked nodes. |
DelayQueue<E extends Delayed> |
An unbounded {@linkplain BlockingQueue blocking queue} of
Delayed elements, in which an element can only be taken
when its delay has expired. |
LinkedBlockingDeque<E> |
An optionally-bounded {@linkplain BlockingDeque blocking deque} based on
linked nodes. |
LinkedBlockingQueue<E> |
An optionally-bounded {@linkplain BlockingQueue blocking queue} based on
linked nodes. |
LinkedTransferQueue<E> |
An unbounded TransferQueue based on linked nodes. |
PriorityBlockingQueue<E> |
An unbounded {@linkplain BlockingQueue blocking queue} that uses
the same ordering rules as class PriorityQueue and supplies
blocking retrieval operations. |
PriorityQueue<E> |
An unbounded priority {@linkplain Queue queue} based on a priority heap. |
SynchronousQueue<E> |
A {@linkplain BlockingQueue blocking queue} in which each insert
operation must wait for a corresponding remove operation by another
thread, and vice versa. |
|
This class provides skeletal implementations of some Queue
operations. The implementations in this class are appropriate when
the base implementation does not allow null
elements. Methods add
, remove
, and
element
are based on offer
, poll
, and peek
, respectively, but throw
exceptions instead of indicating failure via false
or
null
returns.
A Queue
implementation that extends this class must
minimally define a method Queue.offer(E)
which does not permit
insertion of null
elements, along with methods Queue.peek()
, Queue.poll()
, Collection.size()
, and
Collection.iterator()
. Typically, additional methods will be
overridden as well. If these requirements cannot be met, consider
instead subclassing AbstractCollection
.
Protected Constructor Summary
Public Method Summary
boolean
|
add(E e)
Inserts the specified element into this queue if it is possible to do so
immediately without violating capacity restrictions, returning
true upon success and throwing an IllegalStateException
if no space is currently available.
|
boolean
|
addAll( Collection<? extends E> c)
Adds all of the elements in the specified collection to this
queue.
|
void
|
clear()
Removes all of the elements from this queue.
|
E
|
element()
Retrieves, but does not remove, the head of this queue.
|
E
|
remove()
Retrieves and removes the head of this queue.
|
Inherited Method Summary
From class
java.util.AbstractCollection
boolean
|
add(E e)
Ensures that this collection contains the specified element (optional
operation).
This implementation always throws an
UnsupportedOperationException.
|
boolean
|
addAll( Collection<? extends E> c)
Adds all of the elements in the specified collection to this collection
(optional operation).
This implementation iterates over the specified collection, and adds
each object returned by the iterator to this collection, in turn.
|
void
|
clear()
Removes all of the elements from this collection (optional operation).
This implementation iterates over this collection, removing each
element using the Iterator.remove operation.
|
boolean
|
contains( Object o)
Returns true if this collection contains the specified element.
This implementation iterates over the elements in the collection,
checking each element in turn for equality with the specified element.
|
boolean
|
containsAll( Collection<?> c)
Returns true if this collection contains all of the elements
in the specified collection.
This implementation iterates over the specified collection,
checking each element returned by the iterator in turn to see
if it's contained in this collection.
|
boolean
|
isEmpty()
Returns true if this collection contains no elements.
This implementation returns size() == 0.
|
abstract
Iterator<E>
|
iterator()
Returns an iterator over the elements contained in this collection.
|
boolean
|
remove( Object o)
Removes a single instance of the specified element from this
collection, if it is present (optional operation).
This implementation iterates over the collection looking for the
specified element.
|
boolean
|
removeAll( Collection<?> c)
Removes all of this collection's elements that are also contained in the
specified collection (optional operation).
This implementation iterates over this collection, checking each
element returned by the iterator in turn to see if it's contained
in the specified collection.
|
boolean
|
retainAll( Collection<?> c)
Retains only the elements in this collection that are contained in the
specified collection (optional operation).
This implementation iterates over this collection, checking each
element returned by the iterator in turn to see if it's contained
in the specified collection.
|
abstract
int
|
size()
Returns the number of elements in this collection.
|
<T>
T[]
|
toArray(T[] contents)
Returns an array containing all of the elements in this collection;
the runtime type of the returned array is that of the specified array.
This implementation returns an array containing all the elements
returned by this collection's iterator in the same order, stored in
consecutive elements of the array, starting with index 0 .
|
Object[]
|
toArray()
Returns an array containing all of the elements in this collection.
This implementation returns an array containing all the elements
returned by this collection's iterator, in the same order, stored in
consecutive elements of the array, starting with index 0 .
|
String
|
toString()
Returns a string representation of this collection.
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals( Object obj)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long timeout, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long timeout)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
From interface
java.util.Collection
abstract
boolean
|
add(E e)
Ensures that this collection contains the specified element (optional
operation).
|
abstract
boolean
|
addAll( Collection<? extends E> c)
Adds all of the elements in the specified collection to this collection
(optional operation).
|
abstract
void
|
clear()
Removes all of the elements from this collection (optional operation).
|
abstract
boolean
|
contains( Object o)
Returns true if this collection contains the specified element.
|
abstract
boolean
|
containsAll( Collection<?> c)
Returns true if this collection contains all of the elements
in the specified collection.
|
abstract
boolean
|
equals( Object o)
Compares the specified object with this collection for equality.
|
abstract
int
|
hashCode()
Returns the hash code value for this collection.
|
abstract
boolean
|
isEmpty()
Returns true if this collection contains no elements.
|
abstract
Iterator<E>
|
iterator()
Returns an iterator over the elements in this collection.
|
Stream<E>
|
parallelStream()
Returns a possibly parallel Stream with this collection as its
source.
|
abstract
boolean
|
remove( Object o)
Removes a single instance of the specified element from this
collection, if it is present (optional operation).
|
abstract
boolean
|
removeAll( Collection<?> c)
Removes all of this collection's elements that are also contained in the
specified collection (optional operation).
|
boolean
|
removeIf( Predicate<? super E> filter)
Removes all of the elements of this collection that satisfy the given
predicate.
|
abstract
boolean
|
retainAll( Collection<?> c)
Retains only the elements in this collection that are contained in the
specified collection (optional operation).
|
abstract
int
|
size()
Returns the number of elements in this collection.
|
Spliterator<E>
|
|
Stream<E>
|
stream()
Returns a sequential Stream with this collection as its source.
|
abstract
<T>
T[]
|
toArray(T[] a)
Returns an array containing all of the elements in this collection;
the runtime type of the returned array is that of the specified array.
|
abstract
Object[]
|
toArray()
Returns an array containing all of the elements in this collection.
|
From interface
java.util.Queue
abstract
boolean
|
add(E e)
Inserts the specified element into this queue if it is possible to do so
immediately without violating capacity restrictions, returning
true upon success and throwing an IllegalStateException
if no space is currently available.
|
abstract
E
|
element()
Retrieves, but does not remove, the head of this queue.
|
abstract
boolean
|
offer(E e)
Inserts the specified element into this queue if it is possible to do
so immediately without violating capacity restrictions.
|
abstract
E
|
peek()
Retrieves, but does not remove, the head of this queue,
or returns null if this queue is empty.
|
abstract
E
|
poll()
Retrieves and removes the head of this queue,
or returns null if this queue is empty.
|
abstract
E
|
remove()
Retrieves and removes the head of this queue.
|
Protected Constructors
protected
AbstractQueue
()
Constructor for use by subclasses.
Public Methods
public
boolean
add
(E e)
Inserts the specified element into this queue if it is possible to do so
immediately without violating capacity restrictions, returning
true
upon success and throwing an IllegalStateException
if no space is currently available.
This implementation returns true
if offer
succeeds,
else throws an IllegalStateException
.
public
boolean
addAll
(Collection<? extends E> c)
Adds all of the elements in the specified collection to this
queue. Attempts to addAll of a queue to itself result in
IllegalArgumentException
. Further, the behavior of
this operation is undefined if the specified collection is
modified while the operation is in progress.
This implementation iterates over the specified collection,
and adds each element returned by the iterator to this
queue, in turn. A runtime exception encountered while
trying to add an element (including, in particular, a
null
element) may result in only some of the elements
having been successfully added when the associated exception is
thrown.
Parameters
c |
collection containing elements to be added to this queue |
Returns
true
if this queue changed as a result of the call
Throws
ClassCastException |
if the class of an element of the specified
collection prevents it from being added to this queue |
NullPointerException |
if the specified collection contains a
null element and this queue does not permit null elements,
or if the specified collection is null |
IllegalArgumentException |
if some property of an element of the
specified collection prevents it from being added to this
queue, or if the specified collection is this queue |
IllegalStateException |
if not all the elements can be added at
this time due to insertion restrictions |
public
void
clear
()
Removes all of the elements from this queue.
The queue will be empty after this call returns.
This implementation repeatedly invokes poll
until it
returns null
.
public
E
element
()
Retrieves, but does not remove, the head of this queue. This method
differs from peek
only in that it throws an exception if
this queue is empty.
This implementation returns the result of peek
unless the queue is empty.
public
E
remove
()
Retrieves and removes the head of this queue. This method differs
from poll
only in that it throws an exception if this
queue is empty.
This implementation returns the result of poll
unless the queue is empty.