dsto.dfc.collections
Class WeakValueHashMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by dsto.dfc.collections.WeakValueHashMap
All Implemented Interfaces:
Map

public class WeakValueHashMap
extends AbstractMap
implements Map

A hashmap that has weak values in the same way as WeakHashMap has weak keys. Original author: Chris Wood


Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
protected  Set m_entrySet
           
protected  Map m_hash
           
protected  ReferenceQueue m_queue
           
 
Constructor Summary
WeakValueHashMap()
          Constructs a new, empty WeakValueHashMap with the default initial capacity and the default load factor, which is 0.75.
WeakValueHashMap(int initialCapacity)
          Constructs a new, empty WeakValueHashMap with the given initial capacity and the default load factor, which is 0.75.
WeakValueHashMap(int initialCapacity, float loadFactor)
          Constructs a new, empty WeakValueHashMap with the given initial capacity and the given load factor.
WeakValueHashMap(Map t)
          Constructs a new WeakValueHashMap with the same mappings as the specified Map.
 
Method Summary
 void clear()
          Removes all mappings from this map.
 boolean containsKey(Object key)
          Returns true if this map contains a mapping for the specified key.
 Set entrySet()
          Returns a Set view of the mappings in this map.
 Object get(Object key)
          Returns the value to which this map maps the specified key.
protected  void processQueue()
          Remove all invalidated entries from the map, that is, remove all entries whose keys have been discarded.
 Object put(Object key, Object value)
          Updates this map so that the given key maps to the given value.
 Object remove(Object key)
          Removes the mapping for the given key from this map, if present.
protected static boolean valEquals(Object o1, Object o2)
           
 
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsValue, equals, hashCode, isEmpty, keySet, putAll, size, values
 

Field Detail

m_hash

protected final Map m_hash

m_queue

protected final ReferenceQueue m_queue

m_entrySet

protected Set m_entrySet
Constructor Detail

WeakValueHashMap

public WeakValueHashMap(int initialCapacity,
                        float loadFactor)
Constructs a new, empty WeakValueHashMap with the given initial capacity and the given load factor.

Parameters:
initialCapacity - The initial capacity of the WeakValueHashMap
loadFactor - The load factor of the WeakValueHashMap

WeakValueHashMap

public WeakValueHashMap(int initialCapacity)
Constructs a new, empty WeakValueHashMap with the given initial capacity and the default load factor, which is 0.75.

Parameters:
initialCapacity - The initial capacity of the WeakValueHashMap

WeakValueHashMap

public WeakValueHashMap()
Constructs a new, empty WeakValueHashMap with the default initial capacity and the default load factor, which is 0.75.


WeakValueHashMap

public WeakValueHashMap(Map t)
Constructs a new WeakValueHashMap with the same mappings as the specified Map. The WeakValueHashMap is created with an initial capacity of twice the number of mappings in the specified map or 11 (whichever is greater), and a default load factor, which is 0.75.

Parameters:
t - the map whose mappings are to be placed in this map.
Since:
1.3
Method Detail

processQueue

protected void processQueue()
Remove all invalidated entries from the map, that is, remove all entries whose keys have been discarded. This method should be invoked once by each public mutator in this class. We don't invoke this method in public accessors because that can lead to surprising ConcurrentModificationExceptions.


entrySet

public Set entrySet()
Returns a Set view of the mappings in this map.

Specified by:
entrySet in interface Map
Specified by:
entrySet in class AbstractMap
Returns:
The set of entries in the map. This method creates an empty set if the member is null.

containsKey

public boolean containsKey(Object key)
Returns true if this map contains a mapping for the specified key.

Specified by:
containsKey in interface Map
Overrides:
containsKey in class AbstractMap
Parameters:
key - The key whose presence in this map is to be tested.
Returns:
True if the internal map contains the key, false otherwise.

get

public Object get(Object key)
Returns the value to which this map maps the specified key. If this map does not contain a value for this key, then return null.

Specified by:
get in interface Map
Overrides:
get in class AbstractMap
Parameters:
key - The key whose associated value, if any, is to be returned
Returns:
The value for the spacified key.

put

public Object put(Object key,
                  Object value)
Updates this map so that the given key maps to the given value. If the map previously contained a mapping for key then that mapping is replaced and the previous value is returned.

Specified by:
put in interface Map
Overrides:
put in class AbstractMap
Parameters:
key - The key that is to be mapped to the given value
value - The value to which the given key is to be mapped
Returns:
The previous value to which this key was mapped, or null if if there was no mapping for the key

remove

public Object remove(Object key)
Removes the mapping for the given key from this map, if present.

Specified by:
remove in interface Map
Overrides:
remove in class AbstractMap
Parameters:
key - The key whose mapping is to be removed
Returns:
The value to which this key was mapped, or null if there was no mapping for the key

clear

public void clear()
Removes all mappings from this map.

Specified by:
clear in interface Map
Overrides:
clear in class AbstractMap

valEquals

protected static boolean valEquals(Object o1,
                                   Object o2)


Copyright © 2008 Commonwealth of Australia