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.
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 Summary
Fields inherited from class com.fren_gor.ultimateAdvancementAPI.database.Result
occurredException, SUCCESSFUL
-
Constructor Summary
ConstructorDescriptionCreates a successfulObjectResult
withnull
result.ObjectResult
(@NotNull Exception occurredException) Creates a failedObjectResult
.ObjectResult
(T result) Creates a successfulObjectResult
with a result. -
Method Summary
Methods inherited from class com.fren_gor.ultimateAdvancementAPI.database.Result
getOccurredException, isExceptionOccurred, isSucceeded, printStackTrace, rethrowException, rethrowExceptionIfOccurred
-
Field Details
-
result
The result.
-
-
Constructor Details
-
ObjectResult
public ObjectResult()Creates a successfulObjectResult
withnull
result. -
ObjectResult
Creates a successfulObjectResult
with a result.- Parameters:
result
- The result (can benull
).
-
ObjectResult
Creates a failedObjectResult
.- Parameters:
occurredException
- The exception occurred during the operation.
-
-
Method Details
-
hasResult
public boolean hasResult()Returns whether the operation succeeded and the result is notnull
.More formally, this method returns true if and only if
(isSucceeded() && getResult() != null) == true
.- Returns:
- Whether the operation succeeded and the result is not
null
.
-
getResult
Gets the result of the operation if noException
occurred. If an exception occurred, then it is rethrown as anUnhandledException
.- Returns:
- The result of the operation.
- Throws:
UnhandledException
- If an exception occurred.
-
toString
-
equals
-
hashCode
public int hashCode()
-