org.intermine.util
Class CacheMap<K,V>

java.lang.Object
  extended by org.intermine.util.ReferenceMap<K,V>
      extended by org.intermine.util.SoftReferenceMap<K,V>
          extended by org.intermine.util.CacheMap<K,V>
Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Implemented Interfaces:
java.util.Map<K,V>
Direct Known Subclasses:
DisplayObjectFactory

public class CacheMap<K,V>
extends SoftReferenceMap<K,V>

This is a Map implementation designed specifically for people intending to create a cache. The keys are held strongly, but the values are held softly, so the values can be garbage-collected. When an entry is garbage-collected, its key is removed from the Map on the next Map activity.

The entrySet() and values() methods of this class do not work.

See Also:
SoftReference

Nested Class Summary
 
Nested classes/interfaces inherited from class org.intermine.util.ReferenceMap
ReferenceMap.ReferenceWithKey<K>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class org.intermine.util.ReferenceMap
name, NULL_VALUE, queue, subMap
 
Constructor Summary
CacheMap()
          Constructs a new, empty CacheMap with the default initial capacity (16) and the default load factor (0.75).
CacheMap(int initialCapacity)
          Constructs a new, empty CacheMap with the given initial capacity and the default load factor, which is 0.75.
CacheMap(int initialCapacity, float loadFactor)
          Constructs a new, empty CacheMap with the given initial capacity and the given load factor.
CacheMap(java.util.Map<K,V> t)
          Constructs a new CacheMap with the same mappings as the specified Map.
CacheMap(java.lang.String name)
          Constructs a new, empty CacheMap with the default initial capacity (16) and the default load factor (0.75), and a name.
 
Method Summary
 
Methods inherited from class org.intermine.util.SoftReferenceMap
newRef
 
Methods inherited from class org.intermine.util.ReferenceMap
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, toString, values
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CacheMap

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

Parameters:
initialCapacity - The initial capacity of the CacheMap
loadFactor - The load factor of the CacheMap
Throws:
java.lang.IllegalArgumentException - If the initial capacity is negative, or if the load factor is nonpositive.

CacheMap

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

Parameters:
initialCapacity - The initial capacity of the CacheMap
Throws:
java.lang.IllegalArgumentException - If the initial capacity is negative.

CacheMap

public CacheMap()
Constructs a new, empty CacheMap with the default initial capacity (16) and the default load factor (0.75).


CacheMap

public CacheMap(java.lang.String name)
Constructs a new, empty CacheMap with the default initial capacity (16) and the default load factor (0.75), and a name.

Parameters:
name - the name of the CacheMap - printed out in log messages

CacheMap

public CacheMap(java.util.Map<K,V> t)
Constructs a new CacheMap with the same mappings as the specified Map. The CacheMap is created with default load factor, which is 0.75 and an initial capacity sufficient to hold the mappings in the specified Map.

Parameters:
t - the map whose mappings are to be placed in this map.
Throws:
java.lang.NullPointerException - if the specified map is null.