pivot.collections
Interface Queue<T>

All Superinterfaces:
Collection<T>, java.lang.Iterable<T>, List<T>, Sequence<T>
All Known Implementing Classes:
ArrayQueue, LinkedQueue, SynchronizedQueue

public interface Queue<T>
extends List<T>

Interface representing a first-in, first-out (FIFO) queue when unsorted, and a priority queue when sorted.

Author:
gbrown

Nested Class Summary
 
Nested classes/interfaces inherited from interface pivot.collections.List
List.ListListenerList<T>
 
Nested classes/interfaces inherited from interface pivot.collections.Sequence
Sequence.Search, Sequence.Sort, Sequence.Tree
 
Method Summary
 T dequeue()
          Removes the item from the head of the queue and returns it.
 void enqueue(T item)
          Enqueues an item.
 T peek()
          Returns the item at the head of the queue without removing it from the queue.
 
Methods inherited from interface pivot.collections.List
add, clear, getLength, getListListeners, insert, remove, setComparator, update
 
Methods inherited from interface pivot.collections.Sequence
get, indexOf, remove
 
Methods inherited from interface pivot.collections.Collection
getComparator
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

enqueue

void enqueue(T item)
Enqueues an item. If the queue is unsorted, the item is added at the tail of the queue (index 0). Otherwise, it is inserted at the appropriate index.

Parameters:
item - The item to add to the queue.

dequeue

T dequeue()
Removes the item from the head of the queue and returns it. Calling this method should have the same effect as: remove(getLength() - 1, 1);


peek

T peek()
Returns the item at the head of the queue without removing it from the queue. Returns null if the queue contains no items. Will also return null if the head item in the queue is null. getLength() can be used to distinguish between these two cases.