java.util.stream.Collectors.summingDouble()方法的使用及代码示例

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

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

Collectors.summingDouble介绍

暂无

代码示例

代码示例来源:origin: confluentinc/ksql

public static Collection<Double> currentConsumptionRateByQuery() {
 return collectorMap.values()
   .stream()
   .filter(collector -> collector.getGroupId() != null)
   .collect(
     Collectors.groupingBy(
      MetricCollector::getGroupId,
      Collectors.summingDouble(
        m -> m.aggregateStat(ConsumerCollector.CONSUMER_MESSAGES_PER_SEC, false)
      )
    )
   )
   .values();
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<String, Double> sumByCategory_serial_lazy_jdk()
{
  return this.positions.getJdkPositions().stream().collect(
      Collectors.groupingBy(
          Position::getCategory,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<Product, Double> sumByProduct_serial_lazy_jdk()
{
  return this.positions.getJdkPositions().stream().collect(
      Collectors.groupingBy(
          Position::getProduct,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<Account, Double> sumByAccount_serial_lazy_jdk()
{
  return this.positions.getJdkPositions().stream().collect(
      Collectors.groupingBy(
          Position::getAccount,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: RichardWarburton/java-8-lambdas-exercises

@GenerateMicroBenchmark
  // BEGIN serial
public Map<Integer, Double> serialDiceRolls() {
  double fraction = 1.0 / N;
  return IntStream.range(0, N)
          .mapToObj(twoDiceThrows())
          .collect(groupingBy(side -> side, summingDouble(n -> fraction)));
}
  // END serial

代码示例来源:origin: RichardWarburton/java-8-lambdas-exercises

@GenerateMicroBenchmark
  // BEGIN parallel
public Map<Integer, Double> parallelDiceRolls() {
  double fraction = 1.0 / N;
  return IntStream.range(0, N)                        // <1>
          .parallel()                         // <2>
          .mapToObj(twoDiceThrows())          // <3>
          .collect(groupingBy(side -> side,   // <4>
            summingDouble(n -> fraction))); // <5>
}
  // END parallel

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<String, Double> sumByCategory_parallel_lazy_streams_gsc()
{
  return this.positions.getGscPositions().parallelStream().collect(
      Collectors.groupingBy(
          Position::getCategory,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<Account, Double> sumByAccount_parallel_lazy_streams_gsc()
{
  return this.positions.getGscPositions().parallelStream().collect(
      Collectors.groupingBy(
          Position::getAccount,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<String, Double> sumByCategory_parallel_lazy_jdk()
{
  return this.positions.getJdkPositions().parallelStream().collect(
      Collectors.groupingBy(
          Position::getCategory,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<String, Double> sumByCategory_serial_lazy_streams_gsc()
{
  return this.positions.getGscPositions().stream().collect(
      Collectors.groupingBy(
          Position::getCategory,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<Product, Double> sumByProduct_serial_lazy_streams_gsc()
{
  return this.positions.getGscPositions().stream().collect(
      Collectors.groupingBy(
          Position::getProduct,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<Product, Double> sumByProduct_parallel_lazy_streams_gsc()
{
  return this.positions.getGscPositions().parallelStream().collect(
      Collectors.groupingBy(
          Position::getProduct,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<Account, Double> sumByAccount_parallel_lazy_jdk()
{
  return this.positions.getJdkPositions().parallelStream().collect(
      Collectors.groupingBy(
          Position::getAccount,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<Account, Double> sumByAccount_serial_lazy_streams_gsc()
{
  return this.positions.getGscPositions().stream().collect(
      Collectors.groupingBy(
          Position::getAccount,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: goldmansachs/gs-collections

@Benchmark
public Map<Product, Double> sumByProduct_parallel_lazy_jdk()
{
  return this.positions.getJdkPositions().parallelStream().collect(
      Collectors.groupingBy(
          Position::getProduct,
          Collectors.summingDouble(Position::getMarketValue)));
}

代码示例来源:origin: org.eclipse.elk/org.eclipse.elk.core

/**
 * Aggregator that returns the sum of all heuristic results.
 * 
 * @param values heuristic results.
 * @return the sum.
 */
public static double sum(final Collection<Double> values) {
  return values.stream().collect(Collectors.summingDouble((d) -> d));
}

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

@Override
public double sumDouble(ToDoubleFunction<? super T> function) {
  return collect(Collectors.summingDouble(function));
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-starter-dataflow-metrics-collector

public Collection<Metric<Double>> getAggregateMetrics() {
  return getInstances().stream().map(instance -> instance.getMetrics()).flatMap(metrics -> metrics.stream())
      .filter(metric -> metric.getName().matches("integration\\.channel\\.(\\w*)\\.send\\.mean"))
      .collect(Collectors.groupingBy(Metric::getName, Collectors.summingDouble(Metric::getValue))).entrySet()
      .stream().map(entry -> new Metric<Double>(entry.getKey(), entry.getValue(), new Date()))
      .collect(Collectors.toList());
}

代码示例来源:origin: broadinstitute/picard

private double effectiveNumberOfBases(Histogram<?> observations) {
    double totalObservations = observations.getSumOfValues();

    // Convert to log base 4 so that the entropy is now a measure
    // of the effective number of DNA bases.  If we used log(2.0)
    // our result would be in bits.
    double entropyBaseE = observations.values().stream().collect(Collectors.summingDouble(
        v -> {double p = v.getValue() / totalObservations;
            return -p * Math.log(p);}));

    return entropyBaseE / MathUtil.LOG_4_BASE_E;
  }
}

代码示例来源:origin: com.github.broadinstitute/picard

private double effectiveNumberOfBases(Histogram<?> observations) {
    double totalObservations = observations.getSumOfValues();

    // Convert to log base 4 so that the entropy is now a measure
    // of the effective number of DNA bases.  If we used log(2.0)
    // our result would be in bits.
    double entropyBaseE = observations.values().stream().collect(Collectors.summingDouble(
        v -> {double p = v.getValue() / totalObservations;
            return -p * Math.log(p);}));

    return entropyBaseE / MathUtil.LOG_4_BASE_E;
  }
}

相关文章