package alg; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; public class Common { public static void updateMap(Map map, K o) { // if not in map AtomicLong r = map.putIfAbsent(o, new AtomicLong(1)); // else if (r != null) map.get(o).incrementAndGet(); } }