/** * Returns the current count for the given key, which is 0 if it hasn't * been * seen before. This is a convenient version of {@code get} that casts * and extracts the primitive value. */ public double getCount(Object key) { return getIntCount(key); }
public int getRetrieved(L label) { return foundGuessed.getIntCount(label); }
public int getCorrect(L label) { return correctGuesses.getIntCount(label); }
public int getRelevant(L label) { return foundCorrect.getIntCount(label); }
public int getStateSplitCount(String label) { return stateSplitCounts.getIntCount(label); }
public String getCountAsString(E key) { return Integer.toString(getIntCount(key)); }
/** * Finds and returns the smallest count in this Counter. */ public int min() { int min = Integer.MAX_VALUE; for (E key : map.keySet()) { min = Math.min(min, getIntCount(key)); } return min; }
/** * Finds and returns the largest count in this Counter. */ public int max() { int max = Integer.MIN_VALUE; for (E key : map.keySet()) { max = Math.max(max, getIntCount(key)); } return max; }
/** * Subtracts the counts in the given Counter from the counts in this Counter. * <p> * To copy the values from another Counter rather than subtracting them, use */ public void subtractAll(IntCounter<E> counter) { for (E key : map.keySet()) { decrementCount(key, counter.getIntCount(key)); } }
/** * Returns the set of keys whose counts are at or above the given threshold. * This set may have 0 elements but will not be null. */ public Set<E> keysAbove(int countThreshold) { Set<E> keys = Generics.newHashSet(); for (E key : map.keySet()) { if (getIntCount(key) >= countThreshold) { keys.add(key); } } return keys; }
/** * Returns the set of keys whose counts are at or below the given threshold. * This set may have 0 elements but will not be null. */ public Set<E> keysBelow(int countThreshold) { Set<E> keys = Generics.newHashSet(); for (E key : map.keySet()) { if (getIntCount(key) <= countThreshold) { keys.add(key); } } return keys; }
/** * Returns the set of keys that have exactly the given count. * This set may have 0 elements but will not be null. */ public Set<E> keysAt(int count) { Set<E> keys = Generics.newHashSet(); for (E key : map.keySet()) { if (getIntCount(key) == count) { keys.add(key); } } return keys; }
TagCount(IntCounter<String> tagCounts) { for (String tag : tagCounts.keySet()) { map.put(tag, tagCounts.getIntCount(tag)); } getTagsCache = map.keySet().toArray(new String[map.keySet().size()]); sumCache = calculateSumCache(); }
private static <E> void appendIntCountStats(StringBuilder sb, String label, IntCounter<E> counts) { sb.append(label).append("\n"); List<E> sortedKeys = Counters.toSortedList(counts); int total = counts.totalIntCount(); for (E key:sortedKeys) { int count = counts.getIntCount(key); appendFrac(sb, key.toString(), count, total); sb.append("\n"); } }
private static <E> void appendIntCountStats(StringBuilder sb, String label, IntCounter<E> counts) { sb.append(label).append("\n"); List<E> sortedKeys = Counters.toSortedList(counts); int total = counts.totalIntCount(); for (E key:sortedKeys) { int count = counts.getIntCount(key); appendFrac(sb, key.toString(), count, total); sb.append("\n"); } }
/** * Adds the counts in the given Counter to the counts in this Counter. * <p> * To copy the values from another Counter rather than adding them, use */ public void addAll(IntCounter<E> counter) { for (E key : counter.keySet()) { int count = counter.getIntCount(key); incrementCount(key, count); } }
public void clean() { for (K1 key1 : Generics.newHashSet(map.keySet())) { IntCounter<K2> c = map.get(key1); for (K2 key2 : Generics.newHashSet(c.keySet())) { if (c.getIntCount(key2) == 0) { c.remove(key2); } } if (c.keySet().isEmpty()) { map.remove(key1); } } }
/** */ public int getCount(K1 o1, K2 o2) { IntCounter<K2> c = getCounter(o1); if (c.totalCount() == 0 && !c.keySet().contains(o2)) { return defaultReturnValue(); } return c.getIntCount(o2); }
public void buildStateIndex() { stateIndex = new HashIndex<>(); for (String key : stateSplitCounts.keySet()) { for (int i = 0; i < stateSplitCounts.getIntCount(key); ++i) { stateIndex.addToIndex(state(key, i)); } } }
public IntCounter<Pair<K1, K2>> flatten() { IntCounter<Pair<K1, K2>> result = new IntCounter<>(); result.setDefaultReturnValue(defaultValue); for (K1 key1 : firstKeySet()) { IntCounter<K2> inner = getCounter(key1); for (K2 key2 : inner.keySet()) { result.setCount(new Pair<>(key1, key2), inner.getIntCount(key2)); } } return result; }