Top Description Inners Fields Constructors Methods
javassist.scopedpool

public Class SoftValueHashMap<K, V>

extends Object
implements Map<K, V>
Class Inheritance
All Implemented Interfaces
java.util.Map
Imports
java.lang.ref.ReferenceQueue, .SoftReference, java.util.AbstractMap.SimpleImmutableEntry, .ArrayList, .Collection, .HashSet, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap

This Map will remove entries when the value in the map has been cleaned from garbage collection
Author
Bill Burke
Version
Revision: 1.4

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private Map<K, SoftValueHashMap.SoftValueRef<K, V>>
private ReferenceQueue<V>

Constructor Summary

AccessConstructor and Description
public
SoftValueHashMap(int
The initial capacity of the WeakHashMap
initialCapacity
,
float
The load factor of the WeakHashMap
loadFactor
)

Constructs a new, empty WeakHashMap with the given initial capacity and the given load factor.

public
SoftValueHashMap(int
The initial capacity of the WeakHashMap
initialCapacity
)

Constructs a new, empty WeakHashMap with the given initial capacity and the default load factor, which is 0.75.

public
SoftValueHashMap()

Constructs a new, empty WeakHashMap with the default initial capacity and the default load factor, which is 0.75.

public
SoftValueHashMap(Map<K, V>
the map whose mappings are to be placed in this map.
t
)

Constructs a new WeakHashMap with the same mappings as the specified Map.

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements java.util.Map.clear.

Removes all mappings from this map.

public boolean
containsKey(Object
The key whose presence in this map is to be tested.
key
)

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean
containsValue(Object
value whose presence in this map is to be tested
arg0
)

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

public Set<Map.Entry<K, V>>
entrySet()

Implements java.util.Map.entrySet.

Returns a set of the mappings contained in this hash table.

public V
get(Object
The key whose associated value, if any, is to be returned.
key
)

Implements java.util.Map.get.

Returns the value to which this map maps the specified key.

public boolean
isEmpty()

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

public Set<K>
keySet()

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

private void
public V

Returns:

The previous value to which this key was mapped, or null if if there was no mapping for the key
put
(K
The key that is to be mapped to the given value
key
,
V
The value to which the given key is to be mapped
value
)

Implements java.util.Map.put.

Updates this map so that the given key maps to the given value.

public void
putAll(Map<? extends K, ? extends V>
mappings to be stored in this map
arg0
)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).

public V

Returns:

The value to which this key was mapped, or null if there was no mapping for the key.
remove
(Object
The key whose mapping is to be removed.
key
)

Implements java.util.Map.remove.

Removes the mapping for the given key from this map, if present.

public int
size()

Implements java.util.Map.size.

Returns the number of key-value mappings in this map

Note

In contrast with most implementations of the Map interface, the time required by this operation is linear in the size of the map.

private V
public Collection<V>
values()

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hashback to summary
private Map<K, SoftValueHashMap.SoftValueRef<K, V>> hash
queueback to summary
private ReferenceQueue<V> queue

Constructor Detail

SoftValueHashMapback to summary
public SoftValueHashMap(int initialCapacity, float loadFactor)

Constructs a new, empty WeakHashMap with the given initial capacity and the given load factor.

Parameters
initialCapacity:int

The initial capacity of the WeakHashMap

loadFactor:float

The load factor of the WeakHashMap

Exceptions
IllegalArgumentException:
If the initial capacity is less than zero, or if the load factor is nonpositive
SoftValueHashMapback to summary
public SoftValueHashMap(int initialCapacity)

Constructs a new, empty WeakHashMap with the given initial capacity and the default load factor, which is 0.75.

Parameters
initialCapacity:int

The initial capacity of the WeakHashMap

Exceptions
IllegalArgumentException:
If the initial capacity is less than zero
SoftValueHashMapback to summary
public SoftValueHashMap()

Constructs a new, empty WeakHashMap with the default initial capacity and the default load factor, which is 0.75.

SoftValueHashMapback to summary
public SoftValueHashMap(Map<K, V> t)

Constructs a new WeakHashMap with the same mappings as the specified Map. The WeakHashMap 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 is 0.75.

Parameters
t:Map<K, V>

the map whose mappings are to be placed in this map.

Method Detail

clearback to summary
public void clear()

Implements java.util.Map.clear.

Removes all mappings from this map.

Annotations
@Override
containsKeyback to summary
public boolean containsKey(Object key)

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

Parameters
key:Object

The key whose presence in this map is to be tested.

Returns:boolean

Doc from java.util.Map.containsKey.

true if this map contains a mapping for the specified key

Annotations
@Override
containsValueback to summary
public boolean containsValue(Object arg0)

Implements java.util.Map.containsValue.

Doc from java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that Objects.equals(value, v). This operation will probably require time linear in the map size for most implementations of the Map interface.

Parameters
arg0:Object

value whose presence in this map is to be tested

Returns:boolean

true if this map maps one or more keys to the specified value

Annotations
@Override
entrySetback to summary
public Set<Map.Entry<K, V>> entrySet()

Implements java.util.Map.entrySet.

Returns a set of the mappings contained in this hash table.

Returns:Set<Map.Entry<K, V>>

Doc from java.util.Map.entrySet.

a set view of the mappings contained in this map

Annotations
@Override
getback to summary
public V get(Object key)

Implements java.util.Map.get.

Returns the value to which this map maps the specified key. If this map does not contain a value for this key, then return null.

Parameters
key:Object

The key whose associated value, if any, is to be returned.

Returns:V

Doc from java.util.Map.get.

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

Returns:boolean

Doc from java.util.Map.isEmpty.

true if this map contains no key-value mappings

Annotations
@Override
keySetback to summary
public Set<K> keySet()

Implements java.util.Map.keySet.

Doc from java.util.Map.keySet.

Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Returns:Set<K>

a set view of the keys contained in this map

Annotations
@Override
processQueueback to summary
private void processQueue()
putback to summary
public V put(K key, V value)

Implements java.util.Map.put.

Updates this map so that the given key maps to the given value. If the map previously contained a mapping for key then that mapping is replaced and the previous value is returned.

Parameters
key:K

The key that is to be mapped to the given value

value:V

The value to which the given key is to be mapped

Returns:V

The previous value to which this key was mapped, or null if if there was no mapping for the key

Annotations
@Override
putAllback to summary
public void putAll(Map<? extends K, ? extends V> arg0)

Implements java.util.Map.putAll.

Doc from java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. If the specified map has a defined encounter order, processing of its mappings generally occurs in that order.

Parameters
arg0:Map<? extends K, ? extends V>

mappings to be stored in this map

Annotations
@Override
removeback to summary
public V remove(Object key)

Implements java.util.Map.remove.

Removes the mapping for the given key from this map, if present.

Parameters
key:Object

The key whose mapping is to be removed.

Returns:V

The value to which this key was mapped, or null if there was no mapping for the key.

Annotations
@Override
sizeback to summary
public int size()

Implements java.util.Map.size.

Returns the number of key-value mappings in this map

Note

In contrast with most implementations of the Map interface, the time required by this operation is linear in the size of the map.

Returns:int

Doc from java.util.Map.size.

the number of key-value mappings in this map

Annotations
@Override
valueOrNullback to summary
private V valueOrNull(SoftValueHashMap.SoftValueRef<K, V> rtn)
valuesback to summary
public Collection<V> values()

Implements java.util.Map.values.

Doc from java.util.Map.values.

Returns a Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Collection<V>

a collection view of the values contained in this map

Annotations
@Override
javassist.scopedpool back to summary

private Class SoftValueHashMap.SoftValueRef<K, V>

extends SoftReference<V>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public K

Constructor Summary

AccessConstructor and Description
private
SoftValueRef(K key, V val, ReferenceQueue<V> q)

Method Summary

Modifier and TypeMethod and Description
private static <K, V> SoftValueHashMap.SoftValueRef<K, V>
create(K key, V val, ReferenceQueue<V> q)

Inherited from java.lang.ref.SoftReference:
get

Field Detail

keyback to summary
public K key

Constructor Detail

SoftValueRefback to summary
private SoftValueRef(K key, V val, ReferenceQueue<V> q)

Method Detail

createback to summary
private static <K, V> SoftValueHashMap.SoftValueRef<K, V> create(K key, V val, ReferenceQueue<V> q)