mako5.util
Class ArrayQueue<T>

java.lang.Object
  extended by mako5.util.ArrayQueue<T>
All Implemented Interfaces:
Queue<T>

public class ArrayQueue<T>
extends Object
implements Queue<T>

A circular array queue class.

Version:
04-Apr 2006
Author:
Paul Jarrett
See Also:
Queue

Constructor Summary
ArrayQueue()
          Makes an empty circular queue of size 0.
ArrayQueue(int initialCapacity)
          Creates an empty queue using the specified capacity.
 
Method Summary
 void clear()
          Clears all elements from this queue.
 T dequeue()
          Removes the element at the front of this queue and returns a reference to it.
 void enqueue(T val)
          Adds an item to the queue.
 T first()
          Peeks at the first element in this queue.
 boolean isEmpty()
          Returns true when the queue is empty.
 boolean isFull()
          Returns true if this queue is full.
 int size()
          Returns the current number of elements in the queue.
 String toString()
          Returns this as a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArrayQueue

public ArrayQueue()
Makes an empty circular queue of size 0.


ArrayQueue

public ArrayQueue(int initialCapacity)
Creates an empty queue using the specified capacity.

Parameters:
initialCapacity - indicates the initial size of the internal array.
Method Detail

enqueue

public void enqueue(T val)
Adds an item to the queue.

Specified by:
enqueue in interface Queue<T>
Parameters:
val - the thing to add

dequeue

public T dequeue()
Removes the element at the front of this queue and returns a reference to it.

Specified by:
dequeue in interface Queue<T>
Returns:
the element removed from the front of the queue

first

public T first()
Peeks at the first element in this queue.

Returns:
the first element in this queue without dequeueing it

isEmpty

public boolean isEmpty()
Returns true when the queue is empty.

Specified by:
isEmpty in interface Queue<T>
Returns:
true when the queue is empty

size

public int size()
Returns the current number of elements in the queue.

Specified by:
size in interface Queue<T>
Returns:
how many elements are currently in the queue

isFull

public boolean isFull()
Returns true if this queue is full.

Returns:
true if this queue is full

clear

public void clear()
Clears all elements from this queue.

Specified by:
clear in interface Queue<T>
Since:
05-Apr 2006

toString

public String toString()
Returns this as a string.

Overrides:
toString in class Object
Returns:
the string version of this