Known Direct Subclasses
|
Class Overview
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 offer(E)
which does not permit
insertion of null elements, along with methods peek()
, poll()
, size()
, and
iterator()
. Typically, additional methods will be
overridden as well. If these requirements cannot be met, consider
instead subclassing AbstractCollection
.
Summary
Protected Constructors |
|
AbstractQueue()
Constructor for use by subclasses.
|
Public Methods |
boolean
|
add(E e)
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<? extends E> c)
Adds all of the elements in the specified collection to this
queue.
|
void
|
clear()
Removes all of the elements from this queue.
|
E
|
element()
Retrieves, but does not remove, the head of this queue.
|
E
|
remove()
Retrieves and removes the head of this queue.
|
[Expand]
Inherited Methods |
From class
java.util.AbstractCollection
boolean
|
add(E object)
Attempts to add object to the contents of this
Collection (optional).
|
boolean
|
addAll(Collection<? extends E> collection)
Attempts to add all of the objects contained in collection
to the contents of this Collection (optional).
|
void
|
clear()
Removes all elements from this Collection , leaving it empty (optional).
|
boolean
|
contains(Object object)
Tests whether this Collection contains the specified object.
|
boolean
|
containsAll(Collection<?> collection)
Tests whether this Collection contains all objects contained in the
specified Collection .
|
boolean
|
isEmpty()
Returns if this Collection contains no elements.
|
abstract
Iterator<E>
|
iterator()
Returns an instance of Iterator that may be used to access the
objects contained by this Collection .
|
boolean
|
remove(Object object)
Removes one instance of the specified object from this Collection if one
is contained (optional).
|
boolean
|
removeAll(Collection<?> collection)
Removes all occurrences in this Collection of each object in the
specified Collection (optional).
|
boolean
|
retainAll(Collection<?> collection)
Removes all objects from this Collection that are not also found in the
Collection passed (optional).
|
abstract
int
|
size()
Returns a count of how many objects this Collection contains.
|
<T>
T[]
|
toArray(T[] contents)
Returns an array containing all elements contained in this Collection .
|
Object[]
|
toArray()
Returns a new array containing all elements contained in this Collection .
|
String
|
toString()
Returns the string representation of this Collection .
|
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
final
void
|
wait(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
|
From interface
java.lang.Iterable
|
From interface
java.util.Collection
abstract
boolean
|
add(E object)
Attempts to add object to the contents of this
Collection (optional).
|
abstract
boolean
|
addAll(Collection<? extends E> collection)
Attempts to add all of the objects contained in Collection
to the contents of this Collection (optional).
|
abstract
void
|
clear()
Removes all elements from this Collection , leaving it empty (optional).
|
abstract
boolean
|
contains(Object object)
Tests whether this Collection contains the specified object.
|
abstract
boolean
|
containsAll(Collection<?> collection)
Tests whether this Collection contains all objects contained in the
specified Collection .
|
abstract
boolean
|
equals(Object object)
Compares the argument to the receiver, and returns true if they represent
the same object using a class specific comparison.
|
abstract
int
|
hashCode()
Returns an integer hash code for the receiver.
|
abstract
boolean
|
isEmpty()
Returns if this Collection contains no elements.
|
abstract
Iterator<E>
|
iterator()
Returns an instance of Iterator that may be used to access the
objects contained by this Collection .
|
abstract
boolean
|
remove(Object object)
Removes one instance of the specified object from this Collection if one
is contained (optional).
|
abstract
boolean
|
removeAll(Collection<?> collection)
Removes all occurrences in this Collection of each object in the
specified Collection (optional).
|
abstract
boolean
|
retainAll(Collection<?> collection)
Removes all objects from this Collection that are not also found in the
Collection passed (optional).
|
abstract
int
|
size()
Returns a count of how many objects this Collection contains.
|
abstract
<T>
T[]
|
toArray(T[] array)
Returns an array containing all elements contained in this Collection .
|
abstract
Object[]
|
toArray()
Returns a new array containing all elements contained in this Collection .
|
|
From interface
java.util.Queue
abstract
boolean
|
add(E e)
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.
|
abstract
E
|
element()
Retrieves, but does not remove, the head of this queue.
|
abstract
boolean
|
offer(E e)
Inserts the specified element into this queue if it is possible to do
so immediately without violating capacity restrictions.
|
abstract
E
|
peek()
Retrieves, but does not remove, the head of this queue,
or returns null if this queue is empty.
|
abstract
E
|
poll()
Retrieves and removes the head of this queue,
or returns null if this queue is empty.
|
abstract
E
|
remove()
Retrieves and removes the head of this queue.
|
|
Protected Constructors
protected
AbstractQueue
()
Constructor for use by subclasses.
Public Methods
public
boolean
add
(E e)
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.
This implementation returns true if offer succeeds,
else throws an IllegalStateException.
public
boolean
addAll
(Collection<? extends E> c)
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.
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.
Parameters
c
| collection containing elements to be added to this queue |
Returns
- true if this queue changed as a result of the call
Throws
ClassCastException
| if the class of an element of the specified
collection prevents it from being added to this queue |
NullPointerException
| if the specified collection contains a
null element and this queue does not permit null elements,
or if the specified collection is null |
IllegalArgumentException
| if some property of an element of the
specified collection prevents it from being added to this
queue, or if the specified collection is this queue |
IllegalStateException
| if not all the elements can be added at
this time due to insertion restrictions |
public
void
clear
()
Removes all of the elements from this queue.
The queue will be empty after this call returns.
This implementation repeatedly invokes poll
until it
returns null.
public
E
element
()
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.
This implementation returns the result of peek
unless the queue is empty.
public
E
remove
()
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.
This implementation returns the result of poll
unless the queue is empty.