queue
Class MyQueue<E>

java.lang.Object
  extended by queue.MyQueue<E>
All Implemented Interfaces:
Iterable<E>, Queue<E>

public class MyQueue<E>
extends Object
implements Queue<E>

The MyQueue class is an growable, circular, array-based implementation of the Queue interface.


Constructor Summary
MyQueue()
          Set up and initialize the Queue.
 
Method Summary
 E dequeue()
          Removes and returns the object at the front of the queue.
 void enqueue(E e)
          Inserts an element at the rear of the queue.
 E front()
          Returns, but does not remove, the object at the front of the queue.
 MyQueueDataObject<E> getData()
           
 boolean isEmpty()
          Checks to see if the queue is empty.
 Iterator<E> iterator()
          Returns an iterator over the contents of the queue.
 int size()
          Finds out how many elements are currently stored in the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MyQueue

public MyQueue()
Set up and initialize the Queue. Remember: the default initial size should be eight (8).

Method Detail

size

public int size()
Finds out how many elements are currently stored in the queue.

Specified by:
size in interface Queue<E>
Returns:
the number of elements in the Queue

isEmpty

public boolean isEmpty()
Checks to see if the queue is empty.

Specified by:
isEmpty in interface Queue<E>
Returns:
boolean true if the queue is empty; false otherwise

enqueue

public void enqueue(E e)
Inserts an element at the rear of the queue.

Specified by:
enqueue in interface Queue<E>
Parameters:
e - the element to be added

dequeue

public E dequeue()
          throws EmptyQueueException
Removes and returns the object at the front of the queue.

Specified by:
dequeue in interface Queue<E>
Returns:
the element at the front of the queue
Throws:
EmptyQueueException - if the queue is empty

front

public E front()
        throws EmptyQueueException
Returns, but does not remove, the object at the front of the queue.

Specified by:
front in interface Queue<E>
Returns:
the element at the front of the queue
Throws:
EmptyQueueException - if the queue is empty

getData

public MyQueueDataObject<E> getData()
                             throws ArrayIndexOutOfBoundsException
Throws:
ArrayIndexOutOfBoundsException

iterator

public Iterator<E> iterator()
                     throws EmptyQueueException
Returns an iterator over the contents of the queue.

Specified by:
iterator in interface Iterable<E>
Returns:
ObjectIterator iterator over the contents of the queue
Throws:
EmptyQueueException - when there are no elements in queue