gausssoft.collections
Class SynchronizedMap
java.lang.Object
|
+--gausssoft.collections.SynchronizedMap
- All Implemented Interfaces:
- Map, Serializable
- Direct Known Subclasses:
- SynchronizedSortedMap
- public class SynchronizedMap
- extends Object
- implements Map, Serializable
The SynchronizedMap class is used to synchronize all operations on a
Map 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 map. Each instance is serializable only if the backing
map 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.
The keySet(), entrySet() and values() all return
collections that synchronize on the same mutex as the synchronized map. The first time
these methods are called, a SynchronizedCollection or SynchronizedSet is
created, and stored within the SynchronizedMap. Every subsequent call to these methods
will return these stored objects, as opposed to creating new synchronized objects each
method call.
- Author:
- Allan Crooks
- See Also:
Collections,
Map, Serialized Form
|
Field Summary |
protected Object |
mutex
Object to synchronize on. |
protected Map |
root
Backing map. |
root
protected final Map root
- Backing map.
mutex
protected final Object mutex
- Object to synchronize on.
SynchronizedMap
public SynchronizedMap(Map root,
Object mutex)
- Creates a new SynchronizedMap.
- Parameters:
root - The map to use as the backing map.mutex - The object to synchronize operations on.- Throws:
NullPointerException - If root is null.
SynchronizedMap
public SynchronizedMap(Map root)
- Creates a new SynchronizedMap.
The object constructed will synchronize all operations on itself.
- Parameters:
root - The map to use as the backing map.- Throws:
NullPointerException - If root is null.
size
public int size()
- Specified by:
size in interface Map
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty in interface Map
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey in interface Map
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue in interface Map
get
public Object get(Object key)
- Specified by:
get in interface Map
put
public Object put(Object key,
Object value)
- Specified by:
put in interface Map
remove
public Object remove(Object key)
- Specified by:
remove in interface Map
putAll
public void putAll(Map t)
- Specified by:
putAll in interface Map
clear
public void clear()
- Specified by:
clear in interface Map
keySet
public Set keySet()
- Specified by:
keySet in interface Map
values
public Collection values()
- Specified by:
values in interface Map
entrySet
public Set entrySet()
- Specified by:
entrySet in interface Map
equals
public boolean equals(Object o)
- Specified by:
equals in interface Map- Overrides:
equals in class Object
hashCode
public int hashCode()
- Specified by:
hashCode in interface Map- Overrides:
hashCode in class Object
toString
public String toString()
- Overrides:
toString in class Object