Example usage for java.util OptionalDouble isPresent

List of usage examples for java.util OptionalDouble isPresent

Introduction

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

Prototype

boolean isPresent

To view the source code for java.util OptionalDouble isPresent.

Click Source Link

Document

If true then the value is present, otherwise indicates no value is present

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 {/*w  ww .  j av  a  2s  .  c om*/
        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 {/*  w  ww  . ja v a  2  s  .  co m*/
        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   w  w w.  jav  a  2s. 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 {/*from   w ww . 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 {//  ww  w . j av  a2  s  .co m
        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   www  . 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  ww  .  j  a 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.reduce(Double::sum);
    if (d.isPresent()) {
        System.out.println(d.getAsDouble());
    } else {//  w w  w. j  av a2  s.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 {//  www .  j  a  va  2 s .c o m
        System.out.println("Could not  get   the   highest income.");
    }
}

From source file:ch.zweivelo.renderer.simple.shapes.Sphere.java

@Override
public Optional<Double> calculateIntersectionDistance(final Ray ray) {
    Vector3D dir = ray.getDirection();
    Vector3D tmp = ray.getOrigin().subtract(center);

    OptionalDouble min = Solver.QUADRATIC
            .solve(tmp.dotProduct(tmp) - radius * radius, 2 * dir.dotProduct(tmp), dir.dotProduct(dir)).min();

    if (min.isPresent()) {
        return Optional.of(min.getAsDouble());
    }//from  www.j  a  va 2s  .  com

    return Optional.empty();
}