pivot.collections.concurrent
Class SynchronizedQueue<T>

java.lang.Object
  extended by pivot.collections.concurrent.SynchronizedCollection<T>
      extended by pivot.collections.concurrent.SynchronizedList<T>
          extended by pivot.collections.concurrent.SynchronizedQueue<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, Queue<T>, Sequence<T>

public class SynchronizedQueue<T>
extends SynchronizedList<T>
implements Queue<T>

Synchronized implementation of the Queue interface.

Author:
gbrown

Nested Class Summary
 
Nested classes/interfaces inherited from interface pivot.collections.List
List.ListListenerList<T>
 
Nested classes/interfaces inherited from interface pivot.collections.Sequence
Sequence.Search, Sequence.Sort, Sequence.Tree
 
Field Summary
 
Fields inherited from class pivot.collections.concurrent.SynchronizedCollection
collection
 
Constructor Summary
SynchronizedQueue(Queue<T> queue)
           
 
Method Summary
 int add(T item)
          Adds an item to the list.
 T dequeue()
          Removes an item from the head of the queue, blocking if the queue is empty.
 void enqueue(T item)
          Enqueues an item.
 void insert(T item, int index)
          Inserts an item into the list.
 T peek()
          Returns the item at the head of the queue without removing it from the queue.
 
Methods inherited from class pivot.collections.concurrent.SynchronizedList
clear, get, getLength, getListListeners, indexOf, remove, remove, update
 
Methods inherited from class pivot.collections.concurrent.SynchronizedCollection
getComparator, iterator, setComparator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface pivot.collections.List
clear, getLength, getListListeners, remove, setComparator, update
 
Methods inherited from interface pivot.collections.Sequence
get, indexOf, remove
 
Methods inherited from interface pivot.collections.Collection
getComparator
 
Methods inherited from interface java.lang.Iterable
iterator
 

Constructor Detail

SynchronizedQueue

public SynchronizedQueue(Queue<T> queue)
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()
Removes an item from the head of the queue, blocking if the queue is empty.

Specified by:
dequeue in interface Queue<T>
Returns:
The item at the head of the queue, or null if the removing thread was interrupted.

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. getLength() can be used to distinguish between these two cases.

Specified by:
peek in interface Queue<T>

add

public int add(T item)
Description copied from interface: List
Adds an item to the list. If the list is unsorted, the item is appended to the end of the list. Otherwise, it is inserted at the appropriate index.

Specified by:
add in interface List<T>
Specified by:
add in interface Sequence<T>
Overrides:
add in class SynchronizedList<T>
Parameters:
item - The item to be added to the sequence.
Returns:
The index at which the item was added.
See Also:
ListListener.itemInserted(List, int)

insert

public void insert(T item,
                   int index)
Description copied from interface: List
Inserts an item into the list.

Specified by:
insert in interface List<T>
Specified by:
insert in interface Sequence<T>
Overrides:
insert in class SynchronizedList<T>
Parameters:
item - The item to be added to the list.
index - The index at which the item should be inserted. Must be a value between 0 and getLength().
See Also:
ListListener.itemInserted(List, int)