TUM CCSM Commons

edu.tum.cs.commons.collections
Class CounterSet<E>

java.lang.Object
  extended by edu.tum.cs.commons.collections.CounterSet<E>
Direct Known Subclasses:
SortedCounterSet

public class CounterSet<E>
extends java.lang.Object

This class manages a set of counters (i.e. is a mapping from some key objects to integers). As the implementation is based on hash maps, key objects must provide suitable hash keys.

Version:
$Rev: 26268 $
Author:
Florian Deissenboeck, $Author: juergens $
Rating:
GREEN Hash: FE6470D850FAD6E9A77E4059CD0692C5

Field Summary
protected  java.util.Map<E,java.lang.Integer> map
          The underlying map.
protected  int total
          Stores total value.
 
Constructor Summary
CounterSet()
           
 
Method Summary
 boolean contains(E key)
          Checks if an element is stored in the array.
 UnmodifiableSet<E> getKeys()
          Returns the set of all elements used a keys for counters.
 int getTotal()
          Get total sum of all elements.
 int getValue(E key)
          Get the value for an element.
 void inc(E key)
          Same as inc(key, 1).
 void inc(E key, int increment)
          Add the given increment to an element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

protected final java.util.Map<E,java.lang.Integer> map
The underlying map.


total

protected int total
Stores total value.

Constructor Detail

CounterSet

public CounterSet()
Method Detail

inc

public void inc(E key,
                int increment)
Add the given increment to an element. If the element was not present before, it is interpreted as if it was present with value 0.

Parameters:
key - the key of the counter to increment.
increment - the increment.

inc

public void inc(E key)
Same as inc(key, 1).

See Also:
inc(Object, int)

contains

public boolean contains(E key)
Checks if an element is stored in the array.


getValue

public int getValue(E key)
Get the value for an element. If the the element is not stored in the counter 0 is returned.


getKeys

public UnmodifiableSet<E> getKeys()
Returns the set of all elements used a keys for counters.


getTotal

public int getTotal()
Get total sum of all elements.


TUM CCSM Commons

TUM CCSM Commons - 2.7