|
|||||||||
| 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<E,Counter>
com.aliasi.util.ObjectToCounterMap<E>
E - the type of objects used as keys for the mappublic class ObjectToCounterMap<E>
An ObjectToCounterMap maintains a mapping from objects
to integer counters, which may be incremented or set. Objects not
in the underlying map are assumed to have count 0, so
that incrementing an object that is not mapped sets it to the
increment amount.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.util.AbstractMap |
|---|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V> |
| Constructor Summary | |
|---|---|
ObjectToCounterMap()
Construct an object to counter mapping. |
|
ObjectToCounterMap(int initialSize)
Construct an object to counter mapping with the specified initial size. |
|
| Method Summary | |
|---|---|
Comparator<E> |
countComparator()
Returns a CountComparator that compares objects
based on their counts in this object to counter map. |
int |
getCount(E key)
Returns the current count value for the specified key. |
void |
increment(E key)
Increment the value of the specified key by 1. |
void |
increment(E key,
int n)
Increment the value of the specified key by the specified amount. |
Object[] |
keysOrderedByCount()
Returns the array of keys for this object to counter map sorted in decreasing order of their value counts. |
List<E> |
keysOrderedByCountList()
Returns a list of keys for this object to counter map sorted in descending order of count. |
void |
prune(int minCount)
Removes all entries in this counter that have less than the specified minimum count. |
void |
set(E key,
int n)
Sets the value of the specified key to be the specified amount. |
String |
toString()
Returns a string representation of this map. |
| Methods inherited from class java.util.HashMap |
|---|
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values |
| Methods inherited from class java.util.AbstractMap |
|---|
equals, hashCode |
| 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 ObjectToCounterMap()
public ObjectToCounterMap(int initialSize)
initialSize - Initial size of map.| Method Detail |
|---|
public void increment(E key)
1.
Removes the key from the underlying map if the value after
incrementing is 0. Sets the value of the key to
1 if it is not currently set in the underlying
map.
key - Object whose count is incremented by 1
public void increment(E key,
int n)
0, the key is
removed from the map.
key - Object whose count is incremented by the specified
amount.n - Amount to increment the object by.
public void set(E key,
int n)
0, the key is removed from the mapping.
key - Object whose count is incremented by the specified
amount.n - Amount to increment the object by.public int getCount(E key)
0.
public String toString()
toString in class AbstractMap<E,Counter>public List<E> keysOrderedByCountList()
public Object[] keysOrderedByCount()
public void prune(int minCount)
minCount - Minimum count of objects to retain.public Comparator<E> countComparator()
CountComparator that compares objects
based on their counts in this object to counter map. It first
compares objects based on their count, and if the counts are
the same and the objects are comparable, on the objects
themselves. Thus compare(obj1,obj2) method will
not be consistent with equals (see Comparable)
unless the set of keys has a natural ordering that is
consistent with equals. This inconsistency with
equals is tolerable in cases where the comparator
is used for sorting, as in Arrays.sort(Object[],Comparator), but not for
backing a sorted collection such as TreeMap
or TreeSet.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||