org.cojen.util
Class WeakValuedHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.cojen.util.ReferencedValueHashMap<K,V>
          extended by org.cojen.util.WeakValuedHashMap<K,V>
All Implemented Interfaces:
Cloneable, Map<K,V>

public class WeakValuedHashMap<K,V>
extends ReferencedValueHashMap<K,V>

A Map that weakly references its values and can be used as a simple cache. WeakValuedHashMap is not thread-safe and must be wrapped with Collections.synchronizedMap to be made thread-safe.

Note: Weakly referenced entries may be automatically removed during either accessor or mutator operations, possibly causing a concurrent modification to be detected. Therefore, even if multiple threads are only accessing this map, be sure to synchronize this map first. Also, do not rely on the value returned by size() when using an iterator from this map. The iterators may return less entries than the amount reported by size().

Since:
2.1
Author:
Brian S O'Neill

Constructor Summary
WeakValuedHashMap()
          Constructs a new, empty map with a default capacity and load factor, which is 0.75.
WeakValuedHashMap(int initialCapacity)
          Constructs a new, empty map with the specified initial capacity and default load factor, which is 0.75.
WeakValuedHashMap(int initialCapacity, float loadFactor)
          Constructs a new, empty map with the specified initial capacity and the specified load factor.
WeakValuedHashMap(Map<? extends K,? extends V> t)
          Constructs a new map with the same mappings as the given map.
 
Method Summary
 
Methods inherited from class org.cojen.util.ReferencedValueHashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, toString, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
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

WeakValuedHashMap

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

Parameters:
initialCapacity - the initial capacity of the HashMap.
loadFactor - the load factor of the HashMap
Throws:
IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive.

WeakValuedHashMap

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

Parameters:
initialCapacity - the initial capacity of the HashMap.
Throws:
IllegalArgumentException - if the initial capacity is less than zero.

WeakValuedHashMap

public WeakValuedHashMap()
Constructs a new, empty map with a default capacity and load factor, which is 0.75.


WeakValuedHashMap

public WeakValuedHashMap(Map<? extends K,? extends V> t)
Constructs a new map with the same mappings as the given map. The map is created with a capacity of twice the number of mappings in the given map or 11 (whichever is greater), and a default load factor, which is 0.75.



Copyright © 2004-2008 Brian S O'Neill. All Rights Reserved.