Class Optionals

java.lang.Object
com.atlassian.jira.util.Optionals

public final class Optionals extends Object
Utility methods relating to the Optional type, to make up for its deficiencies.
Since:
9.7
  • Method Details

    • fallBack

      @Nonnull public static <T> Optional<T> fallBack(Optional<T> primary, Supplier<Optional<T>> secondarySupplier)
      If the first optional given is empty, falls back to the second one (which could also be empty).
      Type Parameters:
      T - the type of optional value
      Parameters:
      primary - the first optional to check
      secondarySupplier - the supplier of the optional to use as a fallback
      Returns:
      an optional, could be empty
    • foldToEffect

      public static <T> void foldToEffect(Optional<T> optional, Consumer<T> ifPresent, Runnable ifAbsent)
      Specialised version of fold that "returns" Void.
      Type Parameters:
      T - the optional type
      Parameters:
      optional - the optional to be folded
      ifPresent - the consumer to invoke if the optional is present
      ifAbsent - the effect to perform if the optional is empty