scranton.queue
Class QueueViaArrayCirc

java.lang.Object
  extended byscranton.queue.QueueViaArrayCirc
All Implemented Interfaces:
Queue

public class QueueViaArrayCirc
extends java.lang.Object
implements Queue

Implements the Queue interface via compositon using an array (wraparound).


Field Summary
protected  java.lang.Object[] actual
          The array that contains the objects in the queue.
protected  int front
          The index to the array location that contains the front.
protected  int qSize
          The actual size of the queue
 
Constructor Summary
  QueueViaArrayCirc()
          Constructs an empty queue
(package private) QueueViaArrayCirc(int size)
          Constructs an empty queue of the indicated size.
 
Method Summary
 java.lang.Object dequeue()
          Decrease the size of the queue by one by removing and returning reference to the object that was at the front of the queue.
private  java.lang.Object[] doubler(java.lang.Object[] oldArray)
          Method doubler doubles the sixe of the array containing the queue and copies the queue into the new array.
 void enqueue(java.lang.Object item)
          Increase the size of the queue by one by placing item as the rear of the queue.
 Queue factory()
           
 java.lang.Object frontOf()
          Queue does not change, returns the reference to the front object in the queue.
 boolean isEmpty()
          Queue does not change, returns true iff the queue is empty.
 java.lang.String toString()
          Returns a string representation of the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

actual

protected java.lang.Object[] actual
The array that contains the objects in the queue.


front

protected int front
The index to the array location that contains the front.


qSize

protected int qSize
The actual size of the queue

Constructor Detail

QueueViaArrayCirc

public QueueViaArrayCirc()
Constructs an empty queue


QueueViaArrayCirc

QueueViaArrayCirc(int size)
Constructs an empty queue of the indicated size.

Parameters:
size - Establishes the initial size of the array actual
Method Detail

isEmpty

public boolean isEmpty()
Description copied from interface: Queue
Queue does not change, returns true iff the queue is empty.

Specifications:
Q'=Q
Return Q==()

Specified by:
isEmpty in interface Queue
Returns:
boolean Q==().
See Also:
Queue.isEmpty()

frontOf

public java.lang.Object frontOf()
Description copied from interface: Queue
Queue does not change, returns the reference to the front object in the queue.

Specifications:
Q!=()
Q'=Q

Return a0

Specified by:
frontOf in interface Queue
Returns:
Object Front of Queue.
See Also:
Queue.frontOf()

enqueue

public void enqueue(java.lang.Object item)
Description copied from interface: Queue
Increase the size of the queue by one by placing item as the rear of the queue.

Specifications:
Q'=(Q, obj)

Specified by:
enqueue in interface Queue
Parameters:
item - The new rear of the queue
See Also:
Queue.enqueue(java.lang.Object)

dequeue

public java.lang.Object dequeue()
Description copied from interface: Queue
Decrease the size of the queue by one by removing and returning reference to the object that was at the front of the queue. Note: The queue cannot be empty.

Specifications:
Q!=()
Q = (a0, Q')
Return: a0

Specified by:
dequeue in interface Queue
Returns:
Object Front of queue.
See Also:
Queue.dequeue()

doubler

private java.lang.Object[] doubler(java.lang.Object[] oldArray)
Method doubler doubles the sixe of the array containing the queue and copies the queue into the new array.

Parameters:
oldArray - The (filled) array containing the stack's objects
Returns:
Object[] A new array that is double the size.

toString

public java.lang.String toString()
Description copied from interface: Queue
Returns a string representation of the queue. The format of the representation is "FRONT[Ofront\t...\tOrear]REAR"

Specified by:
toString in interface Queue

factory

public Queue factory()