public class SoftHashMap
extends java.util.AbstractMap
| Modifier and Type | Class and Description |
|---|---|
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.
|
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
SoftHashMap()
Constructor
|
SoftHashMap(int hardSize)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
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() |
clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, valuesprivate final java.util.Map hash
private final int HARD_REF_SIZE
private final java.util.LinkedList hardRefCache
private final java.lang.ref.ReferenceQueue queue
public SoftHashMap()
public SoftHashMap(int hardSize)
hardSize - the hard reference size to maintainpublic java.lang.Object get(java.lang.Object key)
get in interface java.util.Mapget in class java.util.AbstractMapprivate void _cleanCollectedValues()
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
put in interface java.util.Mapput in class java.util.AbstractMappublic java.lang.Object remove(java.lang.Object key)
remove in interface java.util.Mapremove in class java.util.AbstractMappublic void clear()
clear in interface java.util.Mapclear in class java.util.AbstractMappublic int size()
size in interface java.util.Mapsize in class java.util.AbstractMappublic java.util.Set entrySet()
entrySet in interface java.util.MapentrySet in class java.util.AbstractMap