Package: java.util

## [Java] Class OptionalInt

- java.util.OptionalInt

-     public class OptionalInt
      extends Object

  GDK enhancements for OptionalInt.

  displayName:
    OptionalInt
  receiverFqcn:
    java.util.OptionalInt

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public OptionalInt` | `filter(IntPredicate test)` If a value is present in the `OptionalInt`, tests the value using the given predicate and returns the optional if the test returns true or else empty.
    `` | `public int` | `get()` If a value is present in the `OptionalInt`, returns the value.
    `<T>` | `public Optional<T>` | `mapToObj(IntFunction<? extends T> mapper)` If a value is present in the `OptionalInt`, returns an `Optional` consisting of the result of applying the given function to the value or else empty.
    `` | `public OptionalInt` | `peek(IntConsumer action)` If a value is present in the `OptionalInt`, executes the specified `action` with the value as input and then returns `self`.
    `` | `public IntStream` | `stream()` If a value is present in the OptionalInt, returns an IntStream 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, 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, tap, toString, use, use, use, with, with, withCloseable, withCloseable, withMethodClosure, withStream, withStream, withTraits`

- - ### Method Detail

    - #### public OptionalInt filter(IntPredicate test)

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

           assert !OptionalInt.empty().filter(i -> true).isPresent()
           assert  OptionalInt.of(1234).filter(i -> true).isPresent()
           assert !OptionalInt.of(1234).filter(i -> false).isPresent()
           assert  OptionalInt.of(1234).filter(i -> true).getAsInt() == 1234

      Since:
        3.0.0

    - #### public int get()

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

           assert OptionalInt.of(1234).get() == 1234

      throws:
        NoSuchElementException if no value is present
      Since:
        3.0.0

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

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

           assert !OptionalInt.empty().mapToObj(x -> new Object()).isPresent()
           assert  OptionalInt.of(1234).mapToObj(x -> new Object()).isPresent()
           assert !OptionalInt.of(1234).mapToObj(x -> null).isPresent()
           assert  OptionalInt.of(1234).mapToObj(Integer::toString).get() == '1234'

      Since:
        3.0.0

    - #### public OptionalInt peek(IntConsumer action)

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

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

           opt = OptionalInt.of(42)
           out = opt.peek{ assert it == 42; called = true }
           assert out === opt
           assert called

      Since:
        5.0.0

    - #### public IntStream stream()

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

      Since:
        3.0.0