structure
Class QueueArray

java.lang.Object
  extended by structure.AbstractStructure
      extended by structure.AbstractLinear
          extended by structure.AbstractQueue
              extended by structure.QueueArray
All Implemented Interfaces:
Linear, Queue, Structure

public class QueueArray
extends AbstractQueue
implements Queue

An implementation of a queue based on arrays.


Field Summary
protected  int count
          current size of queue
protected  java.lang.Object[] data
          The references to values stored within the queue.
protected  int head
          index of the head of queue.
 
Constructor Summary
QueueArray(int size)
          Construct a queue holding at most size elements.
 
Method Summary
 void add(java.lang.Object value)
          Add a value to the tail of the queue.
 void clear()
          Remove all the values from the queue.
 java.lang.Object get()
          Fetch the value at the head of the queue.
 boolean isEmpty()
          Determine if the queue is empty.
 boolean isFull()
          Determines if the queue is not able to accept any new values.
 java.util.Iterator iterator()
          Returns an iterator for traversing the structure.
 java.lang.Object remove()
          Remove a value from the head of the queue.
 int size()
          Determine the number of elements within the queue
 java.lang.String toString()
          Construct a string representation of the queue.
 
Methods inherited from class structure.AbstractQueue
dequeue, enqueue, getFirst, peek
 
Methods inherited from class structure.AbstractLinear
empty, remove
 
Methods inherited from class structure.AbstractStructure
contains, elements, hashCode, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface structure.Queue
dequeue, empty, enqueue, getFirst, peek
 
Methods inherited from interface structure.Structure
contains, elements, remove, values
 

Field Detail

data

protected java.lang.Object[] data
The references to values stored within the queue.


head

protected int head
index of the head of queue.


count

protected int count
current size of queue

Constructor Detail

QueueArray

public QueueArray(int size)
Construct a queue holding at most size elements.

Parameters:
size - The maximum size of the queue.
Postcondition:
create a queue capable of holding at most size values
Method Detail

add

public void add(java.lang.Object value)
Add a value to the tail of the queue.

Specified by:
add in interface Linear
Specified by:
add in interface Queue
Specified by:
add in interface Structure
Parameters:
value - The value added.
See Also:
AbstractQueue.enqueue(java.lang.Object)
Precondition:
the queue is not full
Postcondition:
the value is added to the tail of the structure

remove

public java.lang.Object remove()
Remove a value from the head of the queue.

Specified by:
remove in interface Linear
Specified by:
remove in interface Queue
Returns:
The value actually removed.
See Also:
AbstractQueue.dequeue()
Precondition:
the queue is not empty
Postcondition:
the head of the queue is removed and returned

get

public java.lang.Object get()
Fetch the value at the head of the queue.

Specified by:
get in interface Linear
Specified by:
get in interface Queue
Returns:
Reference to the first value of the queue.
Precondition:
the queue is not empty
Postcondition:
the element at the head of the queue is returned

size

public int size()
Determine the number of elements within the queue

Specified by:
size in interface Linear
Specified by:
size in interface Queue
Specified by:
size in interface Structure
Returns:
The number of elements within the queue.
Postcondition:
returns the number of elements in the queue

clear

public void clear()
Remove all the values from the queue.

Specified by:
clear in interface Structure
Postcondition:
removes all elements from the queue

isFull

public boolean isFull()
Determines if the queue is not able to accept any new values.

Returns:
True iff the queue is full.
Postcondition:
returns true if the queue is at its capacity

isEmpty

public boolean isEmpty()
Determine if the queue is empty.

Specified by:
isEmpty in interface Structure
Overrides:
isEmpty in class AbstractStructure
Returns:
True iff the queue is empty.
Postcondition:
returns true iff the queue is empty

iterator

public java.util.Iterator iterator()
Description copied from interface: Structure
Returns an iterator for traversing the structure.

Specified by:
iterator in interface Structure
Returns:
an iterator for traversing the structure
See Also:
AbstractIterator, Iterator, Enumeration, Structure.elements()

toString

public java.lang.String toString()
Construct a string representation of the queue.

Overrides:
toString in class java.lang.Object
Returns:
String representing the queue.
Postcondition:
returns string representation of queue