Class Result
java.lang.Object
com.fren_gor.ultimateAdvancementAPI.database.Result
- Direct Known Subclasses:
ObjectResult
The
Result
class represents the result of an operation. It can either succeed or fail.
If it failed, then an Exception
occurred.
Example usage:
Result res = doOperation(); if (res.isSucceeded()) { // the condition here is equivalent to !res.isExceptionOccurred() // success } else { // exception occurred! Exception exception = res.getOccurredException(); }
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Gets the occurredException
.int
hashCode()
boolean
Returns whether anException
occurred executing the operation.boolean
Returns whether the operation succeeded.void
Prints the stack trace of the occurred exception.void
Rethrow the occurred exception as anUnhandledException
.void
Rethrow the occurred exception as anUnhandledException
only if that occurred.toString()
-
Field Details
-
SUCCESSFUL
A successfulResult
. -
occurredException
The occurred exception.null
if the operation succeed.
-
-
Constructor Details
-
Result
public Result()Creates a new successfulResult
. -
Result
Creates a failedResult
.- Parameters:
occurredException
- The exception occurred during the operation.- Throws:
IllegalArgumentException
- IfoccurredException
isnull
.
-
-
Method Details
-
isExceptionOccurred
public boolean isExceptionOccurred()Returns whether anException
occurred executing the operation. If noException
occurred, then the operation succeeded.- Returns:
true
if no exception occurred,false
otherwise.
-
isSucceeded
public boolean isSucceeded()Returns whether the operation succeeded. If the operation succeeded, then noException
occurred.- Returns:
true
if the operation succeeded,false
otherwise.
-
getOccurredException
Gets the occurredException
. AnIllegalOperationException
is thrown if no exception occurred.- Returns:
- The occurred exception.
- Throws:
IllegalOperationException
- If no exception occurred.
-
rethrowException
@Contract("-> fail") public void rethrowException() throws UnhandledException, IllegalOperationExceptionRethrow the occurred exception as anUnhandledException
. AnIllegalOperationException
is thrown if no exception occurred.- Throws:
UnhandledException
- If an exception occurred.IllegalOperationException
- If no exception occurred.
-
rethrowExceptionIfOccurred
Rethrow the occurred exception as anUnhandledException
only if that occurred.- Throws:
UnhandledException
- If an exception occurred.
-
printStackTrace
Prints the stack trace of the occurred exception. AnIllegalOperationException
is thrown if no exception occurred.- Throws:
IllegalOperationException
- If no exception occurred.
-
toString
-
equals
-
hashCode
public int hashCode()
-