|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.HashMap<T,java.lang.Integer>
com.googlecode.whatswrong.javautils.Counter<T>
public class Counter<T>
A Counter counts objects of class T.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Constructor Summary | |
---|---|
Counter()
|
Method Summary | |
---|---|
java.lang.Integer |
get(java.lang.Object o)
Gets the count of object o. |
int |
getMaximum()
Gets the maximum count of all objects in the counter. |
void |
increment(T value,
int howmuch)
Increments the count for the given object by howmuch |
static Counter<java.lang.String> |
loadFromFile(java.io.File file)
Loads counts from a column separated file where row looks like "value count". |
void |
save(java.io.OutputStream outputStream)
Saves the counts to column separated text file with format "value count" in each row. |
java.util.List<java.util.Map.Entry<T,java.lang.Integer>> |
sorted(boolean descending)
Sort map entries by counts. |
Methods inherited from class java.util.HashMap |
---|
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, put, putAll, remove, size, values |
Methods inherited from class java.util.AbstractMap |
---|
equals, hashCode, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals, hashCode |
Constructor Detail |
---|
public Counter()
Method Detail |
---|
public java.lang.Integer get(java.lang.Object o)
get
in interface java.util.Map<T,java.lang.Integer>
get
in class java.util.HashMap<T,java.lang.Integer>
o
- the object to get the count of.
public void increment(T value, int howmuch)
howmuch
value
- the object to increment the count for.howmuch
- how much the count should be incremented.public static Counter<java.lang.String> loadFromFile(java.io.File file) throws java.io.IOException
file
- the file to load from.
java.io.IOException
- if I/O goes wrong.public java.util.List<java.util.Map.Entry<T,java.lang.Integer>> sorted(boolean descending)
descending
- the list start with the highest or lowest count.
public void save(java.io.OutputStream outputStream)
outputStream
- the output stream to print to.public int getMaximum()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |