Example usage for java.util.stream DoubleStream sum

List of usage examples for java.util.stream DoubleStream sum

Introduction

In this page you can find the example usage for java.util.stream DoubleStream sum.

Prototype

double sum();

Source Link

Document

Returns the sum of elements in this stream.

Usage

From source file:Main.java

public static void main(String[] args) {
    DoubleStream d = DoubleStream.of(1.2, 2.3, 4.5);

    double v = d.sum();

    System.out.println(v);// www .  j  a v  a 2s  . c  om

}

From source file:com.hortonworks.streamline.streams.metrics.storm.ambari.AmbariMetricsServiceWithStormQuerier.java

private Map<Long, Double> aggregateStreamsForMetricsValues(Map<Long, List<Pair<String, Double>>> ret,
        AggregateFunction aggrFunction) {
    return ret.entrySet().stream().collect(toMap(e -> e.getKey(), e -> {
        DoubleStream valueStream = e.getValue().stream().mapToDouble(d -> d.getRight());
        switch (aggrFunction) {
        case SUM:
            return valueStream.sum();

        case AVG:
            return valueStream.average().orElse(0.0d);

        case MAX:
            return valueStream.max().orElse(0.0d);

        case MIN:
            return valueStream.min().orElse(0.0d);

        default://from  w ww .  j a v a 2  s  .c  o m
            throw new IllegalArgumentException("Not supported aggregated function.");

        }
    }));
}