/** find repeating terms and assign them ordinal values */ private LinkedHashMap<Term,Integer> repeatingTerms() { LinkedHashMap<Term,Integer> tord = new LinkedHashMap<>(); HashMap<Term,Integer> tcnt = new HashMap<>(); for (PhrasePositions pp : phrasePositions) { for (Term t : pp.terms) { Integer cnt = tcnt.compute(t, (key, old) -> old == null ? 1 : 1 + old); if (cnt==2) { tord.put(t,tord.size()); } } } return tord; }
static Map<String,Integer> count( org.neo4j.internal.kernel.api.Transaction transaction, RelationshipTraversalCursor relationship ) throws KernelException { HashMap<String,Integer> counts = new HashMap<>(); while ( relationship.next() ) { String key = computeKey( transaction, relationship ); counts.compute( key, ( k, value ) -> value == null ? 1 : value + 1 ); } return counts; }
/** * @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases. */ @Deprecated @Override public String compute(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) { return super.compute(key, remappingFunction); }
/** * @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases. */ @Deprecated @Override public String compute(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) { return super.compute(key, remappingFunction); }
/** * @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases. */ @Deprecated @Override public String compute(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) { return super.compute(key, remappingFunction); }
/** * @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases. */ @Deprecated @Override public String compute(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) { return super.compute(key, remappingFunction); }
/** * @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases. */ @Deprecated @Override public String compute(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) { return super.compute(key, remappingFunction); }
/** * @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases. */ @Deprecated @Override public String compute(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) { return super.compute(key, remappingFunction); }
@Override public String compute(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) { return map.compute(key, remappingFunction); }
@Override public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { return map.compute(key, remappingFunction); }
final HashMap<Integer, Integer> map = new HashMap<Integer,Integer>(); map.put(123, 456); System.out.println(map); final int x = 234; final BiFunction<? super Integer, ? super Integer, ? extends Integer> f = (k, v) -> v == null ? x : Math.min(v, x); map.compute(123, f); map.compute(999, f); System.out.println(map);
/** find repeating terms and assign them ordinal values */ private LinkedHashMap<Term,Integer> repeatingTerms() { LinkedHashMap<Term,Integer> tord = new LinkedHashMap<>(); HashMap<Term,Integer> tcnt = new HashMap<>(); for (PhrasePositions pp : phrasePositions) { for (Term t : pp.terms) { Integer cnt = tcnt.compute(t, (key, old) -> old == null ? 1 : 1 + old); if (cnt==2) { tord.put(t,tord.size()); } } } return tord; }
@Override public V compute(String key, BiFunction<? super String, ? super V, ? extends V> remappingFunction) { return super.compute(safeToLower(key), remappingFunction); }
public static void main(final String[] arrg) { final HashMap<Integer, Integer> map = new HashMap<Integer,Integer>(); map.put(123, 456); System.out.println(map); map.compute(123, f(345)); map.compute(123, f(99999)); map.compute(999, f(888)); System.out.println(map); } static BiFunction<? super Integer, ? super Integer, ? extends Integer> f(final int x) { return (k, v) -> v == null ? x : Math.min(v, x); }
HashMap<Integer, Integer> num_freq = new HashMap<>(); String input = "10:05"; // Example input char[] input_chars = input.toCharArray(); for(char c : input_chars){ // Accept only characters that are digits if(Character.isDigit(c)){ // Grabs digit from character int num = Character.digit(c, 10); // Put 1 into map if no entry exists, else increment existing value num_freq.compute(num, (k_num, freq) -> freq == null ? 1 : freq + 1); } } // Print result out num_freq.forEach((num, freq) -> { System.out.println("Digit " + num + " appears " + freq + " time(s)"); });
public void accept(Collection<T> elements) { /* First compute the histogram. */ HashMap<T, Integer> histogram = new HashMap<>(); for (T e : elements) { histogram.compute(e, (key, count) -> (count == null) ? 1 : count + 1); } /* Then create the summary statistics. */ for (Map.Entry<T, Integer> entry : histogram.entrySet()) { T element = entry.getKey(); Integer count = entry.getValue(); types.computeIfAbsent(element, key -> new IntSummaryStatistics()).accept(count.intValue()); } } }
candidateCounts.compute(candidate, (k, v) -> v == null ? 1 : v + 1); foundSupportInTxn = true;
@Function(name = "count", arity = 0) public void count(ExecutionContext cx, Object label) { String message, key; if (Type.isUndefined(label)) { StackTraceElement frame = StackTraces.stackTraceStream(new Throwable()).findFirst().get(); key = frameToString(frame); message = "default"; } else { key = ToFlatString(cx, label); message = key; } labels.compute(key, (k, c) -> c != null ? c + 1 : 1); println(cx, LogLevel.Info, String.format("%s: %d", message, labels.get(key))); }
countMap.compute(position, (k, v) -> (v == null) ? 1 : (v + 1));