ecologylab.generic
Class HashMapWriteSynch3<K,I,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by ecologylab.generic.HashMapWriteSynch3<K,I,V>
Type Parameters:
K - Class of the resulting key.
I - Class of the intermediate object, which is used to form keys and values.
V - Class of the value.
All Implemented Interfaces:
ValueFactory<I,V>, java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>

public abstract class HashMapWriteSynch3<K,I,V>
extends java.util.HashMap<K,V>
implements ValueFactory<I,V>

Hashed data structure with synchronized writes/deletes and unsynchronized reads. Uses three objects, instead of two. The values and keys are both formed from a third intermediate object. This enables, for example, using a String as a key, but getting that String from an object of another class, which is also the value.

Author:
andruid, robinson
See Also:
Serialized Form

Constructor Summary
HashMapWriteSynch3()
           
HashMapWriteSynch3(int arg0)
           
HashMapWriteSynch3(int arg0, float arg1)
           
HashMapWriteSynch3(java.util.Map<? extends K,? extends V> arg0)
           
 
Method Summary
protected abstract  K createKey(I intermediate)
           
abstract  V createValue(I intermediate)
           
 V getOrCreateAndPutIfNew(I intermediate)
           
 V getOrCreateAndPutIfNew(I intermediate, ValueFactory<I,V> factory)
          If there is already an entry, return it.
 void putAll(java.util.Map<? extends K,? extends V> m)
          Sycnhronizes if you add another map to this one.
 V remove(java.lang.Object key)
          Sycnhronizes remove.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

HashMapWriteSynch3

public HashMapWriteSynch3(int arg0,
                          float arg1)

HashMapWriteSynch3

public HashMapWriteSynch3(int arg0)

HashMapWriteSynch3

public HashMapWriteSynch3()

HashMapWriteSynch3

public HashMapWriteSynch3(java.util.Map<? extends K,? extends V> arg0)
Method Detail

createKey

protected abstract K createKey(I intermediate)

createValue

public abstract V createValue(I intermediate)
Specified by:
createValue in interface ValueFactory<I,V>

getOrCreateAndPutIfNew

public V getOrCreateAndPutIfNew(I intermediate)

getOrCreateAndPutIfNew

public V getOrCreateAndPutIfNew(I intermediate,
                                ValueFactory<I,V> factory)
If there is already an entry, return it. Otherwise, create an entry with the factory.

Returns:
The entry matching key, found or constructed.

remove

public V remove(java.lang.Object key)
Sycnhronizes remove.

Specified by:
remove in interface java.util.Map<K,V>
Overrides:
remove in class java.util.HashMap<K,V>

putAll

public void putAll(java.util.Map<? extends K,? extends V> m)
Sycnhronizes if you add another map to this one.

Specified by:
putAll in interface java.util.Map<K,V>
Overrides:
putAll in class java.util.HashMap<K,V>