Class ObjectResult<T>

java.lang.Object
com.fren_gor.ultimateAdvancementAPI.database.Result
com.fren_gor.ultimateAdvancementAPI.database.ObjectResult<T>
Type Parameters:
T - The result type.

public class ObjectResult<T> extends Result
The ObjectResult class represents the result of an operation that returns a value, called result. It can either succeed or fail. If it succeeded, then a (possibly null) result is provided. Otherwise, an Exception occurred. Example usage:
     ObjectResult<Integer> res = doOperation();
     if (res.isSucceeded()) { // the condition here is equivalent to !res.isExceptionOccurred()
         // success
         Integer value = res.getResult();
     } else {
         // exception occurred!
         Exception exception = res.getOccurredException();
     }
 
  • Field Details

    • result

      protected final T result
      The result.
  • Constructor Details

    • ObjectResult

      public ObjectResult()
      Creates a successful ObjectResult with null result.
    • ObjectResult

      public ObjectResult(T result)
      Creates a successful ObjectResult with a result.
      Parameters:
      result - The result (can be null).
    • ObjectResult

      public ObjectResult(@NotNull @NotNull Exception occurredException)
      Creates a failed ObjectResult.
      Parameters:
      occurredException - The exception occurred during the operation.
  • Method Details

    • hasResult

      public boolean hasResult()
      Returns whether the operation succeeded and the result is not null.

      More formally, this method returns true if and only if (isSucceeded() &amp;&amp; getResult() != null) == true.

      Returns:
      Whether the operation succeeded and the result is not null.
    • getResult

      @Contract(pure=true) public T getResult() throws UnhandledException
      Gets the result of the operation if no Exception occurred. If an exception occurred, then it is rethrown as an UnhandledException.
      Returns:
      The result of the operation.
      Throws:
      UnhandledException - If an exception occurred.
    • toString

      public String toString()
      Overrides:
      toString in class Result
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Result
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Result