java.util.HashMap.compute()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中java.util.HashMap.compute()方法的一些代码示例,展示了HashMap.compute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashMap.compute()方法的具体详情如下:
包路径:java.util.HashMap
类名称:HashMap
方法名:compute

HashMap.compute介绍

暂无

代码示例

代码示例来源:origin: org.apache.lucene/lucene-core

/** 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;
}

代码示例来源:origin: neo4j/neo4j

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;
}

代码示例来源:origin: com.typesafe.play/play_2.11

/**
 * @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);
}

代码示例来源:origin: com.typesafe.play/play_2.11

/**
 * @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);
}

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * @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);
}

代码示例来源:origin: com.typesafe.play/play

/**
 * @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);
}

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * @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);
}

代码示例来源:origin: com.typesafe.play/play

/**
 * @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);
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@Override
public String compute(String key, BiFunction<? super String, ? super String, ? extends String> remappingFunction) {
  return map.compute(key, remappingFunction);
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

@Override public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
  return map.compute(key, remappingFunction);
}

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.lucene

/** 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;
}

代码示例来源:origin: com.microsoft.azure/azure-cosmosdb-gateway

@Override
public V compute(String key, BiFunction<? super String, ? super V, ? extends V> remappingFunction) {
  return super.compute(safeToLower(key), remappingFunction);
}

代码示例来源:origin: stackoverflow.com

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);
}

代码示例来源:origin: stackoverflow.com

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)");
});

代码示例来源:origin: org.graalvm.compiler/compiler

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());
    }
  }
}

代码示例来源:origin: stanford-futuredata/macrobase

candidateCounts.compute(candidate, (k, v) -> v == null ? 1 : v + 1);
foundSupportInTxn = true;

代码示例来源:origin: anba/es6draft

@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)));
}

代码示例来源:origin: Baqend/Orestes-Bloomfilter

countMap.compute(position, (k, v) -> (v == null) ? 1 : (v + 1));

代码示例来源:origin: com.miglayout/miglayout-javafx

transMap.compute(TransType.OPACITY, (transType, oldTrans) -> {
  if (toOpacity != -1) {
    if (oldTrans != null)
  transMap.compute(TransType.BOUNDS, (transType, oldTrans) -> {
    Rectangle2D curBounds = getBounds(node);

相关文章