com.notuvy.util
Class SortedCountingSet<T>

java.lang.Object
  extended by com.notuvy.util.SortedCountingSet<T>

public class SortedCountingSet<T>
extends Object

Mainly present a SortedSet, but keep a count of how many times each entry was added. The underlying Collection uses equality check to determine existence User: murali


Constructor Summary
SortedCountingSet()
           
 
Method Summary
 void add(T pKey)
          Add the given element to the collection.
 long countFor(T pKey)
          Give the number of times the given entity exists in the collection.
 void expect(T pKey)
          Initialize and element.
 void expectAll(Collection<T> pKeys)
          Initialize with the given collection of elements.
 Set<T> keySet()
          Give the complete set of entities in this collection.
 long remove(T pKey)
          Remove the given entity if it exists in the collection.
 int size()
          The total number of (unique) entities in the collection.
 String toString()
           
 int total()
          The weighted count of all entities.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SortedCountingSet

public SortedCountingSet()
Method Detail

add

public void add(T pKey)
Add the given element to the collection. If it previously existed, increment its counter. Otherwise create it.

Parameters:
pKey - The entity to add.

expect

public void expect(T pKey)
Initialize and element. Add it to the set, but leave the count at 0.

Parameters:
pKey - The element to initialize.

expectAll

public void expectAll(Collection<T> pKeys)
Initialize with the given collection of elements.

Parameters:
pKeys - A generic collection of elements.

keySet

public Set<T> keySet()
Give the complete set of entities in this collection.

Returns:
The sorted set of entities.

countFor

public long countFor(T pKey)
Give the number of times the given entity exists in the collection.

Parameters:
pKey - The entity to check.
Returns:
Integer count, 0 if the entity does not exist.

remove

public long remove(T pKey)
Remove the given entity if it exists in the collection.

Parameters:
pKey - The entity to remove.
Returns:
Integer count, 0 if the entity does not exist.

size

public int size()
The total number of (unique) entities in the collection.

Returns:
Integer size.

total

public int total()
The weighted count of all entities.

Returns:
Integer total.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013. All Rights Reserved.