gausssoft.collections
Class SynchronizedCollection
java.lang.Object
|
+--gausssoft.collections.SynchronizedCollection
- All Implemented Interfaces:
- Collection, Serializable
- Direct Known Subclasses:
- SynchronizedList, SynchronizedSet
- public class SynchronizedCollection
- extends Object
- implements Collection, Serializable
The SynchronizedCollection class is used to synchronize all operations on a
Collection
object on a particular object.
Each method of this implementation synchronizes on a specified object specified
at construction time, and then calls the method of the same signature
of the backing collection. Each instance is serializable only if the backing
collection and mutex is serializable.
This is similar to the synchronization methods in Collections
, but
this implementation allows you to choose what object to synchronize on, and allows
subclassing.
- Author:
- Allan Crooks
- See Also:
Collection
,
Collections
, Serialized Form
root
protected final Collection root
- Backing collection.
mutex
protected final Object mutex
- Object to synchronize on.
SynchronizedCollection
public SynchronizedCollection(Collection root,
Object mutex)
- Creates a new SynchronizedCollection.
- Parameters:
root
- The collection to use as the backing collection.mutex
- The object to synchronize operations on.- Throws:
NullPointerException
- If root is null
.
SynchronizedCollection
public SynchronizedCollection(Collection root)
- Creates a new SynchronizedCollection.
The object constructed will synchronize all operations on itself.
- Parameters:
root
- The collection to use as the backing collection.- Throws:
NullPointerException
- If root is null
.
size
public int size()
- Specified by:
size
in interface Collection
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interface Collection
contains
public boolean contains(Object o)
- Specified by:
contains
in interface Collection
iterator
public Iterator iterator()
- Specified by:
iterator
in interface Collection
toArray
public Object[] toArray()
- Specified by:
toArray
in interface Collection
toArray
public Object[] toArray(Object[] a)
- Specified by:
toArray
in interface Collection
add
public boolean add(Object o)
- Specified by:
add
in interface Collection
remove
public boolean remove(Object o)
- Specified by:
remove
in interface Collection
containsAll
public boolean containsAll(Collection c)
- Specified by:
containsAll
in interface Collection
addAll
public boolean addAll(Collection c)
- Specified by:
addAll
in interface Collection
removeAll
public boolean removeAll(Collection c)
- Specified by:
removeAll
in interface Collection
retainAll
public boolean retainAll(Collection c)
- Specified by:
retainAll
in interface Collection
clear
public void clear()
- Specified by:
clear
in interface Collection
equals
public boolean equals(Object o)
- Specified by:
equals
in interface Collection
- Overrides:
equals
in class Object
hashCode
public int hashCode()
- Specified by:
hashCode
in interface Collection
- Overrides:
hashCode
in class Object
toString
public String toString()
- Overrides:
toString
in class Object