Package javassist.scopedpool
Class SoftValueHashMap<K,V>
- java.lang.Object
-
- javassist.scopedpool.SoftValueHashMap<K,V>
-
- All Implemented Interfaces:
java.util.Map<K,V>
public class SoftValueHashMap<K,V> extends java.lang.Object implements java.util.Map<K,V>
This Map will remove entries when the value in the map has been cleaned from garbage collection- Version:
$Revision: 1.4 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SoftValueHashMap.SoftValueRef<K,V>
-
Constructor Summary
Constructors Constructor Description SoftValueHashMap()
Constructs a new, emptyWeakHashMap
with the default initial capacity and the default load factor, which is0.75
.SoftValueHashMap(int initialCapacity)
Constructs a new, emptyWeakHashMap
with the given initial capacity and the default load factor, which is0.75
.SoftValueHashMap(int initialCapacity, float loadFactor)
Constructs a new, emptyWeakHashMap
with the given initial capacity and the given load factor.SoftValueHashMap(java.util.Map<K,V> t)
Constructs a newWeakHashMap
with the same mappings as the specifiedMap
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all mappings from this map.boolean
containsKey(java.lang.Object key)
Returnstrue
if this map contains a mapping for the specified key.boolean
containsValue(java.lang.Object arg0)
java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
Returns a set of the mappings contained in this hash table.V
get(java.lang.Object key)
Returns the value to which this map maps the specifiedkey
.boolean
isEmpty()
Returnstrue
if this map contains no key-value mappings.java.util.Set<K>
keySet()
private void
processQueue()
V
put(K key, V value)
Updates this map so that the givenkey
maps to the givenvalue
.void
putAll(java.util.Map<? extends K,? extends V> arg0)
V
remove(java.lang.Object key)
Removes the mapping for the givenkey
from this map, if present.int
size()
Returns the number of key-value mappings in this map.private V
valueOrNull(SoftValueHashMap.SoftValueRef<K,V> rtn)
java.util.Collection<V>
values()
-
-
-
Field Detail
-
hash
private java.util.Map<K,SoftValueHashMap.SoftValueRef<K,V>> hash
-
queue
private java.lang.ref.ReferenceQueue<V> queue
-
-
Constructor Detail
-
SoftValueHashMap
public SoftValueHashMap(int initialCapacity, float loadFactor)
Constructs a new, emptyWeakHashMap
with the given initial capacity and the given load factor.- Parameters:
initialCapacity
- The initial capacity of theWeakHashMap
loadFactor
- The load factor of theWeakHashMap
- Throws:
java.lang.IllegalArgumentException
- If the initial capacity is less than zero, or if the load factor is nonpositive
-
SoftValueHashMap
public SoftValueHashMap(int initialCapacity)
Constructs a new, emptyWeakHashMap
with the given initial capacity and the default load factor, which is0.75
.- Parameters:
initialCapacity
- The initial capacity of theWeakHashMap
- Throws:
java.lang.IllegalArgumentException
- If the initial capacity is less than zero
-
SoftValueHashMap
public SoftValueHashMap()
Constructs a new, emptyWeakHashMap
with the default initial capacity and the default load factor, which is0.75
.
-
SoftValueHashMap
public SoftValueHashMap(java.util.Map<K,V> t)
Constructs a newWeakHashMap
with the same mappings as the specifiedMap
. TheWeakHashMap
is created with an initial capacity of twice the number of mappings in the specified map or 11 (whichever is greater), and a default load factor, which is0.75
.- Parameters:
t
- the map whose mappings are to be placed in this map.
-
-
Method Detail
-
entrySet
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Returns a set of the mappings contained in this hash table.
-
processQueue
private void processQueue()
-
size
public int size()
Returns the number of key-value mappings in this map. Note: In contrast with most implementations of theMap
interface, the time required by this operation is linear in the size of the map.
-
isEmpty
public boolean isEmpty()
Returnstrue
if this map contains no key-value mappings.
-
containsKey
public boolean containsKey(java.lang.Object key)
Returnstrue
if this map contains a mapping for the specified key.
-
get
public V get(java.lang.Object key)
Returns the value to which this map maps the specifiedkey
. If this map does not contain a value for this key, then returnnull
.
-
put
public V put(K key, V value)
Updates this map so that the givenkey
maps to the givenvalue
. If the map previously contained a mapping forkey
then that mapping is replaced and the previous value is returned.
-
remove
public V remove(java.lang.Object key)
Removes the mapping for the givenkey
from this map, if present.
-
clear
public void clear()
Removes all mappings from this map.
-
containsValue
public boolean containsValue(java.lang.Object arg0)
-
values
public java.util.Collection<V> values()
-
valueOrNull
private V valueOrNull(SoftValueHashMap.SoftValueRef<K,V> rtn)
-
-