Package: java.util

## [Java] Class OptionalDouble

- java.util.OptionalDouble

-     public class OptionalDouble
      extends Object

  GDK enhancements for OptionalDouble.

  displayName:
    OptionalDouble
  receiverFqcn:
    java.util.OptionalDouble

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public OptionalDouble` | `filter(DoublePredicate test)` If a value is present in the `OptionalDouble`, tests the value using the given predicate and returns the optional if the test returns true or empty otherwise.
    `` | `public double` | `get()` If a value is present in the `OptionalDouble`, returns the value.
    `<T>` | `public Optional<T>` | `mapToObj(DoubleFunction<? extends T> mapper)` If a value is present in the `OptionalDouble`, returns an `Optional` consisting of the result of applying the given function to the value or else empty.
    `` | `public OptionalDouble` | `peek(DoubleConsumer action)` If a value is present in the `OptionalDouble`, executes the specified `action` with the value as input and then returns `self`.
    `` | `public DoubleStream` | `stream()` If a value is present in the OptionalDouble, returns a DoubleStream with the value as its source or else an empty stream.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `addShutdownHook, any, any, asBoolean, asType, clamp, clamp, collect, collect, collect, dump, each, eachMatch, eachMatch, eachWithIndex, every, every, find, find, findAll, findAll, findIndexOf, findIndexOf, findIndexValues, findIndexValues, findLastIndexOf, findLastIndexOf, findResult, findResult, findResult, findResult, getAt, getMetaClass, getMetaPropertyValues, getProperties, grep, grep, hasProperty, identity, inject, inject, inspect, invokeMethod, is, isCase, isNotCase, iterator, metaClass, print, print, printf, printf, println, println, println, putAt, respondsTo, respondsTo, setMetaClass, sleep, sleep, split, sprintf, sprintf, stream, takeIf, tap, toString, use, use, use, with, with, withCloseable, withCloseable, withMethodClosure, withStream, withStream, withTraits`

- - ### Method Detail

    - #### public OptionalDouble filter(DoublePredicate test)

      If a value is present in the `OptionalDouble`, tests the value using the given predicate and returns the optional if the test returns true or empty otherwise.

           assert !OptionalDouble.empty().filter(n -> true).isPresent()
           assert  OptionalDouble.of(Math.PI).filter(n -> true).isPresent()
           assert !OptionalDouble.of(Math.PI).filter(n -> false).isPresent()
           assert  OptionalDouble.of(Math.PI).filter(n -> true).getAsDouble() == Math.PI

      Since:
        3.0.0

    - #### public double get()

      If a value is present in the `OptionalDouble`, returns the value.

           assert OptionalDouble.of(Math.PI).get() == Math.PI

      throws:
        NoSuchElementException if no value is present
      Since:
        3.0.0

    - #### <T> public Optional<T> mapToObj(DoubleFunction<? extends T> mapper)

      If a value is present in the `OptionalDouble`, returns an `Optional` consisting of the result of applying the given function to the value or else empty.

           assert !OptionalDouble.empty().mapToObj(x -> new Object()).isPresent()
           assert  OptionalDouble.of(Math.PI).mapToObj(x -> new Object()).isPresent()
           assert !OptionalDouble.of(Math.PI).mapToObj(x -> null).isPresent()
           assert  OptionalDouble.of(Math.PI).mapToObj(Double::toString).get().startsWith('3.14')

      Since:
        3.0.0

    - #### public OptionalDouble peek(DoubleConsumer action)

      If a value is present in the `OptionalDouble`, executes the specified `action` with the value as input and then returns `self`.

           boolean called = false
           def opt = OptionalDouble.empty()
           def out = opt.peek{ called = true }
           assert out === opt
           assert !called

           opt = OptionalDouble.of(Math.PI)
           out = opt.peek{ assert it == Math.PI; called = true }
           assert out === opt
           assert called

      Since:
        5.0.0

    - #### public DoubleStream stream()

      If a value is present in the OptionalDouble, returns a DoubleStream with the value as its source or else an empty stream.

      Since:
        3.0.0