org.millscript.commons.util.map
Class AbstractEReferenceHashMap<K,V>

java.lang.Object
  extended by org.millscript.commons.util.map.AbstractIMap<K,V>
      extended by org.millscript.commons.util.map.AbstractUMap<K,V>
          extended by org.millscript.commons.util.map.AbstractEMap<K,V>
              extended by org.millscript.commons.util.map.AbstractEReferenceHashMap<K,V>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, org.millscript.commons.alert.AlertDecorator, EMap<K,V>, IMap<K,V>, UMap<K,V>
Direct Known Subclasses:
ESoftHashMap, EWeakHashMap

public abstract class AbstractEReferenceHashMap<K,V>
extends AbstractEMap<K,V>
implements java.lang.Cloneable, java.io.Serializable

This class provides a mutable hash Map implementation that stores keys using Reference objects. This allows mappings within the map to be removed at the discretion of the garbage collector, depending on the type of reference used.

See Also:
Serialized Form

Nested Class Summary
static class AbstractEReferenceHashMap.HashMapIterator<K,V>
          This class implements a map iterator which iterates over an array of hash buckets, sharing the backing store with it's enclosing mutable map.
static class AbstractEReferenceHashMap.HashMapKeysIterator<K>
          This class implements a map iterator which iterates over an array of hash map buckets, returning each maplet key, sharing the backing store with it's enclosing mutable map.
static class AbstractEReferenceHashMap.HashMapKeysList<K>
          This class implements an immutable list which is backed by an array of hash map buckets, but NOTE the values in the list are actually the individual hash maplet keys.
static class AbstractEReferenceHashMap.HashMapMapletIterator<K,V>
          This class implements a map iterator which iterates over an array of hash map buckets, returning each maplet as the value.
static class AbstractEReferenceHashMap.HashMapMapletList<K,V>
          This class implements an immutable list which is backed by an array of hash map buckets, but NOTE the values in the list are actually the individual hash maplets themselves.
static class AbstractEReferenceHashMap.HashMapValuesIterator<V>
          This class implements a map iterator which iterates over an array of hash map buckets, returning each maplet value, sharing the backing store with it's enclosing mutable map.
static class AbstractEReferenceHashMap.HashMapValuesList<V>
          This class implements an immutable list which is backed by an array of hash map buckets, but NOTE the values in the list are actually the individual hash maplet values.
 
Field Summary
protected  java.lang.ref.ReferenceQueue<K> referenceQueue
          The reference queue we'll use to keep track of collected keys.
 
Constructor Summary
AbstractEReferenceHashMap()
          Constructs a new, emtpy mutable hash map.
AbstractEReferenceHashMap(IMap<K,V> map)
          Constructs a new mutable hash map which contains all the mappings from the specified map.
 
Method Summary
protected  void clearQueuedReferences()
          This method should be called to clear any queued references, which implies the keys are no longer valid in this mapping.
 java.lang.Object clone()
           
 boolean contains(K key, V value)
          Returns true if this map contains a mapping from the specified key to the specified value.
 boolean containsKey(K key)
          Returns true if this map contains an entry for the specified key.
 boolean containsValue(V value)
          Returns true if this map contains an entry with the specified value.
 V get(K key)
          Returns the value associated with the specified key, or the default value if no such mapping exists.
 void insert(K key, V value)
          Inserts the specified key-value pair into this map, associating the key with the value.
protected  void insertWithRehash(K key, V value)
          Inserts the specified key-value mapping after performing a rehash of the backing store to increase it's size.
 MapIterator<K,V> iterator(boolean share)
          Returns an iterator over the mappings in this map.
abstract  java.lang.ref.Reference<K> makeReference(K key)
           
 void remove(K key, V value)
          Removes the specified key-value pair from this map.
 void removeAll()
          Removes all the mappings from this map.
 void removeKey(K key)
          Removes the mapping for the specified key.
 void removeValue(V value)
          Removes any mappings from this map which map to the specified value.
protected  IList<K> sharedKeyList()
           
protected  IList<Maplet<K,V>> sharedMapletList()
           
protected  IList<V> sharedValueList()
           
 int size()
          Returns the number of mappings defined in this map.
 void update(K key, V value)
          Updates the mapping for the specified key with the specified value, changing the previous value.
 
Methods inherited from class org.millscript.commons.util.map.AbstractEMap
insert, insertAll, remove, removeAll
 
Methods inherited from class org.millscript.commons.util.map.AbstractUMap
update, updateAll
 
Methods inherited from class org.millscript.commons.util.map.AbstractIMap
contains, containsAll, decorate, equals, getDefault, hashCode, isEmtpy, keyList, mapletList, setDefault, toString, valueList
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.millscript.commons.util.UMap
update, updateAll
 
Methods inherited from interface org.millscript.commons.util.IMap
contains, containsAll, equals, getDefault, hashCode, isEmtpy, keyList, mapletList, setDefault, valueList
 

Field Detail

referenceQueue

protected final transient java.lang.ref.ReferenceQueue<K> referenceQueue
The reference queue we'll use to keep track of collected keys.

Constructor Detail

AbstractEReferenceHashMap

public AbstractEReferenceHashMap()
Constructs a new, emtpy mutable hash map.


AbstractEReferenceHashMap

public AbstractEReferenceHashMap(IMap<K,V> map)
Constructs a new mutable hash map which contains all the mappings from the specified map.

Parameters:
map - the Map to copy mappings from
Method Detail

clearQueuedReferences

protected void clearQueuedReferences()
This method should be called to clear any queued references, which implies the keys are no longer valid in this mapping.


clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException
See Also:
Object.clone()

contains

public boolean contains(K key,
                        V value)
Description copied from interface: IMap
Returns true if this map contains a mapping from the specified key to the specified value.

Specified by:
contains in interface IMap<K,V>
Parameters:
key - the key whose presence to test
value - the value which must match that stored against the specified key
Returns:
true if this map contains a mapping for the specified key-value combination
See Also:
IMap.contains(java.lang.Object, java.lang.Object)

containsKey

public boolean containsKey(K key)
Description copied from interface: IMap
Returns true if this map contains an entry for the specified key.

Specified by:
containsKey in interface IMap<K,V>
Parameters:
key - the key whose presence to test
Returns:
true if this map contains a mapping for the specified key
See Also:
IMap.containsKey(java.lang.Object)

containsValue

public boolean containsValue(V value)
Description copied from interface: IMap
Returns true if this map contains an entry with the specified value.

Specified by:
containsValue in interface IMap<K,V>
Parameters:
value - the value whose presence to test
Returns:
true if this map contains a mapping with the specified value
See Also:
IMap.containsValue(java.lang.Object)

get

public V get(K key)
Description copied from interface: IMap
Returns the value associated with the specified key, or the default value if no such mapping exists.

Specified by:
get in interface IMap<K,V>
Parameters:
key - the key whose associated value to return
Returns:
the value associated with the specified key, or the default value if there is no mapping for the key
See Also:
IMap.get(java.lang.Object)

insert

public void insert(K key,
                   V value)
Description copied from interface: EMap
Inserts the specified key-value pair into this map, associating the key with the value.

Specified by:
insert in interface EMap<K,V>
Parameters:
key - the key to associate the value with
value - the value to associate the key with
See Also:
EMap.insert(java.lang.Object, java.lang.Object)

insertWithRehash

protected void insertWithRehash(K key,
                                V value)
Inserts the specified key-value mapping after performing a rehash of the backing store to increase it's size.

Parameters:
key - the new key to add to the mapping
value - the new value to associate with the given key

iterator

public MapIterator<K,V> iterator(boolean share)
Description copied from interface: IMap
Returns an iterator over the mappings in this map. The order of iteration is implementation dependant and should follow any ordering the implementation provides.

Specified by:
iterator in interface IMap<K,V>
Parameters:
share - if true this instances backing store should be shared with the returned list, otherwise any backing store will be copied.
Returns:
an iterator over this maps mappings
See Also:
IMap.iterator(boolean)

makeReference

public abstract java.lang.ref.Reference<K> makeReference(K key)

remove

public void remove(K key,
                   V value)
Description copied from interface: EMap
Removes the specified key-value pair from this map. For this removal to be successful the specified mapping must exist in this map.

Specified by:
remove in interface EMap<K,V>
Parameters:
key - the key to remove from this map if it is associated with the specified value
value - the value to remove from this map if it is associated with the specified key
See Also:
EMap.remove(java.lang.Object, java.lang.Object)

removeAll

public void removeAll()
Description copied from interface: EMap
Removes all the mappings from this map.

Specified by:
removeAll in interface EMap<K,V>
See Also:
EMap.removeAll()

removeKey

public void removeKey(K key)
Description copied from interface: EMap
Removes the mapping for the specified key.

Specified by:
removeKey in interface EMap<K,V>
Parameters:
key - the key to remove from this map
See Also:
EMap.removeKey(java.lang.Object)

removeValue

public void removeValue(V value)
Description copied from interface: EMap
Removes any mappings from this map which map to the specified value.

Specified by:
removeValue in interface EMap<K,V>
Parameters:
value - the value to remove from this map
See Also:
EMap.removeValue(java.lang.Object)

sharedKeyList

protected IList<K> sharedKeyList()
Specified by:
sharedKeyList in class AbstractIMap<K,V>
See Also:
AbstractIMap.sharedKeyList()

sharedMapletList

protected IList<Maplet<K,V>> sharedMapletList()
Specified by:
sharedMapletList in class AbstractIMap<K,V>
See Also:
AbstractIMap.sharedMapletList()

sharedValueList

protected IList<V> sharedValueList()
Specified by:
sharedValueList in class AbstractIMap<K,V>
See Also:
AbstractIMap.sharedValueList()

size

public int size()
Description copied from interface: IMap
Returns the number of mappings defined in this map.

Specified by:
size in interface IMap<K,V>
Returns:
the number of mappings in this map
See Also:
IMap.size()

update

public void update(K key,
                   V value)
Description copied from interface: UMap
Updates the mapping for the specified key with the specified value, changing the previous value.

Specified by:
update in interface UMap<K,V>
Parameters:
key - the key to associate the value with
value - the value to associate the key with
See Also:
UMap.update(java.lang.Object, java.lang.Object)


Copyright © 2005-2007 Open World Ltd. All Rights Reserved.