org.cojen.util
Class SoftValuedHashMap<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.SoftValuedHashMap<K,V>
All Implemented Interfaces:
Cloneable, Map<K,V>

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

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

Note: Softly 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().

Author:
Brian S O'Neill

Constructor Summary
SoftValuedHashMap()
          Constructs a new, empty map with a default capacity and load factor, which is 0.75.
SoftValuedHashMap(int initialCapacity)
          Constructs a new, empty map with the specified initial capacity and default load factor, which is 0.75.
SoftValuedHashMap(int initialCapacity, float loadFactor)
          Constructs a new, empty map with the specified initial capacity and the specified load factor.
SoftValuedHashMap(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

SoftValuedHashMap

public SoftValuedHashMap(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.

SoftValuedHashMap

public SoftValuedHashMap(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.

SoftValuedHashMap

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


SoftValuedHashMap

public SoftValuedHashMap(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.