/** * This method returns pair of elements with a max value * * @return */ public Pair<F, S> argMax() { Double maxCount = -Double.MAX_VALUE; Pair<F, S> maxKey = null; for (Map.Entry<F, Counter<S>> entry : maps.entrySet()) { Counter<S> counter = entry.getValue(); S localMax = counter.argMax(); if (counter.getCount(localMax) > maxCount || maxKey == null) { maxKey = new Pair<F, S>(entry.getKey(), localMax); maxCount = counter.getCount(localMax); } } return maxKey; }
private String maximalValue(Map<String, Integer> map) { Counter<String> counter = new Counter<>(); for (Map.Entry<String, Integer> entry : map.entrySet()) { counter.incrementCount(entry.getKey(), entry.getValue()); } return counter.argMax(); }
/** * This method returns pair of elements with a max value * * @return */ public Pair<F, S> argMax() { Double maxCount = -Double.MAX_VALUE; Pair<F, S> maxKey = null; for (Map.Entry<F, Counter<S>> entry : maps.entrySet()) { Counter<S> counter = entry.getValue(); S localMax = counter.argMax(); if (counter.getCount(localMax) > maxCount || maxKey == null) { maxKey = new Pair<>(entry.getKey(), localMax); maxCount = counter.getCount(localMax); } } return maxKey; }