Class RefCountedMap<K,V>
java.lang.Object
com.espertech.esper.common.internal.collection.RefCountedMap<K,V>
Reference-counting map based on a HashMap implementation that stores as a value a pair of value and reference counter.
The class provides a reference method that takes a key
and increments the reference count for the key. It also provides a de-reference method that takes a key and
decrements the reference count for the key, and removes the key if the reference count reached zero.
Null values are not allowed as keys.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear out the collection.boolean
dereference
(K key) Decreases the reference count for a given key by one.Get the value for a given key, returning null if the key was not found.Add and key and value with a reference count as one.void
Increase the reference count for a given key by one.
-
Constructor Details
-
RefCountedMap
public RefCountedMap()Constructor.
-
-
Method Details
-
put
Add and key and value with a reference count as one. If the key already exists, throw an exception. Clients should use the "get" method first to check if the key exists.- Parameters:
key
- to addvalue
- to add- Returns:
- value added
-
get
Get the value for a given key, returning null if the key was not found.- Parameters:
key
- is the key to look up and return the value for- Returns:
- value for key, or null if key was not found
-
reference
Increase the reference count for a given key by one. Throws an IllegalArgumentException if the key was not found.- Parameters:
key
- is the key to increase the ref count for
-
dereference
Decreases the reference count for a given key by one. Returns true if the reference count reaches zero. Removes the key from the collection when the reference count reaches zero. Throw an IllegalArgumentException if the key is not found.- Parameters:
key
- to de-reference- Returns:
- true to indicate the reference count reached zero, false to indicate more references to the key exist.
-
clear
public void clear()Clear out the collection.
-