AbstractQueue

abstract class AbstractQueue<E> : AbstractCollection<E> , Queue<E>

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 which does not permit insertion of null elements, along with methods , 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.

This class is a member of the {@docRoot}/java.base/java/util/package-summary.html#CollectionsFramework.

Since

1.5

Author

Doug Lea

Parameters

the type of elements held in this queue

Inheritors

Properties

Link copied to clipboard
abstract override val size: Int

Functions

Link copied to clipboard
open override fun add(e: E): Boolean

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.

Link copied to clipboard
open override fun addAll(c: Collection<E>): Boolean

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.

Link copied to clipboard
open override fun clear()

Removes all of the elements from this queue. The queue will be empty after this call returns.

Link copied to clipboard
open operator override fun contains(element: E): Boolean
Link copied to clipboard
open override fun containsAll(elements: Collection<E>): Boolean
Link copied to clipboard
open override fun element(): E

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.

Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
abstract operator override fun iterator(): MutableIterator<E>
Link copied to clipboard
abstract fun offer(e: E): Boolean

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. When using a capacity-restricted queue, this method is generally preferable to .add, which can fail to insert an element only by throwing an exception.

Link copied to clipboard
abstract fun peek(): E?

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Link copied to clipboard
abstract fun poll(): E?

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Link copied to clipboard
abstract fun remove(element: E): Boolean

open override fun remove(): E

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.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun toString(): String