Example usage for java.util.stream DoubleStream min

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

Introduction

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

Prototype

OptionalDouble min();

Source Link

Document

Returns an OptionalDouble describing the minimum element of this stream, or an empty OptionalDouble if this stream is empty.

Usage

From source file:Main.java

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

    OptionalDouble v = d.min();

    if (v.isPresent()) {
        System.out.println(v.getAsDouble());
    } else {// w w  w  .  j  a  v  a  2 s .c  o  m
        System.out.println("no value");
    }
}

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.  ja v  a2s .  c  o  m
            throw new IllegalArgumentException("Not supported aggregated function.");

        }
    }));
}