Example usage for java.util OptionalDouble getAsDouble

List of usage examples for java.util OptionalDouble getAsDouble

Introduction

In this page you can find the example usage for java.util OptionalDouble getAsDouble.

Prototype

public double getAsDouble() 

Source Link

Document

If a value is present, returns the value, otherwise throws NoSuchElementException .

Usage

From source file:Main.java

public static void main(String[] args) {
    IntStream i = IntStream.of(6, 5, 7, 1, 2, 3, 3);
    OptionalDouble d = i.average();
    if (d.isPresent()) {
        System.out.println(d.getAsDouble());
    } else {//from  w w  w.  j a  va2s . c  o m
        System.out.println("no value");
    }
}

From source file:Main.java

public static void main(String[] args) {
    DoubleStream b = DoubleStream.of(1.1, 2.2, 3.3, 4.4, 5.5);
    OptionalDouble d = b.findAny();
    if (d.isPresent()) {
        System.out.println(d.getAsDouble());
    } else {//from   w ww  .  j a  v  a  2  s .c  om
        System.out.println("no data");
    }
}

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 {/*from   ww w.  j  a  va2  s  .  c om*/
        System.out.println("no value");
    }
}

From source file:Main.java

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

    OptionalDouble v = d.max();

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

From source file:Main.java

public static void main(String[] args) {
    DoubleStream b = DoubleStream.of(1.1, 2.2, 3.3, 4.4, 5.5);
    OptionalDouble d = b.findFirst();
    if (d.isPresent()) {
        System.out.println(d.getAsDouble());
    } else {/*  w w w.  j  a v a 2s . c om*/
        System.out.println("no data");
    }
}

From source file:Main.java

public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);
    OptionalDouble o = b.average();

    if (o.isPresent()) {
        System.out.println(o.getAsDouble());
    } else {//from  w w  w .  j  a v a2  s.com
        System.out.println("no value");
    }
}

From source file:Main.java

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

    OptionalDouble v = d.average();

    if (v.isPresent()) {
        System.out.println(v.getAsDouble());
    } else {//from   w w w  . ja va 2s .  com
        System.out.println("no value");
    }
}

From source file:Main.java

public static void main(String[] args) {
    DoubleStream b = DoubleStream.of(1.1, 2.2, 3.3, 4.4, 5.5);

    OptionalDouble d = b.reduce(Double::sum);
    if (d.isPresent()) {
        System.out.println(d.getAsDouble());
    } else {//from  ww  w .  jav  a  2s .  c  om
        System.out.println("no value");
    }
}

From source file:Main.java

public static void main(String[] args) {
    OptionalDouble income = Employee.persons().stream().mapToDouble(Employee::getIncome).max();

    if (income.isPresent()) {
        System.out.println("Highest income:   " + income.getAsDouble());
    } else {//  ww w  .  j  av  a  2 s  .c  o m
        System.out.println("Could not  get   the   highest income.");
    }
}

From source file:gr.iti.mklab.reveal.forensics.util.Util.java

/**
 * Calculate histogram//from   ww  w .j  av  a  2 s. com
 */

public static int[] createhistogram(double[] zmat, int bins) throws IOException {

    OptionalDouble max = DoubleStream.of(zmat).max();
    OptionalDouble min = DoubleStream.of(zmat).min();
    int[] result = new int[bins];
    double binSize = (max.getAsDouble() - min.getAsDouble()) / bins;

    for (double d : zmat) {
        int bin = (int) ((d - min.getAsDouble()) / binSize);
        if (bin < 0) {
            /* this data is smaller than min */ System.out.println("this data point is smaller than min " + d);
        } else if (bin >= bins) { /* this data point is bigger than max */
            result[bin - 1] += 1;
        } else {
            result[bin] += 1;
        }
    }

    return result;
}