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

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

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

Collectors.averagingDouble介绍

暂无

代码示例

canonical example by Tabnine

private Double calculateAverageGrade(Map<String, List<Integer>> gradesList, String studentName)
  throws Exception {
 return Optional.ofNullable(gradesList.get(studentName))
   .map(list -> list.stream().collect(Collectors.averagingDouble(x -> x)))
   .orElseThrow(() -> new Exception("Student not found - " + studentName));
}

代码示例来源:origin: aol/cyclops

default double mean(ToDoubleFunction<T> fn){
  return stream().collect(Collectors.<T>averagingDouble(fn));
}
default Option<T> median(){

代码示例来源:origin: aol/cyclops

default double stdDeviation(ToDoubleFunction<T> fn){
  Seq<T> list = stream().seq();
  double avg = list.collect(Collectors.<T>averagingDouble(fn));
  return Math.sqrt( list.stream().mapToDouble(fn)
      .map(i->i-avg)
      .map(i->i*i)
      .average()
      .getAsDouble());
}

代码示例来源:origin: aol/cyclops

default double populationVariance(ToDoubleFunction<T> fn){
  Seq<T> list = stream().seq();
  double avg = list.collect(Collectors.<T>averagingDouble(fn));
  return (list.map(t -> fn.applyAsDouble(t))
      .map(t -> t - avg)
      .map(t -> t * t)
      .sumDouble(i -> i)/(list.size()));
}

代码示例来源:origin: aol/cyclops

default double variance(ToDoubleFunction<T> fn){
  Seq<T> list = stream().seq();
  double avg = list.collect(Collectors.<T>averagingDouble(fn));
  return (list.map(t -> fn.applyAsDouble(t))
      .map(t -> t - avg)
      .map(t -> t * t)
      .sumDouble(i -> i))/(list.size()-1);
}
default double populationVariance(ToDoubleFunction<T> fn){

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

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

代码示例来源:origin: jponge/vertx-in-action

private void average(Message<JsonObject> message) {
  double avg = lastValues.values().stream()
   .collect(Collectors.averagingDouble(Double::doubleValue));
  JsonObject json = new JsonObject().put("average", avg);
  message.reply(json);
 }
}

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

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

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

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

代码示例来源:origin: com.oath.cyclops/cyclops

default double mean(ToDoubleFunction<T> fn){
  return stream().collect(Collectors.<T>averagingDouble(fn));
}
default Option<T> median(){

代码示例来源:origin: nurkiewicz/rxjava-book-examples

private double averageOfList(List<Double> list) {
  return list
      .stream()
      .collect(Collectors.averagingDouble(x -> x));
}

代码示例来源:origin: epam/NGB

public static double calculateAverage(List<Double> values) {
  return values.stream().collect(Collectors.averagingDouble(x -> x));
}

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

averageTemperature = this.temperatureHistory.values()
    .stream()
    .collect(Collectors.averagingDouble(value -> value));

代码示例来源:origin: epam/NGB

public static double measurePerformance(TestTask task, int attemptsCount) throws Exception {
  List<Double> timings = new ArrayList<>();
  for (int i = 0; i < attemptsCount; i++) {
    double time1 = Utils.getSystemTimeMilliseconds();
    task.doTest();
    double time2 = Utils.getSystemTimeMilliseconds();
    timings.add(time2 - time1);
  }
  return timings.stream().collect(Collectors.averagingDouble(x -> x));
}

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

.collect(Collectors.averagingDouble(Double::doubleValue));
final double powerUsersAvg = values.stream().map(TableDTO::getPowerUsers)
  .collect(Collectors.averagingDouble(Double::doubleValue));

代码示例来源:origin: com.oath.cyclops/cyclops

default double stdDeviation(ToDoubleFunction<T> fn){
  Seq<T> list = stream().seq();
  double avg = list.collect(Collectors.<T>averagingDouble(fn));
  return Math.sqrt( list.stream().mapToDouble(fn)
      .map(i->i-avg)
      .map(i->i*i)
      .average()
      .getAsDouble());
}

代码示例来源:origin: com.oath.cyclops/cyclops

default double variance(ToDoubleFunction<T> fn){
  Seq<T> list = stream().seq();
  double avg = list.collect(Collectors.<T>averagingDouble(fn));
  return (list.map(t -> fn.applyAsDouble(t))
      .map(t -> t - avg)
      .map(t -> t * t)
      .sumDouble(i -> i))/(list.size()-1);
}
default double populationVariance(ToDoubleFunction<T> fn){

代码示例来源:origin: com.oath.cyclops/cyclops

default double populationVariance(ToDoubleFunction<T> fn){
  Seq<T> list = stream().seq();
  double avg = list.collect(Collectors.<T>averagingDouble(fn));
  return (list.map(t -> fn.applyAsDouble(t))
      .map(t -> t - avg)
      .map(t -> t * t)
      .sumDouble(i -> i)/(list.size()));
}

代码示例来源:origin: us.ihmc/euclid-test

assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON);
assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON);
assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON);

代码示例来源:origin: us.ihmc/euclid-test

assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON);
assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), 1.5 * EPSILON);
assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON);
assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON);
assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON);
assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON);
assertEquals(0.0, errors.stream().collect(Collectors.averagingDouble(Double::doubleValue)), EPSILON);

相关文章