gausssoft.collections
Class SynchronizedSortedMap

java.lang.Object
  |
  +--gausssoft.collections.SynchronizedMap
        |
        +--gausssoft.collections.SynchronizedSortedMap
All Implemented Interfaces:
Map, Serializable, SortedMap

public class SynchronizedSortedMap
extends SynchronizedMap
implements SortedMap

The SynchronizedSortedMap class is used to synchronize all operations on a SortedMap 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 SynchronizedMap.keySet(), SynchronizedMap.entrySet() and SynchronizedMap.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.

The subMap(Object, Object), headMap(Object) and tailMap(Object) methods all return SynchronizedSortedMap objects which synchronize on the same mutex used by the parent SynchronizedSortedMap.

Author:
Allan Crooks
See Also:
Collections, SortedMap, Serialized Form

Inner classes inherited from class java.util.Map
Map.Entry
 
Field Summary
protected  SortedMap root
          Backing map.
 
Fields inherited from class gausssoft.collections.SynchronizedMap
mutex
 
Constructor Summary
SynchronizedSortedMap(SortedMap root)
          Creates a new SynchronizedSortedMap.
SynchronizedSortedMap(SortedMap root, Object mutex)
          Creates a new SynchronizedSortedMap.
 
Method Summary
 Comparator comparator()
           
 Object firstKey()
           
 SortedMap headMap(Object toKey)
           
 Object lastKey()
           
 SortedMap subMap(Object fromKey, Object toKey)
           
 SortedMap tailMap(Object fromKey)
           
 
Methods inherited from class gausssoft.collections.SynchronizedMap
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, toString, values
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Field Detail

root

protected final SortedMap root
Backing map.
Constructor Detail

SynchronizedSortedMap

public SynchronizedSortedMap(SortedMap root,
                             Object mutex)
Creates a new SynchronizedSortedMap.
Parameters:
root - The set to use as the backing set.
mutex - The object to synchronize operations on.
Throws:
NullPointerException - If root is null.

SynchronizedSortedMap

public SynchronizedSortedMap(SortedMap root)
Creates a new SynchronizedSortedMap.

The object constructed will synchronize all operations on itself.

Parameters:
root - The set to use as the backing set.
Throws:
NullPointerException - If root is null.
Method Detail

comparator

public Comparator comparator()
Specified by:
comparator in interface SortedMap

firstKey

public Object firstKey()
Specified by:
firstKey in interface SortedMap

lastKey

public Object lastKey()
Specified by:
lastKey in interface SortedMap

subMap

public SortedMap subMap(Object fromKey,
                        Object toKey)
Specified by:
subMap in interface SortedMap

headMap

public SortedMap headMap(Object toKey)
Specified by:
headMap in interface SortedMap

tailMap

public SortedMap tailMap(Object fromKey)
Specified by:
tailMap in interface SortedMap