Package org.intermine.util
Class CacheMap<K,V>
- java.lang.Object
-
- org.intermine.util.ReferenceMap<K,V>
-
- org.intermine.util.SoftReferenceMap<K,V>
-
- org.intermine.util.CacheMap<K,V>
-
- Type Parameters:
K
- the type of keys maintained by this mapV
- the type of mapped values
- All Implemented Interfaces:
java.util.Map<K,V>
- Direct Known Subclasses:
ReportObjectFactory
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.
- Author:
- Matthew Wakeling
- See Also:
SoftReference
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.intermine.util.ReferenceMap
ReferenceMap.ReferenceWithKey<K>
-
-
Field Summary
-
Fields inherited from class org.intermine.util.ReferenceMap
name, NULL_VALUE, queue, subMap
-
-
Constructor Summary
Constructors Constructor Description 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.lang.String name)
Constructs a new, empty CacheMap with the default initial capacity (16) and the default load factor (0.75), and a name.CacheMap(java.util.Map<K,V> t)
Constructs a new CacheMap with the same mappings as the specified Map.
-
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
-
-
-
-
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 CacheMaploadFactor
- 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.
-
-