Package com.ibm.wala.util.collections
Class FifoQueue<T>
- java.lang.Object
-
- com.ibm.wala.util.collections.FifoQueue<T>
-
- Direct Known Subclasses:
FifoQueueNoDuplicates
public class FifoQueue<T> extends 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
Constructors Constructor Description FifoQueue()
Creates a FIFO queue with no elements enqueued.FifoQueue(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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(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.
-
-
-
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(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:
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
ifelement
is in the queue. Otherwisefalse
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 implementequals()
, 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(Iterator<? extends T> elements) throws 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 implementequals()
, 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:
IllegalArgumentException
- if elements == null
-
pop
public T pop() throws IllegalStateException
Remove the next Object from the queue and return it to the caller. ThrowsIllegalStateException
if the queue is empty when this method is called.- Returns:
- the next Object in the queue.
- Throws:
IllegalStateException
-
peek
public T peek() throws IllegalStateException
Returns the next Object in the queue, but leaves it in the queue. ThrowsIllegalStateException
if the queue is empty when this method is called.- Returns:
- the next Object in the queue.
- Throws:
IllegalStateException
-
-