org.apache.pivot.collections
Class ArrayQueue<T>

java.lang.Object
  extended by org.apache.pivot.collections.ArrayList<T>
      extended by org.apache.pivot.collections.ArrayQueue<T>
All Implemented Interfaces:
Serializable, Iterable<T>, Collection<T>, List<T>, Queue<T>, Sequence<T>

public class ArrayQueue<T>
extends ArrayList<T>
implements Queue<T>

Implementation of the Queue interface that is backed by an array.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Queue
Queue.QueueListenerList<T>
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.List
List.ItemIterator<T>, List.ListListenerList<T>
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Sequence
Sequence.Tree
 
Field Summary
 
Fields inherited from class org.apache.pivot.collections.ArrayList
DEFAULT_CAPACITY
 
Constructor Summary
ArrayQueue()
           
ArrayQueue(Comparator<T> comparator)
           
ArrayQueue(int capacity)
           
 
Method Summary
 T dequeue()
          Removes the item from the head of the queue and returns it.
 void enqueue(T item)
          Enqueues an item.
 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 class org.apache.pivot.collections.ArrayList
add, binarySearch, binarySearch, clear, ensureCapacity, equals, get, getCapacity, getComparator, getLength, getListListeners, hashCode, indexOf, insert, iterator, remove, remove, setComparator, sort, sort, sort, toArray, toString, trimToSize, update
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.pivot.collections.Collection
clear, getComparator, setComparator
 
Methods inherited from interface java.lang.Iterable
iterator
 

Constructor Detail

ArrayQueue

public ArrayQueue()

ArrayQueue

public ArrayQueue(Comparator<T> comparator)

ArrayQueue

public ArrayQueue(int capacity)
Method Detail

enqueue

public void enqueue(T item)
Description copied from interface: Queue
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.

Specified by:
enqueue in interface Queue<T>
Parameters:
item - The item to add to the queue.

dequeue

public T dequeue()
Description copied from interface: Queue
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);

Specified by:
dequeue in interface Queue<T>

peek

public T peek()
Description copied from interface: Queue
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.

Specified by:
peek in interface Queue<T>

isEmpty

public boolean isEmpty()
Description copied from interface: Queue
Tests the emptiness of the queue.

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

getQueueListeners

public ListenerList<QueueListener<T>> getQueueListeners()
Description copied from interface: Queue
Returns the queue listener list.

Specified by:
getQueueListeners in interface Queue<T>