org.elkoserver.foundation.run
Class Queue

java.lang.Object
  extended by org.elkoserver.foundation.run.Queue
All Implemented Interfaces:
Enumeration

public class Queue
extends Object
implements Enumeration

A conventional fifo queue in which dequeued items are removed in the same order they were enqueued. An untyped queue can hold any object (except null). A queue can be created with a dynamic type, in which case, at no extra overhead, enqueue will only enqueue objects of that type (or a subtype, but not null). This check imposes no extra overhead, since Java always makes us pay for a dynamic type check on array store anyway. Queue is a thread-safe data structure, providing its own lock, and a blocking dequeue() operation.


Constructor Summary
Queue()
          Makes a Queue that can hold any object.
Queue(Class elementType)
          Makes a Queue that can hold objects of the specified elementType.
 
Method Summary
 Object dequeue()
          Get the least-recently-added element off of the queue.
 void enqueue(Object newElement)
          Add a new element to the queue.
 boolean hasMoreElements()
          Check to see if the queue has more elements.
 Object nextElement()
          Get the least-recently-added element off of the queue.
 Object optDequeue()
          Get the least-recently-added element off of the queue, or null if the queue is currently empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Queue

public Queue()
Makes a Queue that can hold any object.


Queue

public Queue(Class elementType)
Makes a Queue that can hold objects of the specified elementType.

Parameters:
elementType - may not be a primitive (ie, scalar) type.
Method Detail

dequeue

public Object dequeue()
Get the least-recently-added element off of the queue. If the queue is currently empty, block until there is an element that can be dequeued.


enqueue

public void enqueue(Object newElement)
Add a new element to the queue.

Parameters:
newElement - the object to be added to the end of the queue.
Throws:
NullPointerException - thrown if newElement is null
ArrayStoreException - thrown if newElement does not conform to the elementType specified in the Queue constructor.

hasMoreElements

public boolean hasMoreElements()
Check to see if the queue has more elements. This method allows a Queue to be used as an Enumeration.

Specified by:
hasMoreElements in interface Enumeration
Returns:
is false if the queue is empty, otherwise true

nextElement

public Object nextElement()
                   throws NoSuchElementException
Get the least-recently-added element off of the queue. If the queue is currently empty, throw NoSuchElementException. This method allows a Queue to be used as an Enumeration.

Specified by:
nextElement in interface Enumeration
Throws:
NoSuchElementException

optDequeue

public Object optDequeue()
Get the least-recently-added element off of the queue, or null if the queue is currently empty.