m865.datastructures
Class QueueAL

java.lang.Object
  extended bym865.datastructures.AbstractQueue
      extended bym865.datastructures.QueueAL
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection

public class QueueAL
extends AbstractQueue

This class implements a Queue using a dynamic array

Version:
2.0 09/16/04
Author:
Daniel D. Warner

Nested Class Summary
 class QueueAL.QueueALIterator
          An iterator for this queue.
 
Field Summary
protected  java.util.ArrayList v
          The dynamic array is implemented with the java.util.ArrayList
 
Fields inherited from class m865.datastructures.AbstractQueue
hash
 
Constructor Summary
  QueueAL()
          Constructs a queue whose dynamic array has the default initial size for a ArrayList.
  QueueAL(java.util.Collection c)
          Constructs a queue which is initialized with the objects in the specified collection
  QueueAL(int capacity)
          Constructs a queue whose dynamic array has a specified initial size.
protected QueueAL(int hash, java.util.ArrayList v)
          Constructs a queue with a specified hash code and a clone of the specified ArrayList.
 
Method Summary
 void clear()
          Removes all the objects from this queue.
 java.lang.Object clone()
          The Cloneable Interface indicates that the clone method, which is inherited from Object, is implemented so that a true clone (a true and independent copy) of the object is returned.
 java.lang.Object dequeue()
          Removes and returns the object at the beginning of the queue.
 void enqueue(java.lang.Object obj)
          Appends an object to the end of the queue.
 java.util.Iterator iterator()
          A factory method which returns an Iterator to the collection in this queue.
static void main(java.lang.String[] args)
          This main method tests the QueueAL class to insure that the elementary functions are correct.
 java.lang.Object peek()
          Returns the object at the beginning of the queue.
 int size()
          Determines the size of this queue.
 java.lang.String toString()
          List the objects in the queue
 
Methods inherited from class m865.datastructures.AbstractQueue
add, addAll, contains, containsAll, downdateHashCode, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray, updateHashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

v

protected java.util.ArrayList v
The dynamic array is implemented with the java.util.ArrayList

Constructor Detail

QueueAL

public QueueAL(int capacity)
Constructs a queue whose dynamic array has a specified initial size. Whenever the dynamic array is increased, it's size will determined by the default ArrayList strategy, which traditionally doubles the size.

Parameters:
capacity - the initial size of the dynamic array.

QueueAL

public QueueAL()
Constructs a queue whose dynamic array has the default initial size for a ArrayList.


QueueAL

public QueueAL(java.util.Collection c)
Constructs a queue which is initialized with the objects in the specified collection

Parameters:
c - the collection of objects to be initially enqueued onto this queue.

QueueAL

protected QueueAL(int hash,
                  java.util.ArrayList v)
Constructs a queue with a specified hash code and a clone of the specified ArrayList. This constuctor is only for use within the class and its subclasses.

Parameters:
hash - the hash code
v - the ArrayList to be cloned.
Method Detail

enqueue

public void enqueue(java.lang.Object obj)
Appends an object to the end of the queue.

Specified by:
enqueue in class AbstractQueue
Parameters:
obj - the object to be appended to the end of the queue.

dequeue

public java.lang.Object dequeue()
Removes and returns the object at the beginning of the queue.

Specified by:
dequeue in class AbstractQueue
Returns:
the object at the beginning of the queue or null if the queue is empty.

peek

public java.lang.Object peek()
Returns the object at the beginning of the queue. The queue remains unchanged.

Specified by:
peek in class AbstractQueue
Returns:
the object at the beginning of the queue or null if the queue is empty.

clear

public void clear()
Removes all the objects from this queue. This is one of the optional operations specified by the Collection Interface


clone

public java.lang.Object clone()
The Cloneable Interface indicates that the clone method, which is inherited from Object, is implemented so that a true clone (a true and independent copy) of the object is returned.

Returns:
a clone (a true and independent copy) of this queue.

iterator

public java.util.Iterator iterator()
A factory method which returns an Iterator to the collection in this queue. This iterator will walk throught the queue from the top to the bottom. It will throw a ConcurrentModificationException if the queue is altered during the iteration.

Returns:
a QueueALIterator which will iterate through this queue from the front to back.

size

public int size()
Determines the size of this queue.

Returns:
the number of objects in this queue.

toString

public java.lang.String toString()
List the objects in the queue

Overrides:
toString in class AbstractQueue
Returns:
a formatted string listing the objects in this queue

main

public static void main(java.lang.String[] args)
This main method tests the QueueAL class to insure that the elementary functions are correct.

Parameters:
args - optional command line argument that will be ignored.