Increment a Counter Using a Map

Increment an Integer Counter Using a Map<String, Integer>.

Javadoc available at https://www.javatapas.com/docs/javatapas/util/IncrementCounterMap.html


public static void incrementCounterMap(Map<String, Integer> counterMap, String key){incrementCounterMap(counterMap, key, 1);}

public static void incrementCounterMap(Map<String, Integer> counterMap, String key, int incValue){incrementCounterMap(counterMap, key, 0, incValue);}

public static void incrementCounterMap(Map<String, Integer> counterMap, String key, int startValue, int incValue){

	Integer currentValue = counterMap.get(key);
	if (currentValue == null){currentValue = startValue;}
	int newValue = currentValue + incValue;
	counterMap.put(key, newValue);

}