Package uk.gov.gchq.gaffer.types
Class FreqMap
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<String,Long>
-
- uk.gov.gchq.gaffer.types.FreqMap
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,Long>
public class FreqMap extends HashMap<String,Long>
FreqMap
extendsHashMap
with String keys and Long values, adding an upsert operation.- 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>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Long
getTotal()
void
upsert(String key)
Increments the value of an existing key by 1.void
upsert(String key, Long value)
Adds a new key and value to the map if the key is not already there.-
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
-
-
-
-
Method Detail
-
upsert
public void upsert(String key, Long value)
Adds a new key and value to the map if the key is not already there. If the key is already there, the value supplied is added to the existing value for the key and the result is inserted into the map.- Parameters:
key
- The key in the map to increment or insert.value
- The value to increment by or initialise to.
-
upsert
public void upsert(String key)
Increments the value of an existing key by 1. If the key doesn't exist, initialises the value to 1.- Parameters:
key
- The key to increment or insert.
-
getTotal
public Long getTotal()
- Returns:
- the total frequency.
-
-