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

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

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

Collectors.averagingInt介绍

暂无

代码示例

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

public double averageNumberOfTracks(List<Album> albums) {
  return albums.stream()
         .collect(averagingInt(album -> album.getTrackList().size()));
}
  // END averagingTracks

代码示例来源:origin: Vedenin/useful-java-links

double average = numbers.stream().collect(Collectors.averagingInt((p) -> p - 1));
System.out.println("average = " + average); // print  average = 1.5

代码示例来源:origin: biezhi/learn-java8

public static void main(String[] args) {
    List<Project> projects = Project.buildData();
    Double collect = projects.stream()
        .collect(averagingInt(Project::getStars));
    System.out.println(collect);

    System.out.println(Stream.of("Hello", "Java8")
        .collect(joining(",")));

    Integer collect1 = projects.stream()
        .collect(reducing(0, Project::getStars, (x, y) -> x + y));
    System.out.println(collect1);

    Optional<Integer> collect2 = projects.stream()
        .map(Project::getStars)
        .collect(reducing((x, y) -> x + y));
    System.out.println(collect2);
  }
}

代码示例来源:origin: dunwu/javacore

private static void test3(List<Person> persons) {
  Double averageAge = persons
    .stream()
    .collect(Collectors.averagingInt(p -> p.age));
  System.out.println(averageAge);     // 19.0
}

代码示例来源:origin: pavelfatin/typometer

private static double maxDeviationIn(Collection<Integer> values) {
    double average = values.stream().collect(Collectors.averagingInt(it -> it));

    return values.stream().map(it -> abs(it - average)).reduce(0.0D, Math::max);
  }
}

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

@Override
public double avgInt(ToIntFunction<? super T> function) {
  return collect(Collectors.averagingInt(function));
}

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

@Override
public double avgInt(ToIntFunction<? super T> function) {
  return collect(Collectors.averagingInt(function));
}

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

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.stream.Collectors;

public class FindAverage {

  public static void main(String[] args) throws IOException,
      URISyntaxException {

    Double average = Arrays
        .stream(Files
            .lines(Paths.get(ClassLoader.getSystemResource(
                "input.txt").toURI()))
            .reduce((a, b) -> a + " " + b).map(e -> e.split(" "))
            .get()).filter(e -> e.matches("\\d+"))
        .map(Integer::new)
        .collect(Collectors.averagingInt(Integer::intValue));

    System.out.println("Average = " + average);
  }
}

代码示例来源:origin: gauravrmazra/gauravbytes

System.out.println(personByAge);
Double averageAge = persons.stream().collect(Collectors.averagingInt(Person::getAge));
System.out.println(averageAge);

代码示例来源:origin: theonedev/onedev

works.queued.drainTo(works.working, worker.getMaxBatchSize());
if (!works.working.isEmpty()) {
  double priority = works.working.stream().collect(Collectors.averagingInt(Prioritized::getPriority));
  workExecutor.execute(new PrioritizedRunnable((int)priority) {

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

collect.forEach((k, v) -> System.out.println(k + " " + v.stream().collect(Collectors.averagingInt(Information::getAge))));

代码示例来源:origin: shengsiyuan/jdk8

System.out.println(students.stream().collect(averagingInt(Student::getScore)));
System.out.println(students.stream().collect(summingInt(Student::getScore)));
IntSummaryStatistics intSummaryStatistics = students.stream().collect(summarizingInt(Student::getScore));

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

public void testObjCollectorIntAverager() {
 Cache<Integer, String> cache = getCache(0);
 int range = 10;
 // First populate the cache with a bunch of values
 IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
 assertEquals(range, cache.size());
 CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
 assertEquals(4.5, createStream(entrySet).collect(
    () -> Collectors.averagingInt(Map.Entry::getKey)));
}

代码示例来源:origin: improbable-research/keanu

private static double calculateMeanOfVertex(IntegerVertex vertex) {
    KeanuProbabilisticModel model = new KeanuProbabilisticModel(vertex.getConnectedGraph());

    return MetropolisHastings.withDefaultConfigFor(model, KeanuRandom.getDefaultRandom())
      .generatePosteriorSamples(model, Collections.singletonList(vertex)).stream()
      .limit(2000)
      .collect(Collectors.averagingInt((NetworkSample state) -> state.get(vertex).scalar()));
  }
}

相关文章