net.esper.collection
Class RefCountedSet<K>

java.lang.Object
  extended by net.esper.collection.RefCountedSet<K>

public class RefCountedSet<K>
extends java.lang.Object

reference-counting set based on a HashMap implementation that stores keys and a reference counter for each unique key value. Each time the same key is added, the reference counter increases. Each time a key is removed, the reference counter decreases.


Constructor Summary
RefCountedSet()
          Constructor.
 
Method Summary
 boolean add(K key)
          Add a key to the set.
 java.util.Iterator<java.util.Map.Entry<K,java.lang.Integer>> entryIterator()
          Returns an iterator over the entry set.
 boolean remove(K key)
          Removed a key to the set.
 int size()
          Returns the number of values in the collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RefCountedSet

public RefCountedSet()
Constructor.

Method Detail

add

public boolean add(K key)
Add a key to the set. Add with a reference count of one if the key didn't exist in the set. Increase the reference count by one if the key already exists. Return true if this is the first time the key was encountered, or false if key is already in set.

Parameters:
key - to add
Returns:
true if the key is not in the set already, false if the key is already in the set

remove

public boolean remove(K key)
Removed a key to the set. Removes the key if the reference count is one. Decreases the reference count by one if the reference count is more then one. Return true if the reference count was one and the key thus removed, or false if key is stays in set.

Parameters:
key - to add
Returns:
true if the key is removed, false if it stays in the set
Throws:
java.lang.IllegalStateException - is a key is removed that wasn't added to the map

entryIterator

public java.util.Iterator<java.util.Map.Entry<K,java.lang.Integer>> entryIterator()
Returns an iterator over the entry set.

Returns:
entry set iterator

size

public int size()
Returns the number of values in the collection.

Returns:
size