org.apache.pivot.collections
Interface Queue<T>

All Superinterfaces:
Collection<T>, Iterable<T>
All Known Implementing Classes:
ArrayQueue, LinkedQueue, SynchronizedQueue

public interface Queue<T>
extends Collection<T>

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


Nested Class Summary
static class Queue.QueueListenerList<T>
          Queue listener list.
 
Method Summary
 T dequeue()
          Removes the item from the head of the queue and returns it.
 void enqueue(T item)
          Enqueues an item.
 int getLength()
          Returns the length of the queue.
 ListenerList<QueueListener<T>> getQueueListeners()
          Returns the queue listener list.
 boolean isEmpty()
          Tests the emptiness of the queue.
 T peek()
          Returns the item at the head of the queue without removing it from the queue.
 
Methods inherited from interface org.apache.pivot.collections.Collection
clear, getComparator, setComparator
 
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. isEmpty() can be used to distinguish between these two cases.


isEmpty

boolean isEmpty()
Tests the emptiness of the queue.

Specified by:
isEmpty in interface Collection<T>
Returns:
true if the queue contains no items; false, otherwise.

getLength

int getLength()
Returns the length of the queue.


getQueueListeners

ListenerList<QueueListener<T>> getQueueListeners()
Returns the queue listener list.