Class RefCountedMap<K,V>

java.lang.Object
com.espertech.esper.common.internal.collection.RefCountedMap<K,V>

public class RefCountedMap<K,V> extends 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

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear out the collection.
    boolean
    Decreases the reference count for a given key by one.
    get(K key)
    Get the value for a given key, returning null if the key was not found.
    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 Details

    • RefCountedMap

      public RefCountedMap()
      Constructor.
  • Method Details

    • 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.