|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
com.taco.data.SoftValueMap
public class SoftValueMap
A map whose values may disappear when no strong references to them exist.
This map does not support null
keys or values! Use
MapUtilities.wrap()
and MapUtilities.unwrap()
if
you want to put null
keys or values in this map.
This class is not synchronized.
Nested Class Summary | |
---|---|
protected class |
SoftValueMap.SoftValue
The values actually put into the storage map. |
protected class |
SoftValueMap.SoftValueEntrySet
A class that acts as the entry set of a SoftValueMap . |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry |
Field Summary | |
---|---|
protected java.util.Set |
_entrySet
The entry set, lazily computed, and cached. |
protected java.util.Map |
_innerMap
The map that provides the storage. |
protected java.lang.ref.ReferenceQueue |
_referenceQueue
Cleared references are put here. |
protected long |
_version
When the map is cleared, all instances of SoftValue
shouldn't cause purgeClearedValues() to remove a new
key/value pair when the soft reference is cleared. |
Constructor Summary | |
---|---|
SoftValueMap()
|
|
SoftValueMap(IMapFactory mapFactory,
int capacity)
|
|
SoftValueMap(IMapFactory mapFactory,
java.util.Map sourceMap)
|
|
SoftValueMap(int capacity)
|
|
SoftValueMap(java.util.Map sourceMap)
|
Method Summary | |
---|---|
void |
clear()
|
java.lang.Object |
clone()
|
boolean |
containsKey(java.lang.Object key)
|
java.util.Set |
entrySet()
|
java.lang.Object |
get(java.lang.Object key)
If key is null , return null ,
since this map does not support null keys. |
static void |
main(java.lang.String[] args)
A simple test program. |
void |
purgeClearedValues()
Remove all associations to values that have been cleared. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
|
java.lang.Object |
remove(java.lang.Object key)
|
int |
size()
|
Methods inherited from class java.util.AbstractMap |
---|
containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.Map _innerMap
protected java.lang.ref.ReferenceQueue _referenceQueue
protected long _version
When the map is cleared, all instances of SoftValue
shouldn't cause purgeClearedValues()
to remove a new
key/value pair when the soft reference is cleared.
To fix these problems, maintain a version number for the map, and
mark instances of SoftValue
with the version number. When
the map is cleared, increment the version number. When
purgeClearedValues()
is called, compare the version
numbers and only remove key/value pairs if the version number matches.
protected transient java.util.Set _entrySet
Constructor Detail |
---|
public SoftValueMap()
public SoftValueMap(int capacity)
public SoftValueMap(java.util.Map sourceMap)
public SoftValueMap(IMapFactory mapFactory, int capacity)
public SoftValueMap(IMapFactory mapFactory, java.util.Map sourceMap)
Method Detail |
---|
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.util.AbstractMap
java.lang.CloneNotSupportedException
public void clear()
clear
in interface java.util.Map
clear
in class java.util.AbstractMap
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
containsKey
in class java.util.AbstractMap
public java.util.Set entrySet()
entrySet
in interface java.util.Map
entrySet
in class java.util.AbstractMap
public java.lang.Object get(java.lang.Object key)
key
is null
, return null
,
since this map does not support null keys. Otherwise, return value
corresponding to key
.
get
in interface java.util.Map
get
in class java.util.AbstractMap
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 int size()
size
in interface java.util.Map
size
in class java.util.AbstractMap
public void purgeClearedValues()
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |