Class Fallible<SuccessType,FailureType>

java.lang.Object
gov.nasa.jpl.aerie.merlin.server.http.Fallible<SuccessType,FailureType>
Type Parameters:
SuccessType - The value type stored on success
FailureType - The error type stored on failure

public class Fallible<SuccessType,FailureType> extends Object
A class representing a fallible operation result.
  • Method Details

    • isFailure

      public boolean isFailure()
      Check if the operation was a failure.
      Returns:
      true if the operation was a failure, otherwise false.
    • get

      public SuccessType get()
      Get the value
      Returns:
      The value;
    • getOptional

      public Optional<SuccessType> getOptional()
      Get the value wrapped in an Optional.
      Returns:
      An Optional containing the value, or an empty Optional if the Fallible is a failure.
    • getMessage

      public String getMessage()
      Get the failure message.
    • getFailure

      public FailureType getFailure()
      Get the failure value.
    • getFailureOptional

      public Optional<FailureType> getFailureOptional()
      Get the failure wrapped in an Optional.
      Returns:
      An Optional containing the failure, or an empty Optional if the Fallible is a success.
    • of

      public static <SuccessType, FailureType> Fallible<SuccessType,FailureType> of(SuccessType value)
      Return a Fallible with a successful value.
      Type Parameters:
      SuccessType - The type of the value.
      Parameters:
      value - The successful value.
      Returns:
      A successful Fallible.
    • failure

      public static <SuccessType, FailureType> Fallible<SuccessType,FailureType> failure(FailureType error)
      Return a Fallible representing a failure with a value.
      Type Parameters:
      FailureType - The type of the value.
      Parameters:
      error - The value indicating failure.
      Returns:
      A failed Fallible with a value.
    • failure

      public static <SuccessType, FailureType> Fallible<SuccessType,FailureType> failure(FailureType error, String message)
      Return a Fallible representing a failure with a value and a message.
      Type Parameters:
      FailureType - > The type of the value.
      Parameters:
      error - The value indicating failure.
      message - The message associated with the failure.
      Returns:
      A failed Fallible with a value and a message.