Package emissary.util
Class CounterSet
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<String,Integer>
-
- emissary.util.CounterSet
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,Integer>
- Direct Known Subclasses:
CharacterCounterSet
public class CounterSet extends HashMap<String,Integer>
A set of named counters that can be easily incremented- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
flexentry
-
Constructor Summary
Constructors Constructor Description CounterSet()
Create a new set of countersCounterSet(boolean flexentry)
Create a new set of countersCounterSet(int initialCapacity)
Create a new set of countersCounterSet(int initialCapacity, float loadFactor)
Create a new set of counters
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
add(String key, int val)
Add value to a countervoid
addKey(String key)
Add a countervoid
addKeys(Collection<String> keys)
Add a collection of countersint
decrement(String key)
Decrement the named CounterSet<String>
getKeys()
Get the names of the current countersint
increment(String key)
Increment the named Counterboolean
isFlexEntry()
Determine flex entry statusvoid
setFlexEntry(boolean val)
Change the flexentry setting-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
-
-
-
Constructor Detail
-
CounterSet
public CounterSet()
Create a new set of counters
-
CounterSet
public CounterSet(boolean flexentry)
Create a new set of counters- Parameters:
flexentry
- whether to allow non initialized keys to be incremented
-
CounterSet
public CounterSet(int initialCapacity)
Create a new set of counters- Parameters:
initialCapacity
- hash map initial capacity
-
CounterSet
public CounterSet(int initialCapacity, float loadFactor)
Create a new set of counters- Parameters:
initialCapacity
- hash map initial capacityloadFactor
- hash map load factor
-
-
Method Detail
-
setFlexEntry
public void setFlexEntry(boolean val)
Change the flexentry setting- Parameters:
val
- the new value
-
isFlexEntry
public boolean isFlexEntry()
Determine flex entry status- Returns:
- true if unknown keys are allowed in add/increment
-
addKey
public void addKey(String key)
Add a counter- Parameters:
key
- the name of the new Counter
-
addKeys
public void addKeys(Collection<String> keys)
Add a collection of counters- Parameters:
keys
- the names of the new counters
-
add
public int add(String key, int val)
Add value to a counter- Parameters:
key
- the name of the counterval
- how much to add- Returns:
- the value of the counter, or -1 if it is not allowed
-
increment
public int increment(String key)
Increment the named Counter- Parameters:
key
- the name of the Counter- Returns:
- the value of the counter, or -1 if it is not allowed
-
decrement
public int decrement(String key)
Decrement the named Counter- Parameters:
key
- the name of the Counter- Returns:
- the value of the counter, or -1 if it is not allowed
-
-