java.util
Class AbstractQueue<E>

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.AbstractCollection sample code for java.util.AbstractCollection definition code for java.util.AbstractCollection <E>
      extended by java.util.AbstractQueue<E>
Type Parameters:
E - the type of elements held in this collection
All Implemented Interfaces:
Iterable sample code for java.lang.Iterable definition code for java.lang.Iterable <E>, Collection sample code for java.util.Collection definition code for java.util.Collection <E>, Queue sample code for java.util.Queue definition code for java.util.Queue <E>
Direct Known Subclasses:
ArrayBlockingQueue sample code for java.util.concurrent.ArrayBlockingQueue definition code for java.util.concurrent.ArrayBlockingQueue , ConcurrentLinkedQueue sample code for java.util.concurrent.ConcurrentLinkedQueue definition code for java.util.concurrent.ConcurrentLinkedQueue , DelayQueue sample code for java.util.concurrent.DelayQueue definition code for java.util.concurrent.DelayQueue , LinkedBlockingQueue sample code for java.util.concurrent.LinkedBlockingQueue definition code for java.util.concurrent.LinkedBlockingQueue , PriorityBlockingQueue sample code for java.util.concurrent.PriorityBlockingQueue definition code for java.util.concurrent.PriorityBlockingQueue , PriorityQueue sample code for java.util.PriorityQueue definition code for java.util.PriorityQueue , SynchronousQueue sample code for java.util.concurrent.SynchronousQueue definition code for java.util.concurrent.SynchronousQueue

public abstract class AbstractQueue<E>
extends AbstractCollection sample code for java.util.AbstractCollection definition code for java.util.AbstractCollection <E>
implements Queue sample code for java.util.Queue definition code for java.util.Queue <E>

This class provides skeletal implementations of some Queue sample code for java.util.Queue definition code for java.util.Queue operations. The implementations in this class are appropriate when the base implementation does not allow null elements. Methods add sample code for java.util.AbstractQueue.add(E) definition code for java.util.AbstractQueue.add(E) , remove sample code for java.util.AbstractQueue.remove() definition code for java.util.AbstractQueue.remove() , and element sample code for java.util.AbstractQueue.element() definition code for java.util.AbstractQueue.element() are based on offer sample code for java.util.Queue.offer(E) definition code for java.util.Queue.offer(E) , poll sample code for java.util.Queue.poll() definition code for java.util.Queue.poll() , and peek sample code for java.util.Queue.peek() definition code for java.util.Queue.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 Queue.offer(E) sample code for java.util.Queue.offer(E) definition code for java.util.Queue.offer(E) which does not permit insertion of null elements, along with methods Queue.peek() sample code for java.util.Queue.peek() definition code for java.util.Queue.peek() , Queue.poll() sample code for java.util.Queue.poll() definition code for java.util.Queue.poll() , Collection.size() sample code for java.util.Collection.size() definition code for java.util.Collection.size() , and a Collection.iterator() sample code for java.util.Collection.iterator() definition code for java.util.Collection.iterator() supporting Iterator.remove() sample code for java.util.Iterator.remove() definition code for java.util.Iterator.remove() . Typically, additional methods will be overridden as well. If these requirements cannot be met, consider instead subclassing AbstractCollection sample code for java.util.AbstractCollection definition code for java.util.AbstractCollection .

This class is a member of the Java Collections Framework.

Since:
1.5

Constructor Summary
protected AbstractQueue sample code for java.util.AbstractQueue.AbstractQueue() definition code for java.util.AbstractQueue.AbstractQueue() ()
          Constructor for use by subclasses.
 
Method Summary
 boolean add sample code for java.util.AbstractQueue.add(E) definition code for java.util.AbstractQueue.add(E) (E o)
          Adds the specified element to this queue.
 boolean addAll sample code for java.util.AbstractQueue.addAll(java.util.Collection) definition code for java.util.AbstractQueue.addAll(java.util.Collection) (Collection sample code for java.util.Collection definition code for java.util.Collection <? extends E> c)
          Adds all of the elements in the specified collection to this queue.
 void clear sample code for java.util.AbstractQueue.clear() definition code for java.util.AbstractQueue.clear() ()
          Removes all of the elements from this collection.
 E element sample code for java.util.AbstractQueue.element() definition code for java.util.AbstractQueue.element() ()
          Retrieves, but does not remove, the head of this queue.
 E remove sample code for java.util.AbstractQueue.remove() definition code for java.util.AbstractQueue.remove() ()
          Retrieves and removes the head of this queue.
 
Methods inherited from class java.util.AbstractCollection sample code for java.util.AbstractCollection definition code for java.util.AbstractCollection
contains sample code for java.util.AbstractCollection.contains(java.lang.Object) definition code for java.util.AbstractCollection.contains(java.lang.Object) , containsAll sample code for java.util.AbstractCollection.containsAll(java.util.Collection) definition code for java.util.AbstractCollection.containsAll(java.util.Collection) , isEmpty sample code for java.util.AbstractCollection.isEmpty() definition code for java.util.AbstractCollection.isEmpty() , iterator sample code for java.util.AbstractCollection.iterator() definition code for java.util.AbstractCollection.iterator() , remove sample code for java.util.AbstractCollection.remove(java.lang.Object) definition code for java.util.AbstractCollection.remove(java.lang.Object) , removeAll sample code for java.util.AbstractCollection.removeAll(java.util.Collection) definition code for java.util.AbstractCollection.removeAll(java.util.Collection) , retainAll sample code for java.util.AbstractCollection.retainAll(java.util.Collection) definition code for java.util.AbstractCollection.retainAll(java.util.Collection) , size sample code for java.util.AbstractCollection.size() definition code for java.util.AbstractCollection.size() , toArray sample code for java.util.AbstractCollection.toArray() definition code for java.util.AbstractCollection.toArray() , toArray sample code for java.util.AbstractCollection.toArray(T[]) definition code for java.util.AbstractCollection.toArray(T[]) , toString sample code for java.util.AbstractCollection.toString() definition code for java.util.AbstractCollection.toString()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 
Methods inherited from interface java.util.Queue sample code for java.util.Queue definition code for java.util.Queue
offer sample code for java.util.Queue.offer(E) definition code for java.util.Queue.offer(E) , peek sample code for java.util.Queue.peek() definition code for java.util.Queue.peek() , poll sample code for java.util.Queue.poll() definition code for java.util.Queue.poll()
 
Methods inherited from interface java.util.Collection sample code for java.util.Collection definition code for java.util.Collection
contains sample code for java.util.Collection.contains(java.lang.Object) definition code for java.util.Collection.contains(java.lang.Object) , containsAll sample code for java.util.Collection.containsAll(java.util.Collection) definition code for java.util.Collection.containsAll(java.util.Collection) , equals sample code for java.util.Collection.equals(java.lang.Object) definition code for java.util.Collection.equals(java.lang.Object) , hashCode sample code for java.util.Collection.hashCode() definition code for java.util.Collection.hashCode() , isEmpty sample code for java.util.Collection.isEmpty() definition code for java.util.Collection.isEmpty() , iterator sample code for java.util.Collection.iterator() definition code for java.util.Collection.iterator() , remove sample code for java.util.Collection.remove(java.lang.Object) definition code for java.util.Collection.remove(java.lang.Object) , removeAll sample code for java.util.Collection.removeAll(java.util.Collection) definition code for java.util.Collection.removeAll(java.util.Collection) , retainAll sample code for java.util.Collection.retainAll(java.util.Collection) definition code for java.util.Collection.retainAll(java.util.Collection) , size sample code for java.util.Collection.size() definition code for java.util.Collection.size() , toArray sample code for java.util.Collection.toArray() definition code for java.util.Collection.toArray() , toArray sample code for java.util.Collection.toArray(T[]) definition code for java.util.Collection.toArray(T[])
 

Constructor Detail

AbstractQueue sample code for java.util.AbstractQueue() definition code for java.util.AbstractQueue()

protected AbstractQueue()
Constructor for use by subclasses.

Method Detail

add sample code for java.util.AbstractQueue.add(E) definition code for java.util.AbstractQueue.add(E)

public boolean add(E o)
Adds the specified element to this queue. This implementation returns true if offer succeeds, else throws an IllegalStateException.

Specified by:
add sample code for java.util.Collection.add(E) definition code for java.util.Collection.add(E) in interface Collection sample code for java.util.Collection definition code for java.util.Collection <E>
Overrides:
add sample code for java.util.AbstractCollection.add(E) definition code for java.util.AbstractCollection.add(E) in class AbstractCollection sample code for java.util.AbstractCollection definition code for java.util.AbstractCollection <E>
Parameters:
o - the element
Returns:
true (as per the general contract of Collection.add).
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if the specified element is null
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if element cannot be added

remove sample code for java.util.AbstractQueue.remove() definition code for java.util.AbstractQueue.remove()

public E remove()
Retrieves and removes the head of this queue. This implementation returns the result of poll unless the queue is empty.

Specified by:
remove sample code for java.util.Queue.remove() definition code for java.util.Queue.remove() in interface Queue sample code for java.util.Queue definition code for java.util.Queue <E>
Returns:
the head of this queue.
Throws:
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if this queue is empty.

element sample code for java.util.AbstractQueue.element() definition code for java.util.AbstractQueue.element()

public E element()
Retrieves, but does not remove, the head of this queue. This implementation returns the result of peek unless the queue is empty.

Specified by:
element sample code for java.util.Queue.element() definition code for java.util.Queue.element() in interface Queue sample code for java.util.Queue definition code for java.util.Queue <E>
Returns:
the head of this queue.
Throws:
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if this queue is empty.

clear sample code for java.util.AbstractQueue.clear() definition code for java.util.AbstractQueue.clear()

public void clear()
Removes all of the elements from this collection. The collection will be empty after this call returns.

This implementation repeatedly invokes poll sample code for java.util.Queue.poll() definition code for java.util.Queue.poll() until it returns null.

Specified by:
clear sample code for java.util.Collection.clear() definition code for java.util.Collection.clear() in interface Collection sample code for java.util.Collection definition code for java.util.Collection <E>
Overrides:
clear sample code for java.util.AbstractCollection.clear() definition code for java.util.AbstractCollection.clear() in class AbstractCollection sample code for java.util.AbstractCollection definition code for java.util.AbstractCollection <E>

addAll sample code for java.util.AbstractQueue.addAll(java.util.Collection<? extends E>) definition code for java.util.AbstractQueue.addAll(java.util.Collection<? extends E>)

public boolean addAll(Collection sample code for java.util.Collection definition code for java.util.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 collection, 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.

Specified by:
addAll sample code for java.util.Collection.addAll(java.util.Collection) definition code for java.util.Collection.addAll(java.util.Collection) in interface Collection sample code for java.util.Collection definition code for java.util.Collection <E>
Overrides:
addAll sample code for java.util.AbstractCollection.addAll(java.util.Collection) definition code for java.util.AbstractCollection.addAll(java.util.Collection) in class AbstractCollection sample code for java.util.AbstractCollection definition code for java.util.AbstractCollection <E>
Parameters:
c - collection whose elements are to be added to this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if the specified collection or any of its elements are null.
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if c is this queue.
See Also:
add(Object) sample code for java.util.AbstractQueue.add(E) definition code for java.util.AbstractQueue.add(E)