com.ibm.wala.util.collections
Class FifoQueue<T>

java.lang.Object
  extended by com.ibm.wala.util.collections.FifoQueue<T>
Direct Known Subclasses:
FifoQueueNoDuplicates

public class FifoQueue<T>
extends java.lang.Object

FIFO work queue management of Objects that prevents an object from being added to the queue if it is already enqueued and has not yet been popped.


Constructor Summary
FifoQueue()
          Creates a FIFO queue with no elements enqueued.
FifoQueue(java.util.Collection<T> collection)
          Creates a new FIFO queue containing the elements of the specified Collection.
FifoQueue(T element)
          Creates a new FIFO queue containing the argument to this constructor.
 
Method Summary
 boolean contains(T element)
          Indicate whether the specified element is currently in the queue.
 boolean isEmpty()
          Returns whether or not this queue is empty (no enqueued elements).
 T peek()
          Returns the next Object in the queue, but leaves it in the queue.
 T pop()
          Remove the next Object from the queue and return it to the caller.
 void push(java.util.Iterator<? extends T> elements)
          Insert all of the elements in the specified Iterator at the tail end of the queue if not already present in the queue.
 void push(T element)
          Insert an Object at the tail end of the queue if it is not already in the queue.
 int size()
          Return the current number of enqueued Objects, the number of Objects that were pushed into the queue and have not been popped.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FifoQueue

public FifoQueue()
Creates a FIFO queue with no elements enqueued.


FifoQueue

public FifoQueue(T element)
Creates a new FIFO queue containing the argument to this constructor.

Parameters:
element - is the element to add to the queue.

FifoQueue

public FifoQueue(java.util.Collection<T> collection)
Creates a new FIFO queue containing the elements of the specified Collection. The order the elements are inserted into the queue is unspecified.

Parameters:
collection - is the Collection of Object instances to be enqueue.
Throws:
java.lang.IllegalArgumentException - if collection is null
Method Detail

size

public int size()
Return the current number of enqueued Objects, the number of Objects that were pushed into the queue and have not been popped.

Returns:
the current queue size.
See Also:
isEmpty()

isEmpty

public boolean isEmpty()
Returns whether or not this queue is empty (no enqueued elements).

Returns:
true when there are no enqueued objects. false if there are objects remaining in the queue.
See Also:
size()

contains

public boolean contains(T element)
Indicate whether the specified element is currently in the queue.

Parameters:
element - determine whether this object is in the queue.
Returns:
true if element is in the queue. Otherwise false if not currently in the queue.

push

public void push(T element)
Insert an Object at the tail end of the queue if it is not already in the queue. If the Object is already in the queue, the queue remains unmodified.

This method determines whether an element is already in the queue using the element's equals() method. If the element's class does not implement equals(), the default implementation assumes they are equal only if it is the same object.

Parameters:
element - is the Object to be added to the queue if not already present in the queue.

push

public void push(java.util.Iterator<? extends T> elements)
          throws java.lang.IllegalArgumentException
Insert all of the elements in the specified Iterator at the tail end of the queue if not already present in the queue. Any element in the Iterator already in the queue is ignored.

This method determines whether an element is already in the queue using the element's equals() method. If the element's class does not implement equals(), the default implementation assumes they are equal if it is the same object.

Parameters:
elements - an Iterator of Objects to be added to the queue if not already queued.
Throws:
java.lang.IllegalArgumentException - if elements == null

pop

public T pop()
      throws java.lang.IllegalStateException
Remove the next Object from the queue and return it to the caller. Throws IllegalStateException if the queue is empty when this method is called.

Returns:
the next Object in the queue.
Throws:
java.lang.IllegalStateException

peek

public T peek()
       throws java.lang.IllegalStateException
Returns the next Object in the queue, but leaves it in the queue. Throws IllegalStateException if the queue is empty when this method is called.

Returns:
the next Object in the queue.
Throws:
java.lang.IllegalStateException