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

x33g5p2x  于2022-01-17 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(323)

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

LinkedHashMap.compute介绍

暂无

代码示例

代码示例来源:origin: com.ca.apim.gateway/gateway-export-plugin

@Override
public synchronized Object compute(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
  return propertyMap.compute(key, remappingFunction);
}

代码示例来源:origin: org.jooq/jool

private static <T, X> Collector<T, ?, X> mode0(Function<? super Seq<Tuple2<T, Long>>, ? extends X> transformer) {
  return Collector.of(
    () -> new LinkedHashMap<T, Long>(),
    (m, v) -> m.compute(v, (k1, v1) -> v1 == null ? 1L : v1 + 1L),
    (m1, m2) -> {
      m1.putAll(m2);
      return m1;
    },
    m -> Seq.seq(m).transform(transformer)
  );
}

代码示例来源:origin: opencb/opencga

private void addVariant(Variant variant, String chromosome, long slicePos) {
  List<Variant> list;
  TreeMap<Long, List<Variant>> positionMap = bufferTree.compute(chromosome,
      (s, map) -> map == null ? new TreeMap<>(Long::compareTo) : map);
  list = positionMap.compute(slicePos, (pos, variants) -> variants == null ? new LinkedList<>() : variants);
  if (list.isEmpty()) {
    // New list, new slice
    numSlices++;
  }
  list.add(variant);
  if (currentChromosome == null) {
    // Set first chromosome
    currentChromosome = chromosome;
  }
}

代码示例来源:origin: org.jooq/jool-java-8

private static <T, X> Collector<T, ?, X> mode0(Function<? super Seq<Tuple2<T, Long>>, ? extends X> transformer) {
  return Collector.of(
    () -> new LinkedHashMap<T, Long>(),
    (m, v) -> m.compute(v, (k1, v1) -> v1 == null ? 1L : v1 + 1L),
    (m1, m2) -> {
      m1.putAll(m2);
      return m1;
    },
    m -> Seq.seq(m).transform(transformer)
  );
}

代码示例来源:origin: org.jooq/jool-java-8

/**
 * Get a {@link Collector} that calculates the <code>MODE()</code> function.
 */
public static <T, U> Collector<T, ?, Seq<T>> modeAllBy(Function<? super T, ? extends U> function) {
  return Collector.of(
    () -> new LinkedHashMap<U, List<T>>(),
    (m, t) -> m.compute(function.apply(t), (k, l) -> {
      List<T> result = l != null ? l : new ArrayList<>();
      result.add(t);
      return result;
    }),
    (m1, m2) -> {
      for (Entry<U, List<T>> e : m2.entrySet()) {
        List<T> l = m1.get(e.getKey());
        if (l == null)
          m1.put(e.getKey(), e.getValue());
        else
          l.addAll(e.getValue());
      }
      return m1;
    },
    m -> Seq.seq(m).maxAllBy(t -> t.v2.size()).flatMap(t -> Seq.seq(t.v2))
  );
}

代码示例来源:origin: org.jooq/jool

/**
 * Get a {@link Collector} that calculates the <code>MODE()</code> function.
 */
public static <T, U> Collector<T, ?, Seq<T>> modeAllBy(Function<? super T, ? extends U> function) {
  return Collector.of(
    () -> new LinkedHashMap<U, List<T>>(),
    (m, t) -> m.compute(function.apply(t), (k, l) -> {
      List<T> result = l != null ? l : new ArrayList<>();
      result.add(t);
      return result;
    }),
    (m1, m2) -> {
      for (Entry<U, List<T>> e : m2.entrySet()) {
        List<T> l = m1.get(e.getKey());
        
        if (l == null)
          m1.put(e.getKey(), e.getValue());
        else
          l.addAll(e.getValue());
      }
      return m1;
    },
    m -> Seq.seq(m).maxAllBy(t -> t.v2.size()).flatMap(t -> Seq.seq(t.v2))
  );
}

相关文章