pivot.collections.concurrent
Class SynchronizedCollection<T>

java.lang.Object
  extended by pivot.collections.concurrent.SynchronizedCollection<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>
Direct Known Subclasses:
SynchronizedList, SynchronizedMap, SynchronizedSet

public abstract class SynchronizedCollection<T>
extends Object
implements Collection<T>

Abstract base class for synchronized collection wrappers.

NOTE In order to guarantee thread-safe access, all access to the backing collection must be via the synchronized wrapper.

Author:
gbrown

Field Summary
protected  Collection<T> collection
           
 
Constructor Summary
SynchronizedCollection(Collection<T> collection)
           
 
Method Summary
 Comparator<T> getComparator()
          Returns the collection's sort order.
 Iterator<T> iterator()
          NOTE Callers must manually synchronize on the SynchronizedCollection instance to ensure thread safety during iteration.
 void setComparator(Comparator<T> comparator)
          Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface pivot.collections.Collection
clear
 

Field Detail

collection

protected Collection<T> collection
Constructor Detail

SynchronizedCollection

public SynchronizedCollection(Collection<T> collection)
Method Detail

getComparator

public Comparator<T> getComparator()
Description copied from interface: Collection
Returns the collection's sort order.

Specified by:
getComparator in interface Collection<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(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.

Specified by:
setComparator in interface Collection<T>
Parameters:
comparator - The comparator used to order elements in the collection, or null if the collection is unsorted.

iterator

public Iterator<T> iterator()
NOTE Callers must manually synchronize on the SynchronizedCollection instance to ensure thread safety during iteration.

Specified by:
iterator in interface Iterable<T>