public abstract class AbstractQueue<E>
- Object
- AbstractCollection<E>
- AbstractQueue
ImplementsCollection<E>, Iterable<E>, Queue<E>
Known subtypesPriorityQueue
AbstractQueue is an abstract class which implements some of the methods in
Queue. The provided implementations of add, remove and
element are based on offer, poll, and peek except
that they throw exceptions to indicate some error instead of returning true
or false.
Type parameter E: the type of the element in the collection.
Constructors
protected AbstractQueue() | Constructor to be used by subclasses. |
Methods
public boolean add(E o) | Adds an element to the queue. |
public boolean addAll(Collection<? extends E> c) | Adds all the elements of a collection to the queue. |
public E remove() | Removes the element at the head of the queue and returns it. |
public E element() | Returns but does not remove the element at the head of the queue. |
public void clear() | Removes all elements of the queue, leaving it empty. |
Inherited methods
From AbstractCollection
contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toString, toArray, toArray
From Collection
Constructor details
AbstractQueue
protected AbstractQueue()Constructor to be used by subclasses.
Method details
add
public boolean add(E o)Adds an element to the queue.
Parameters
oE- the element to be added to the queue.
Returns
true if the operation succeeds, otherwise false.Throws
IllegalStateException- if the element is not allowed to be added to the queue.
addAll
public boolean addAll(Collection<? extends E> c)Adds all the elements of a collection to the queue. If the collection is
the queue itself, then an IllegalArgumentException will be thrown. If
during the process, some runtime exception is thrown, then those elements
in the collection which have already successfully been added will remain
in the queue. The result of the method is undefined if the collection is
modified during the process of the method.
Parameters
cCollection<? extends E>- the collection to be added to the queue.
Returns
true if the operation succeeds, otherwise false.Throws
NullPointerException- if the collection or any element of it is null.
IllegalArgumentException- If the collection to be added to the queue is the queue itself.
remove
public E remove()Removes the element at the head of the queue and returns it.
Returns
the element at the head of the queue.
Throws
NoSuchElementException- if the queue is empty.
element
public E element()Returns but does not remove the element at the head of the queue.
Returns
the element at the head of the queue.
Throws
NoSuchElementException- if the queue is empty.
clear
public void clear()Removes all elements of the queue, leaving it empty.
Throws
UnsupportedOperationException- it the iterator does not support removing elements from
this
Collection