|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
org.ka2ddo.util.SoftCache
public class SoftCache
This is a HashMap based on using SoftReferences to the values. If a SoftReference becomes cleared by garbage-collection, the corresponding key is removed from the map. It uses conventional linked lists for the entries in the map, and is modifiable.
The SoftCache does not maintain any strong/hard references to any of its entry values. To prevent an entry in the SoftCache from being reclaimed by garbage-collection, external code must maintain a hard reference to the values object in question.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Constructor Summary | |
---|---|
SoftCache()
Constructs an empty SoftCache with the default initial capacity (16) and the default load factor (0.75). |
|
SoftCache(int initialCapacity)
Constructs an empty SoftCache with the specified initial capacity and the default load factor (0.75). |
|
SoftCache(int initialCapacity,
float loadFactor)
Constructs an empty SoftCache with the specified initial capacity and load factor. |
|
SoftCache(java.util.Map m)
Constructs a new SoftCache with the same mappings as the specified Map. |
Method Summary | |
---|---|
void |
clear()
Removes all mappings from this map (optional operation). |
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified key. |
java.util.Set |
entrySet()
Returns a set view of the mappings contained in this map. |
java.lang.Object |
get(java.lang.Object key)
Returns the value to which this map maps the specified key. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Associates the specified value with the specified key in this map (optional operation). |
java.lang.Object |
remove(java.lang.Object key)
Removes the mapping for this key from this map if present. |
int |
size()
Returns the number of key-value mappings in this map. |
Methods inherited from class java.util.AbstractMap |
---|
clone, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SoftCache(int initialCapacity, float loadFactor)
initialCapacity
- The initial capacity.loadFactor
- The load factor.
java.lang.IllegalArgumentException
- if the initial capacity is negative
or the load factor is nonpositive.public SoftCache(int initialCapacity)
initialCapacity
- the initial capacity.
java.lang.IllegalArgumentException
- if the initial capacity is negative.public SoftCache()
public SoftCache(java.util.Map m)
m
- the map whose mappings are to be placed in this map.
java.lang.NullPointerException
- if the specified map is null.Method Detail |
---|
public java.util.Set entrySet()
entrySet
in interface java.util.Map
entrySet
in class java.util.AbstractMap
public int size()
This implementation returns entrySet().size().
size
in interface java.util.Map
size
in class java.util.AbstractMap
public void clear()
clear
in interface java.util.Map
clear
in class java.util.AbstractMap
public boolean containsKey(java.lang.Object key)
This implementation iterates over entrySet() searching for an entry with the specified key. If such an entry is found, true is returned. If the iteration terminates without finding such an entry, false is returned. Note that this implementation requires linear time in the size of the map; many implementations will override this method.
containsKey
in interface java.util.Map
containsKey
in class java.util.AbstractMap
key
- key whose presence in this map is to be tested.
java.lang.NullPointerException
- key is null and this map does not
not permit null keys.public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
get
in class java.util.AbstractMap
key
- key whose associated value is to be returned.
java.lang.NullPointerException
- if the key is null and this map
does not not permit null keys.containsKey(Object)
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
remove
in class java.util.AbstractMap
key
- key whose mapping is to be removed from the map.
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
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
java.lang.NullPointerException
- this map does not permit null
keys or values, and the specified key or value is
null.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |