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 theQueue
interface 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 void
clear()
Removes all elements from the collection.T
dequeue()
Removes the item from the head of the queue and returns it.void
enqueue(T item)
Enqueues an item.java.util.Comparator<T>
getComparator()
Returns the collection's sort order.int
getLength()
int
getMaxLength()
ListenerList<QueueListener<T>>
getQueueListeners()
boolean
isEmpty()
Tests the emptiness of the queue.java.util.Iterator<T>
iterator()
T
peek()
Returns the item at the head of the queue without removing it from the queue.void
setComparator(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.void
setMaxLength(int maxLength)
Set the maximum allowed queue length (0 means unlimited).
-
-
-
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 (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: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);
-
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.
-
clear
public void clear()
Description copied from interface:Collection
Removes all elements from the collection.- Specified by:
clear
in interfaceCollection<T>
-
isEmpty
public boolean isEmpty()
Description copied from interface:Queue
Tests the emptiness of the queue.
-
getLength
public int getLength()
-
getMaxLength
public int getMaxLength()
- Specified by:
getMaxLength
in interfaceQueue<T>
- Returns:
- The maximum queue length allowed (0 means unlimited).
-
setMaxLength
public void setMaxLength(int maxLength)
Description copied from interface:Queue
Set the maximum allowed queue length (0 means unlimited).- Specified by:
setMaxLength
in interfaceQueue<T>
- Parameters:
maxLength
- The maximum allowed length.
-
getComparator
public java.util.Comparator<T> getComparator()
Description copied from interface:Collection
Returns the collection's sort order.- Specified by:
getComparator
in interfaceCollection<T>
- Returns:
- The comparator used to order elements in the collection, or
null
if the sort order is undefined. - See Also:
Collection.setComparator(Comparator)
-
setComparator
public void setComparator(java.util.Comparator<T> comparator)
Description copied from interface:Collection
Sets 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:
setComparator
in 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:
iterator
in interfacejava.lang.Iterable<T>
-
getQueueListeners
public ListenerList<QueueListener<T>> getQueueListeners()
- Specified by:
getQueueListeners
in interfaceQueue<T>
- Returns:
- The queue listener list.
-
-