org.erights.e.elib.vat
Class Queue

java.lang.Object
  |
  +--org.erights.e.elib.vat.Queue
All Implemented Interfaces:
Enumeration
Direct Known Subclasses:
SynchQueue

public class Queue
extends Object
implements Enumeration

Safe: 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.

The class Queue itself is no longer thread safe, instead being optimized for using inside one vat. See the subclass SynchQueue for a thread-safe variant with a blocking operation.

Author:
Mark S. Miller
See Also:
org.erights.e.elib.vat.Vat

Field Summary
private static int INITIAL_SIZE
           
private  int myCurSize
           
private  int myIn
           
private  int myMaxSize
           
private  int myOut
           
private  Object[] myStuff
           
 
Constructor Summary
Queue()
          Enabled: Makes a Queue that can hold any object.
Queue(Class elementType)
          Enabled: Makes a Queue that can hold objects of the specified elementType.
 
Method Summary
 void enqueue(Object newElement)
          Enabled: Add a new element to the queue.
 boolean hasMoreElements()
          Enabled: Check to see if the queue has more elements.
 Object nextElement()
          Enabled: Get the least-recently-added element off of the queue.
 Object optDequeue()
          Enabled: 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
 
Methods inherited from interface java.util.Enumeration
asList, iterate
 

Field Detail

INITIAL_SIZE

private static final int INITIAL_SIZE

myStuff

private Object[] myStuff

myMaxSize

private int myMaxSize

myCurSize

private int myCurSize

myOut

private int myOut

myIn

private int myIn
Constructor Detail

Queue

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


Queue

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

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

enqueue

public void enqueue(Object newElement)
Enabled: 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 coerce to the elementType specified in the Queue constructor.

hasMoreElements

public boolean hasMoreElements()
Enabled: 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
Enabled: 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
Returns:
the next element of this enumeration.
NoSuchElementException

optDequeue

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



comments?