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() |
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
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.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