Package org.biojava.nbio.core.util
Class SoftHashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
org.biojava.nbio.core.util.SoftHashMap<K,V>
- Type Parameters:
K
- the key typeV
- the value type
- All Implemented Interfaces:
Map<K,
V>
An in memory cache using soft references. (can be garbage collected)
This code is based on: http://java-interview-faqs.blogspot.com/2008/09/building-faster-and-efficient-cache.html
Note that entrySet() is not implemented and therefore many methods such as keySet(), containsKey(), values() etc do not work.
This class is therefore best used as a cache simply to put and get items by a known key
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
-
Constructor Summary
-
Method Summary
Methods inherited from class java.util.AbstractMap
clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, values
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
DEFAULT_LIMIT
- See Also:
-
-
Constructor Details
-
SoftHashMap
public SoftHashMap() -
SoftHashMap
- Parameters:
hardSize
- A maximum number of items to maintain hard references to that will not be eligible for garbage collection
-
-
Method Details
-
get
-
put
Here we put the key, value pair into the HashMap using a SoftValue object. -
remove
-
clear
-
size
-
entrySet
-