com.espertech.esper.collection
Class RefCountedSet<K>

java.lang.Object
  extended by com.espertech.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.
RefCountedSet(java.util.Map<K,java.lang.Integer> refSet, int numValues)
           
 
Method Summary
 boolean add(K key)
          Add a key to the set.
 void add(K key, int numReferences)
          Add a key to the set with the given number of references.
 void clear()
          Clear out the collection.
 java.util.Iterator<java.util.Map.Entry<K,java.lang.Integer>> entryIterator()
          Returns an iterator over the entry set.
 int getNumValues()
           
 java.util.Map<K,java.lang.Integer> getRefSet()
           
 java.util.Iterator<K> keyIterator()
          Returns a key iterator.
 boolean remove(K key)
          Removed a key to the set.
 boolean removeAll(K key)
          Remove a key from the set regardless of the number of references.
 void setNumValues(int numValues)
           
 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.


RefCountedSet

public RefCountedSet(java.util.Map<K,java.lang.Integer> refSet,
                     int numValues)
Method Detail

clear

public void clear()
Clear out the collection.


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

add

public void add(K key,
                int numReferences)
Add a key to the set with the given number of references.

Parameters:
key - to add
numReferences - initial number of references

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

removeAll

public boolean removeAll(K key)
Remove a key from the set regardless of the number of references.

Parameters:
key - to add
Returns:
true if the key is removed, false if the key was not found
Throws:
java.lang.IllegalStateException - if 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

keyIterator

public java.util.Iterator<K> keyIterator()
Returns a key iterator.

Returns:
key iterator

size

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

Returns:
size

getRefSet

public java.util.Map<K,java.lang.Integer> getRefSet()

getNumValues

public int getNumValues()

setNumValues

public void setNumValues(int numValues)

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