public final class SoftValueMap
extends java.lang.Object
implements java.util.Map
Modifier and Type | Class and Description |
---|---|
(package private) static class |
SoftValueMap.IndexedSoftReference
An extension of WeakReference that can store an index of the bucket it
is associated with.
|
(package private) static class |
SoftValueMap.SoftEntry
The structure used for chaining colliding keys.
|
Modifier and Type | Field and Description |
---|---|
private static boolean |
DEBUG |
private static boolean |
ENQUEUE_FOUND_CLEARED_ENTRIES |
private static java.lang.String |
EOL |
private static boolean |
IDENTITY_OPTIMIZATION |
private SoftValueMap.SoftEntry[] |
m_buckets |
private float |
m_loadFactor |
private int |
m_readAccessCount |
private int |
m_readClearCheckFrequency |
private int |
m_size |
private int |
m_sizeThreshold |
private java.lang.ref.ReferenceQueue |
m_valueReferenceQueue |
private int |
m_writeAccessCount |
private int |
m_writeClearCheckFrequency |
Constructor and Description |
---|
SoftValueMap()
Equivalent to
SoftValueMap(1, 1) . |
SoftValueMap(int initialCapacity,
float loadFactor,
int readClearCheckFrequency,
int writeClearCheckFrequency)
Constructs a SoftValueMap with specified initial capacity, load factor,
and cleared value removal frequencies.
|
SoftValueMap(int readClearCheckFrequency,
int writeClearCheckFrequency)
Equivalent to
SoftValueMap(11, 0.75F, getClearCheckFrequency, putClearCheckFrequency) . |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
(package private) void |
debugDump(java.lang.StringBuffer out) |
java.util.Set |
entrySet() |
boolean |
equals(java.lang.Object rhs) |
java.lang.Object |
get(java.lang.Object key)
Returns the value that is mapped to a given 'key'.
|
int |
hashCode() |
boolean |
isEmpty()
Returns 'false' is this map contains key-value mappings (even if some of
the values may have been cleared already but not removed from the table).
|
java.util.Set |
keySet() |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Updates the table to map 'key' to 'value'.
|
void |
putAll(java.util.Map map) |
private void |
rehash()
Re-hashes the table into a new array of buckets.
|
java.lang.Object |
remove(java.lang.Object key) |
private void |
removeClearedValues()
Removes all entries whose soft values have been cleared _and_ enqueued.
|
int |
size()
Returns the number of key-value mappings in this map.
|
java.lang.String |
toString()
Overrides Object.toString() for debug purposes.
|
java.util.Collection |
values() |
private final java.lang.ref.ReferenceQueue m_valueReferenceQueue
private final float m_loadFactor
private final int m_readClearCheckFrequency
private final int m_writeClearCheckFrequency
private SoftValueMap.SoftEntry[] m_buckets
private int m_size
private int m_sizeThreshold
private int m_readAccessCount
private int m_writeAccessCount
private static final java.lang.String EOL
private static final boolean IDENTITY_OPTIMIZATION
private static final boolean ENQUEUE_FOUND_CLEARED_ENTRIES
private static final boolean DEBUG
public SoftValueMap()
SoftValueMap(1, 1)
.public SoftValueMap(int readClearCheckFrequency, int writeClearCheckFrequency)
SoftValueMap(11, 0.75F, getClearCheckFrequency, putClearCheckFrequency)
.public SoftValueMap(int initialCapacity, float loadFactor, int readClearCheckFrequency, int writeClearCheckFrequency)
initialCapacity
- initial number of hash buckets in the table
[may not be negative, 0 is equivalent to 1].loadFactor
- the load factor to use to determine rehashing points
[must be in (0.0, 1.0] range].readClearCheckFrequency
- specifies that every readClearCheckFrequency
get(java.lang.Object)
should check for and remove all mappings whose soft values
have been cleared by the garbage collector [may not be less than 1].writeClearCheckFrequency
- specifies that every writeClearCheckFrequency
put(java.lang.Object, java.lang.Object)
should check for and remove all mappings whose soft values
have been cleared by the garbage collector [may not be less than 1].public boolean equals(java.lang.Object rhs)
equals
in interface java.util.Map
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Map
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public int size()
NOTE: in contrast with the java.util.WeakHashMap implementation, this is a constant time operation.
size
in interface java.util.Map
public boolean isEmpty()
NOTE: in contrast with the java.util.WeakHashMap implementation, this is a constant time operation.
isEmpty
in interface java.util.Map
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
key
- mapping key [may not be null].public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
key
- mapping key [may not be null].value
- mapping value [may not be null].public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
public void clear()
clear
in interface java.util.Map
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
public void putAll(java.util.Map map)
putAll
in interface java.util.Map
public java.util.Set keySet()
keySet
in interface java.util.Map
public java.util.Set entrySet()
entrySet
in interface java.util.Map
public java.util.Collection values()
values
in interface java.util.Map
void debugDump(java.lang.StringBuffer out)
private void rehash()
private void removeClearedValues()