| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public abstract class AbstractQueue extends AbstractCollection implements Queue
This class provides skeletal implementations of some {@link Queue} operations. The implementations in this class are appropriate when the base implementation does not allow null elements. Methods {@link #add add}, {@link #remove remove}, and {@link #element element} are based on {@link #offer offer}, {@link #poll poll}, and {@link #peek 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 {@link Queue#offer} which does not permit insertion of null elements, along with methods {@link Queue#peek}, {@link Queue#poll}, {@link Collection#size}, and a {@link Collection#iterator} supporting {@link Iterator#remove}. Typically, additional methods will be overridden as well. If these requirements cannot be met, consider instead subclassing {@link AbstractCollection}.
This class is a member of the Java Collections Framework.
Constructor Summary | |
---|---|
protected |
Constructor for use by subclasses. |
Method Summary | |
---|---|
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. |
boolean |
addAll(Collection c) Adds all of the elements in the specified collection to this queue. |
void |
clear() Removes all of the elements from this queue. |
Object |
element() Retrieves, but does not remove, the head of this queue. |
Object |
remove() Retrieves and removes the head of this queue. |
Methods inherited from class java.util.AbstractCollection |
---|
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected AbstractQueue()
Method Detail |
---|
public boolean add(Object e)
This implementation returns true if offer succeeds, else throws an IllegalStateException.
add
in class AbstractCollection
e
- the element to addpublic boolean addAll(Collection c)
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.
addAll
in class AbstractCollection
c
- collection containing elements to be added to this queuepublic void clear()
This implementation repeatedly invokes {@link #poll poll} until it returns null.
clear
in class AbstractCollection
public Object element()
This implementation returns the result of peek unless the queue is empty.
public Object remove()
This implementation returns the result of poll unless the queue is empty.
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |