|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.statcvs.util.IntegerMap
public class IntegerMap
Utility class for storing a map from Object
s to
int
s.
This class makes it easy to sort by key or value, and provides
useful features like sum()
, max()
, and
percent calculation.
The keys must be comparable, for example String
s.
Behaviour for null
keys is unspecified.
Constructor Summary | |
---|---|
IntegerMap()
|
Method Summary | |
---|---|
void |
addInt(java.lang.Object key,
int addValue)
Adds an int to the value stored at a key. |
double |
average()
Returns the average of all values in the map. |
boolean |
contains(java.lang.Object key)
Returns true if the map contains a value
for this key. |
void |
dec(java.lang.Object key)
Same as addInt(key, -1) |
int |
get(java.lang.Object key)
Gets a value from the map. |
java.lang.Integer |
getInteger(java.lang.Object key)
Same as get(Object) , but returns an Integer ,
not an int . |
double |
getPercent(java.lang.Object key)
Gets the value stored at a key as a percentage of all values in the map. |
double |
getPercentOfMaximum(java.lang.Object key)
Gets the value stored at a key as a percentage of the maximum value in the map. |
void |
inc(java.lang.Object key)
Same as addInt(key, 1) |
java.util.Iterator |
iteratorSortedByKey()
Returns an iterator on the keys, sorted by key ascending. |
java.util.Iterator |
iteratorSortedByValue()
Returns an iterator on the keys, sorted by values ascending. |
java.util.Iterator |
iteratorSortedByValueReverse()
Returns an iterator on the keys, sorted by values descending. |
java.util.Set |
keySet()
Returns a set view of the keys. |
int |
max()
Returns the maximum value in the map. |
void |
put(java.lang.Object key,
int value)
Puts a value into the map, overwriting any previous value for the same key. |
void |
remove(java.lang.Object key)
Deletes a value from the map. |
int |
size()
Returns the number of key-value pairs stored in the map. |
int |
sum()
Returns the sum of all values in the map. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IntegerMap()
Method Detail |
---|
public void put(java.lang.Object key, int value)
key
- an Object
which is used as key.value
- the int
value to be stored at this key.public int get(java.lang.Object key)
key
- an Object
which is used as key.
public java.lang.Integer getInteger(java.lang.Object key)
get(Object)
, but returns an Integer
,
not an int
.
key
- the key to get the value for
Integer
objectpublic double getPercent(java.lang.Object key)
key
- the key to get the value for
public double getPercentOfMaximum(java.lang.Object key)
key
- the key to get the value for
public void addInt(java.lang.Object key, int addValue)
int
to the value stored at a key.
If no value was stored before at this key, the int
will be stored there.
key
- the key to whose value addValue
should be addedaddValue
- the int
to be addedpublic void inc(java.lang.Object key)
addInt(key, 1)
key
- the key whose value should be increasedpublic void dec(java.lang.Object key)
addInt(key, -1)
key
- the key whose value should be decreasedpublic void remove(java.lang.Object key)
put(key, 0)
. Removing will reduce
the size of the map, putting 0 will not.
key
- the key that should be removedpublic boolean contains(java.lang.Object key)
true
if the map contains a value
for this key.
key
- the key to check for
true
if the key is in the mappublic int size()
public java.util.Set keySet()
Set
view of all keyspublic java.util.Iterator iteratorSortedByKey()
public java.util.Iterator iteratorSortedByValue()
public java.util.Iterator iteratorSortedByValueReverse()
public int sum()
public double average()
public int max()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |