Class Optionals

java.lang.Object
org.linkki.util.Optionals

@Deprecated(since="2.4.0") public final class Optionals extends Object
Deprecated.
The methods in this class are now implemented by the JDK, rendering this class useless. Use the corresponding methods offered by Optional instead.
Utility class for Optional.
  • Method Details

    • ifPresentOrElse

      @Deprecated(since="2.4.0") public static <T> void ifPresentOrElse(Optional<T> optional, Consumer<? super T> action, Runnable emptyAction)
      If a value is present in the given optional, performs the given action with the value, otherwise performs the given empty-based action.
      Parameters:
      optional - an Optional
      action - the action to be performed, if a value is present
      emptyAction - the empty-based action to be performed, if no value is present
      Throws:
      NullPointerException - if a value is present and the given action is null, or no value is present and the given empty-based action is null.
    • stream

      @Deprecated(since="2.4.0") public static <T> Stream<T> stream(Optional<T> o)
      Deprecated.
      Call Optional.stream() on the object instead.
      If a value is present, returns a sequential Stream containing only that value, otherwise returns an empty Stream.

      API Note: This method can be used to transform a Stream of optional elements to a Stream of present value elements:

       Stream<Optional<T>> os = .. 
       Stream<T> s = os.flatMap(Optional::stream)
       
      Returns:
      the optional value as a Stream
    • either

      @Deprecated(since="2.4.0") public static <T> Optionals.Either<T> either(Optional<T> o)
      Deprecated.
      Call Optional.or(Supplier) on the object instead.
      Creates an Optionals.Either wrapper around the given Optional on which Optionals.Either.or(Supplier) can be called.