com.pushtotest.tool.util
Class Queue

java.lang.Object
  extended by com.pushtotest.tool.util.Queue

public class Queue
extends java.lang.Object

A Thread-safe Queue implementation. This is a (hopefully) Thread-safe FIFO Queue that is backed by a Vector. It should allow the standard functionality of a queue without requiring the user to worry about the details of thread safety. This should be a monitor, so if you try to pop() or peek() on an empty queue, then the thread will wait until the queue has an object to get.


Field Summary
protected  java.util.List container
           
 
Constructor Summary
Queue()
          Creates a new Queue with the default capacity.
Queue(java.util.Collection collection)
          Creates a new queue with the initial queue elements set to the objects in the collection passed in.
Queue(int capacity)
          Creates a new Queue with the initial capacity passed in.
 
Method Summary
 int contains(java.lang.Object inObject)
          Call this method to find out where a specific object is in the Queue.
 void flush()
          Removes all of the Queued objects so that the size will be 0.
 boolean isEmpty()
          Tests whether or not this Queue has any Objects in it or not.
 java.lang.Object peek()
          Return the next Object in the Queue, but don't remove it.
 java.lang.Object pop()
          Return the next item in the Queue and remove it from the Queue.
 void push(java.lang.Object inObject)
          Put this new Object in the Queue.
 int size()
          Tells how Objects are in the Queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

container

protected java.util.List container
Constructor Detail

Queue

public Queue()
Creates a new Queue with the default capacity.


Queue

public Queue(int capacity)
      throws java.lang.IllegalArgumentException
Creates a new Queue with the initial capacity passed in.

Parameters:
capacity - The initial capacity for the Queu.
Throws:
java.lang.IllegalArgumentException - If the capacity is a negative number.

Queue

public Queue(java.util.Collection collection)
Creates a new queue with the initial queue elements set to the objects in the collection passed in. They will be ordered in the order of the collection's itterator.

Parameters:
collection - The collection to start this queue with.
Throws:
java.lang.NullPointerException - DOCUMENT ME!
Method Detail

pop

public java.lang.Object pop()
Return the next item in the Queue and remove it from the Queue.

Returns:
The Object that is next in line

peek

public java.lang.Object peek()
Return the next Object in the Queue, but don't remove it.

Returns:
The Object that is next in line.

push

public void push(java.lang.Object inObject)
Put this new Object in the Queue. It will be at the end of the Queue. If the Object is null, it will be thrown away.

Parameters:
inObject - The Object to put into the Queue
Throws:
java.lang.NullPointerException - DOCUMENT ME!

size

public int size()
Tells how Objects are in the Queue.

Returns:
The size of the Queue.

isEmpty

public boolean isEmpty()
Tests whether or not this Queue has any Objects in it or not.

Returns:
Is this Queue empty or not?

contains

public int contains(java.lang.Object inObject)
Call this method to find out where a specific object is in the Queue. Method returns -1 if the Object is not in the Queue. Throws a NullPonterException if the object passed in is null.

Parameters:
inObject - The Object that you want to find in the Queue.
Returns:
The base 0 position of the Object in the Queue or -1 if it's not found.

flush

public void flush()
Removes all of the Queued objects so that the size will be 0.