Stay organized with collections
Save and categorize content based on your preferences.
AI-generated Key Takeaways
AbstractQueue is a skeletal implementation of the Queue interface in Java, designed for queues that do not permit null elements and requiring subclasses to implement core methods like offer, peek, poll, size, and iterator.
It provides base implementations for methods like add, remove, and element which utilize the core methods and throw exceptions upon failure instead of returning false or null.
Common queue implementations like ArrayBlockingQueue, PriorityQueue, and ConcurrentLinkedQueue are direct subclasses of AbstractQueue.
The class includes methods for adding elements (add, addAll), clearing the queue (clear), and retrieving the head element (element, remove).
AbstractQueue simplifies queue creation by providing a foundation for handling non-null elements and common queue operations, leaving specific implementation details to subclasses.
An unbounded {@linkplain BlockingQueue blocking queue} that uses
the same ordering rules as class PriorityQueue and supplies
blocking retrieval operations.
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.
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.
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.
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.
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.
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.
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.
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.
Creates a Spliterator over the elements described by this
Iterable.
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.
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
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[],["`AbstractQueue` offers a base for `Queue` implementations that disallow `null` elements. Subclasses must implement `offer`, `peek`, `poll`, `size`, and `iterator`; they should also override other inherited methods, or use `AbstractCollection` instead. `add`, `remove`, and `element` methods are provided and are based on `offer`, `poll`, and `peek` respectively, throwing exceptions on failure. `addAll` adds a collection, and clear removes all elements by repeatedly calling poll.\n"]]