salvo.jesus.util
Class Queue

java.lang.Object
  extended by salvo.jesus.util.Queue
All Implemented Interfaces:
java.io.Serializable

public class Queue
extends java.lang.Object
implements java.io.Serializable

A Queue represents a first-in-first-out (FIFO) data structure. Unlike java.lang.Stack that simply extends java.util.Vector, this class does not extend java.util.Vector but delegates its methods to a java.util.Vector. Therefore, unlike java.util.Stack, the methods from java.util.Vector are not available.

Author:
Jesus M. Salvo Jr.
See Also:
Serialized Form

Field Summary
(package private)  java.util.Vector delegate
           
 
Constructor Summary
Queue()
          Creates an empty queue
 
Method Summary
 java.lang.Object get()
          Gets and removes the item at the beginning of the queue
 boolean isEmpty()
          Tests if the queue is empty
 boolean isQueued(java.lang.Object item)
          Tests if the item is in the queue.
 void put(java.lang.Object item)
          Puts an item at the end of the queue.
 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

delegate

java.util.Vector delegate
Constructor Detail

Queue

public Queue()
Creates an empty queue

Method Detail

put

public void put(java.lang.Object item)
Puts an item at the end of the queue. Note that this will not check of duplicate items in the queue.

Parameters:
item - The item to be added at the end of the queue

get

public java.lang.Object get()
                     throws EmptyQueueException
Gets and removes the item at the beginning of the queue

Returns:
The item at the beginning of the queue.
Throws:
EmptyQueueException

isEmpty

public boolean isEmpty()
Tests if the queue is empty

Returns:
True if the queue is empty, false otherwise.

isQueued

public boolean isQueued(java.lang.Object item)
Tests if the item is in the queue. Because the Queue allows duplicate items, isQueued() will return true even if the item was removed from the queue if the item was queued twice before being removed from the queue.

Returns:
True if the item is in the queue, false otherwise.

toString

public java.lang.String toString()
Returns a String representation of the queue. This simply calls the toString() method of the Vector class.

Overrides:
toString in class java.lang.Object