Package org.apache.pivot.collections
Class ArrayQueue<T>
- java.lang.Object
 - 
- org.apache.pivot.collections.ArrayQueue<T>
 
 
- 
- Type Parameters:
 T- The type of object stored in this queue.
- All Implemented Interfaces:
 java.io.Serializable,java.lang.Iterable<T>,Collection<T>,Queue<T>
public class ArrayQueue<T> extends java.lang.Object implements Queue<T>, java.io.Serializable
- See Also:
 - Serialized Form
 
 
- 
- 
Constructor Summary
Constructors Constructor Description ArrayQueue()Construct an empty queue, with all defaults.ArrayQueue(int capacity)Construct an empty queue with a given initial capacity.ArrayQueue(int capacity, int maxLen)Construct an empty queue with a given initial capacity and maxmimum length.ArrayQueue(int capacity, int maxLen, java.util.Comparator<T> comparator)Construct an empty queue with a given initial capacity, maximum length, and comparator for ordering the queue.ArrayQueue(java.util.Comparator<T> comparator)Construct an empty queue with the given comparator used to order the elements in it. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all elements from the collection.Tdequeue()Removes the item from the head of the queue and returns it.voidenqueue(T item)Enqueues an item.voidensureCapacity(int capacity)Ensure that the queue has sufficient internal capacity to satisfy the given number of elements.java.util.Comparator<T>getComparator()Returns the collection's sort order.intgetLength()intgetMaxLength()ListenerList<QueueListener<T>>getQueueListeners()booleanisEmpty()Tests the emptiness of the queue.java.util.Iterator<T>iterator()Tpeek()Returns the item at the head of the queue without removing it from the queue.voidsetComparator(java.util.Comparator<T> comparator)Set/remove the comparator for this queue.voidsetMaxLength(int maxLen)Set the maximum allowed queue length (0 means unlimited). 
 - 
 
- 
- 
Constructor Detail
- 
ArrayQueue
public ArrayQueue()
Construct an empty queue, with all defaults. 
- 
ArrayQueue
public ArrayQueue(java.util.Comparator<T> comparator)
Construct an empty queue with the given comparator used to order the elements in it.- Parameters:
 comparator- A comparator used to sort the elements in the queue as they are added.
 
- 
ArrayQueue
public ArrayQueue(int capacity)
Construct an empty queue with a given initial capacity.- Parameters:
 capacity- The initial capacity for the queue.
 
- 
ArrayQueue
public ArrayQueue(int capacity, int maxLen)Construct an empty queue with a given initial capacity and maxmimum length.- Parameters:
 capacity- The initial capacity for the queue.maxLen- The maximum permitted queue length.
 
- 
ArrayQueue
public ArrayQueue(int capacity, int maxLen, java.util.Comparator<T> comparator)Construct an empty queue with a given initial capacity, maximum length, and comparator for ordering the queue.- Parameters:
 capacity- The initial capacity for the queue.maxLen- The maximum permitted queue length.comparator- The comparator to use for ordering the elements.
 
 - 
 
- 
Method Detail
- 
enqueue
public void enqueue(T item)
Description copied from interface:QueueEnqueues an item. If the queue is unsorted, the item is added at the tail of the queue (index0). Otherwise, it is inserted at the appropriate index according to the priority/sort order.If there is a maximum queue length defined and the queue is already at the maximum length this new item will not be queued.
 
- 
dequeue
public T dequeue()
Description copied from interface:QueueRemoves 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
public T peek()
Description copied from interface:QueueReturns 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. 
- 
clear
public void clear()
Description copied from interface:CollectionRemoves all elements from the collection.- Specified by:
 clearin interfaceCollection<T>
 
- 
isEmpty
public boolean isEmpty()
Description copied from interface:QueueTests the emptiness of the queue. 
- 
getLength
public int getLength()
 
- 
getMaxLength
public int getMaxLength()
- Specified by:
 getMaxLengthin interfaceQueue<T>- Returns:
 - The maximum queue length allowed (0 means unlimited).
 
 
- 
setMaxLength
public void setMaxLength(int maxLen)
Description copied from interface:QueueSet the maximum allowed queue length (0 means unlimited).- Specified by:
 setMaxLengthin interfaceQueue<T>- Parameters:
 maxLen- The maximum allowed length.
 
- 
ensureCapacity
public void ensureCapacity(int capacity)
Ensure that the queue has sufficient internal capacity to satisfy the given number of elements.- Parameters:
 capacity- The capacity to ensure (to make sure no further allocations are done to accommodate this number of elements).
 
- 
getComparator
public java.util.Comparator<T> getComparator()
Description copied from interface:CollectionReturns the collection's sort order.- Specified by:
 getComparatorin interfaceCollection<T>- Returns:
 - The comparator used to order elements in the collection, or
 
nullif the sort order is undefined. - See Also:
 Collection.setComparator(Comparator)
 
- 
setComparator
public void setComparator(java.util.Comparator<T> comparator)
Set/remove the comparator for this queue.If a new comparator is set the queue will be reordered if it contains any elements. Removing the comparator will not reorder any elements.
Calls the
QueueListener.comparatorChanged(org.apache.pivot.collections.Queue<T>, java.util.Comparator<T>)method for each registered listener after setting the new comparator.- Specified by:
 setComparatorin interfaceCollection<T>- Parameters:
 comparator- The new comparator used to order the elements in the queue. Can benullto remove the existing comparator.
 
- 
iterator
public java.util.Iterator<T> iterator()
- Specified by:
 iteratorin interfacejava.lang.Iterable<T>
 
- 
getQueueListeners
public ListenerList<QueueListener<T>> getQueueListeners()
- Specified by:
 getQueueListenersin interfaceQueue<T>- Returns:
 - The queue listener list.
 
 
 - 
 
 -