|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.util.Counter
A utility class that can keep counts associated with objects. The most common use is to count occurrences of Strings or some other object type, but you can also use it to keep track of times or other numbers, per object.
The counter is implemented as a hashtable, where the keys are the objects, and the values are the counts for those objects.
Nested Class Summary | |
static class |
Counter.Count
Keeps track of an object and its count. |
Constructor Summary | |
Counter()
Constructs a new Counter |
Method Summary | |
void |
clear()
Clears out all the counts - removes all keys from the table. |
void |
decrementCount(java.lang.Object obj)
Decrements the count for this object. |
void |
decrementCount(java.lang.Object obj,
int amount)
Decrements the count for an object by the specified amount. |
java.lang.String |
dumpValues()
Returns a printout of the (sorted) values in the list. |
java.lang.String |
dumpValues(int max)
Returns a printout of the (sorted) values in the list. |
int |
getCount(java.lang.Object obj)
Returns the count for a particular object. |
java.util.List |
getCounts()
Returns a list of the counts we've accumulated so far. |
java.util.List |
getSortedCounts()
Returns a list, sorted by count, from highest to lowest, of the keys in the data structure. |
int |
getTotalCount()
Returns the sum of all the counts in this Counter. |
void |
incrementCount(java.lang.Object obj)
Increments the count for this object. |
void |
incrementCount(java.lang.Object obj,
int amount)
Increments the count for this object by the desired amount. |
static void |
main(java.lang.String[] args)
Tests the data structure. |
void |
setCount(java.lang.Object obj,
int total)
Sets the count directly for this object. |
int |
size()
Returns the number of distinct keys in the table. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Counter()
Method Detail |
public void incrementCount(java.lang.Object obj)
public void incrementCount(java.lang.Object obj, int amount)
obj
- the objectamount
- the amount to add to the countpublic void decrementCount(java.lang.Object obj)
public void decrementCount(java.lang.Object obj, int amount)
obj
- the objectamount
- the amount to subtractpublic int getCount(java.lang.Object obj)
public void setCount(java.lang.Object obj, int total)
public java.util.List getCounts()
public java.util.List getSortedCounts()
public java.lang.String dumpValues()
public java.lang.String dumpValues(int max)
max
- the max number of values to print.public void clear()
public int getTotalCount()
public int size()
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |