com.espertech.esper.collection
Class RefCountedMap<K,V>

java.lang.Object
  extended by com.espertech.esper.collection.RefCountedMap<K,V>

public class RefCountedMap<K,V>
extends java.lang.Object

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
RefCountedMap()
          Constructor.
 
Method Summary
 void clear()
          Clear out the collection.
 boolean dereference(K key)
          Decreases the reference count for a given key by one.
 V get(K key)
          Get the value for a given key, returning null if the key was not found.
 V put(K key, V value)
          Add and key and value with a reference count as one.
 void reference(K key)
          Increase the reference count for a given key by one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RefCountedMap

public RefCountedMap()
Constructor.

Method Detail

put

public V put(K key,
             V value)
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 add
value - to add
Returns:
value added

get

public V get(K key)
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

public void reference(K key)
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

public boolean dereference(K key)
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.


© 2006-2015 EsperTech Inc.
All rights reserved.
Visit us at espertech.com