Example usage for java.util.stream Collectors summarizingDouble

List of usage examples for java.util.stream Collectors summarizingDouble

Introduction

In this page you can find the example usage for java.util.stream Collectors summarizingDouble.

Prototype

public static <T> Collector<T, ?, DoubleSummaryStatistics> summarizingDouble(
        ToDoubleFunction<? super T> mapper) 

Source Link

Document

Returns a Collector which applies an double -producing mapping function to each input element, and returns summary statistics for the resulting values.

Usage

From source file:Main.java

public static void main(String[] args) {
    DoubleSummaryStatistics incomeStats = Employee.persons().stream()
            .collect(Collectors.summarizingDouble(Employee::getIncome));
    System.out.println(incomeStats);
}

From source file:Main.java

public static void main(String[] args) {
    Map<Employee.Gender, DoubleSummaryStatistics> incomeStatsByGender = Employee.persons().stream().collect(
            Collectors.groupingBy(Employee::getGender, Collectors.summarizingDouble(Employee::getIncome)));

    System.out.println(incomeStatsByGender);
}

From source file:io.yields.math.concepts.operator.Smoothness.java

public static List<Tuple> normalize(Collection<Tuple> tuples) {
    DoubleSummaryStatistics statsForX = tuples.stream()
            .collect(Collectors.summarizingDouble(tuple -> tuple.getX()));
    DoubleSummaryStatistics statsForY = tuples.stream()
            .collect(Collectors.summarizingDouble(tuple -> tuple.getY()));
    double minX = statsForX.getMin();
    double maxX = statsForX.getMax();
    double minY = statsForY.getMin();
    double maxY = statsForY.getMax();
    return tuples.stream().map(tuple -> {
        double x = (tuple.getX() - minX) / (maxX - minX);
        double y = (tuple.getY() - minY) / (maxY - minY);
        return new Tuple(x, y);
    }).collect(Collectors.toList());
}

From source file:com.gs.collections.impl.jmh.AggregateByTest.java

@Warmup(iterations = 20)
@Measurement(iterations = 10)// ww  w .java 2 s.  c o m
@Benchmark
public Map<Product, DoubleSummaryStatistics> aggregateByProduct_serial_lazy_jdk() {
    Map<Product, DoubleSummaryStatistics> result = this.jdkPositions.stream().collect(Collectors
            .groupingBy(Position::getProduct, Collectors.summarizingDouble(Position::getMarketValue)));
    Assert.assertNotNull(result);
    return result;
}

From source file:com.gs.collections.impl.jmh.AggregateByTest.java

@Warmup(iterations = 20)
@Measurement(iterations = 10)/*from  ww w  .ja  va 2s.c  o m*/
@Benchmark
public Map<Account, DoubleSummaryStatistics> aggregateByAccount_serial_lazy_jdk() {
    Map<Account, DoubleSummaryStatistics> accountDoubleMap = this.jdkPositions.stream().collect(Collectors
            .groupingBy(Position::getAccount, Collectors.summarizingDouble(Position::getMarketValue)));
    Assert.assertNotNull(accountDoubleMap);
    return accountDoubleMap;
}

From source file:com.gs.collections.impl.jmh.AggregateByTest.java

@Warmup(iterations = 20)
@Measurement(iterations = 10)//from   ww  w.ja v  a 2s  .  c o m
@Benchmark
public Map<String, DoubleSummaryStatistics> aggregateByCategory_serial_lazy_jdk() {
    Map<String, DoubleSummaryStatistics> categoryDoubleMap = this.jdkPositions.stream().collect(Collectors
            .groupingBy(Position::getCategory, Collectors.summarizingDouble(Position::getMarketValue)));
    Assert.assertNotNull(categoryDoubleMap);
    return categoryDoubleMap;
}

From source file:com.gs.collections.impl.jmh.AggregateByTest.java

@Warmup(iterations = 20)
@Measurement(iterations = 10)//  w w  w  .  ja  v a2s  .  c  om
@Benchmark
public Map<Product, DoubleSummaryStatistics> aggregateByProduct_parallel_lazy_jdk() {
    Map<Product, DoubleSummaryStatistics> result = this.jdkPositions.parallelStream().collect(Collectors
            .groupingBy(Position::getProduct, Collectors.summarizingDouble(Position::getMarketValue)));
    Assert.assertNotNull(result);
    return result;
}

From source file:com.gs.collections.impl.jmh.AggregateByTest.java

@Warmup(iterations = 20)
@Measurement(iterations = 10)/*from www .j  a  va2 s.com*/
@Benchmark
public Map<Account, DoubleSummaryStatistics> aggregateByAccount_parallel_lazy_jdk() {
    Map<Account, DoubleSummaryStatistics> result = this.jdkPositions.parallelStream().collect(Collectors
            .groupingBy(Position::getAccount, Collectors.summarizingDouble(Position::getMarketValue)));
    Assert.assertNotNull(result);
    return result;
}

From source file:com.gs.collections.impl.jmh.AggregateByTest.java

@Warmup(iterations = 20)
@Measurement(iterations = 10)//  w w  w  . j av a 2s  .c  o  m
@Benchmark
public Map<String, DoubleSummaryStatistics> aggregateByCategory_parallel_lazy_jdk() {
    Map<String, DoubleSummaryStatistics> result = this.jdkPositions.parallelStream().collect(Collectors
            .groupingBy(Position::getCategory, Collectors.summarizingDouble(Position::getMarketValue)));
    Assert.assertNotNull(result);
    return result;
}

From source file:org.eclipse.collections.impl.jmh.AggregateByTest.java

@Benchmark
public Map<Product, DoubleSummaryStatistics> aggregateByProduct_serial_lazy_jdk() {
    Map<Product, DoubleSummaryStatistics> result = this.jdkPositions.stream().collect(Collectors
            .groupingBy(Position::getProduct, Collectors.summarizingDouble(Position::getMarketValue)));
    Assert.assertNotNull(result);//from  www .j  a v a2  s.c o  m
    return result;
}