Class Result<T,E extends Throwable>

java.lang.Object
com.yubico.yubikit.core.util.Result<T,E>
Type Parameters:
T - the type of the wrapped value
E - the type of the exception thrown

public class Result<T,E extends Throwable> extends Object
Result value, wrapping a T (if successful) or an Exception (if failed).
  • Method Details

    • getValue

      public T getValue() throws E
      Gets the held value, if the Result is successful, or throws the error on failure.
      Returns:
      the held value on success
      Throws:
      E - the held exception on failure
    • isSuccess

      public boolean isSuccess()
      Checks if the Result is successful.
    • isError

      public boolean isError()
      Checks if the Result is a failure.
    • success

      public static <T, E extends Throwable> Result<T,E> success(T value)
      Constructs a Result for a value (success).
      Parameters:
      value - the value to hold
    • failure

      public static <T, E extends Throwable> Result<T,E> failure(E error)
      Constructs a Result for an Exception (failure).
      Parameters:
      error - the error to hold
    • of

      public static <T> Result<T,Exception> of(Callable<T> call)
      Runs the given callable, creating a Result of its value, if run successfully, or its Exception.
      Parameters:
      call - callable to invoke, resulting in a value