Package org.apache.pivot.collections
Class LinkedQueue<T>
- java.lang.Object
-
- org.apache.pivot.collections.LinkedQueue<T>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<T>,Collection<T>,Queue<T>
public class LinkedQueue<T> extends java.lang.Object implements Queue<T>, java.io.Serializable
Implementation of theQueueinterface that is backed by a linked list.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LinkedQueue()LinkedQueue(int maxLength)LinkedQueue(int maxLength, java.util.Comparator<T> comparator)LinkedQueue(java.util.Comparator<T> comparator)
-
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.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)Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.voidsetMaxLength(int maxLength)Set the maximum allowed queue length (0 means unlimited).
-
-
-
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 maxLength)
Description copied from interface:QueueSet the maximum allowed queue length (0 means unlimited).- Specified by:
setMaxLengthin interfaceQueue<T>- Parameters:
maxLength- The maximum allowed length.
-
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)
Description copied from interface:CollectionSets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.Calling this method more than once with the same comparator will re-sort the collection.
- Specified by:
setComparatorin interfaceCollection<T>- Parameters:
comparator- The comparator used to order elements in the collection, or null if the collection is unsorted.
-
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.
-
-