Class Result<T,​E extends java.lang.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 java.lang.Throwable>
extends java.lang.Object
Result value, wrapping a T (if successful) or an Exception (if failed).
  • Method Summary

    Modifier and Type Method Description
    static <T,​ E extends java.lang.Throwable>
    Result<T,​E>
    failure​(E error)
    Constructs a Result for an Exception (failure).
    T getValue()
    Gets the held value, if the Result is successful, or throws the error on failure.
    boolean isError()
    Checks if the Result is a failure.
    boolean isSuccess()
    Checks if the Result is successful.
    static <T> Result<T,​java.lang.Exception> of​(java.util.concurrent.Callable<T> call)
    Runs the given callable, creating a Result of its value, if run successfully, or its Exception.
    static <T,​ E extends java.lang.Throwable>
    Result<T,​E>
    success​(T value)
    Constructs a Result for a value (success).

    Methods inherited from class java.lang.Object

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

    • getValue

      public T getValue() throws E extends java.lang.Throwable
      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 java.lang.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 java.lang.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,​java.lang.Exception> of​(java.util.concurrent.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