E
- the type of the element in the collection.public abstract class AbstractQueue<E> extends AbstractCollection<E> implements Queue<E>
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.Modifier | Constructor and Description |
---|---|
protected |
AbstractQueue()
Constructor to be used by subclasses.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o)
Adds an element to the queue.
|
boolean |
addAll(Collection<? extends E> c)
Adds all the elements of a collection to the queue.
|
void |
clear()
Removes all elements of the queue, leaving it empty.
|
E |
element()
Returns but does not remove the element at the head of the queue.
|
E |
remove()
Removes the element at the head of the queue and returns it.
|
contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
public boolean add(E o)
add
in interface Collection<E>
add
in class AbstractCollection<E>
o
- the element to be added to the queue.true
if the operation succeeds, otherwise false
.IllegalStateException
- if the element is not allowed to be added to the queue.public boolean addAll(Collection<? extends E> c)
addAll
in interface Collection<E>
addAll
in class AbstractCollection<E>
c
- the collection to be added to the queue.true
if the operation succeeds, otherwise false
.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.public E remove()
remove
in interface Queue<E>
NoSuchElementException
- if the queue is empty.public E element()
element
in interface Queue<E>
NoSuchElementException
- if the queue is empty.public void clear()
clear
in interface Collection<E>
clear
in class AbstractCollection<E>
AbstractCollection.iterator()
,
AbstractCollection.isEmpty()
,
AbstractCollection.size()