Class AbstractQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
- Type Parameters:
E- the type of the element in the collection.
- All Implemented Interfaces:
Iterable<E>, Collection<E>, Queue<E>
- Direct Known Subclasses:
PriorityQueue
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.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds an element to the queue.booleanaddAll(Collection<? extends E> c) Adds all the elements of a collection to the queue.voidclear()Removes all elements of the queue, leaving it empty.element()Returns but does not remove the element at the head of the queue.remove()Removes the element at the head of the queue and returns it.Methods inherited from class AbstractCollection
contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toStringMethods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
AbstractQueue
protected AbstractQueue()Constructor to be used by subclasses.
-
-
Method Details
-
add
Adds an element to the queue.- Specified by:
addin interfaceCollection<E>- Overrides:
addin classAbstractCollection<E>- Parameters:
o- the element to be added to the queue.- Returns:
trueif the operation succeeds, otherwisefalse.- Throws:
IllegalStateException- if the element is not allowed to be added to the queue.
-
addAll
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.- Specified by:
addAllin interfaceCollection<E>- Overrides:
addAllin classAbstractCollection<E>- Parameters:
c- the collection to be added to the queue.- Returns:
trueif the operation succeeds, otherwisefalse.- 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
Removes the element at the head of the queue and returns it.- Specified by:
removein interfaceQueue<E>- Returns:
- the element at the head of the queue.
- Throws:
NoSuchElementException- if the queue is empty.
-
element
Returns but does not remove the element at the head of the queue.- Specified by:
elementin interfaceQueue<E>- 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.- Specified by:
clearin interfaceCollection<E>- Overrides:
clearin classAbstractCollection<E>- See Also:
-