|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
org.onemind.commons.java.lang.ref.SoftHashMap
public class SoftHashMap
Nested Class Summary | |
---|---|
private static class |
SoftHashMap.SoftValue
We define our own subclass of SoftReference which contains not only the value but also the key to make it easier to find the entry in the HashMap after it's been garbage collected. |
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Field Summary | |
---|---|
private int |
HARD_REF_SIZE
The number of "hard" references to hold internally. |
private java.util.LinkedList |
hardRefCache
The FIFO list of hard references, order of last access. |
private java.util.Map |
hash
The internal HashMap that will hold the SoftReference. |
private java.lang.ref.ReferenceQueue |
queue
Reference queue for cleared SoftReference objects. |
Constructor Summary | |
---|---|
SoftHashMap()
Constructor |
|
SoftHashMap(int hardSize)
Constructor |
Method Summary | |
---|---|
private void |
_cleanCollectedValues()
Go through the ReferenceQueue and remove garbage collected SoftValue objects from the HashMap |
void |
clear()
|
java.util.Set |
entrySet()
|
java.lang.Object |
get(java.lang.Object key)
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Here we put the key, value pair into the HashMap using a SoftValue object. |
java.lang.Object |
remove(java.lang.Object key)
|
int |
size()
|
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 |
Field Detail |
---|
private final java.util.Map hash
private final int HARD_REF_SIZE
private final java.util.LinkedList hardRefCache
private final java.lang.ref.ReferenceQueue queue
Constructor Detail |
---|
public SoftHashMap()
public SoftHashMap(int hardSize)
hardSize
- the hard reference size to maintainMethod Detail |
---|
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
get
in class java.util.AbstractMap
private void _cleanCollectedValues()
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
put
in class java.util.AbstractMap
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
remove
in class java.util.AbstractMap
public void clear()
clear
in interface java.util.Map
clear
in class java.util.AbstractMap
public int size()
size
in interface java.util.Map
size
in class java.util.AbstractMap
public java.util.Set entrySet()
entrySet
in interface java.util.Map
entrySet
in class java.util.AbstractMap
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |