Class OptionalUtils


  • public final class OptionalUtils
    extends java.lang.Object
    Utilities for Java's Optional class.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.Optional<T> or​(java.util.function.Supplier<java.util.Optional<? extends T>>... optionals)
      Return the first optional to be defined.
      static <T> java.util.Optional<T> or​(java.util.Optional<T> a, java.util.Optional<? extends T> b)
      Return the first optional to be defined.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • or

        public static <T> java.util.Optional<T> or​(java.util.Optional<T> a,
                                                   java.util.Optional<? extends T> b)
        Return the first optional to be defined.
        Type Parameters:
        T - The type
        Parameters:
        a - The first
        b - The second
        Returns:
        a or b or empty
      • or

        @SafeVarargs
        public static <T> java.util.Optional<T> or​(java.util.function.Supplier<java.util.Optional<? extends T>>... optionals)
        Return the first optional to be defined.
        Type Parameters:
        T - The type
        Parameters:
        optionals - the lambdas returning the optionals
        Returns:
        the first non-empty or empty