Package com.coachconnect.util
Class Result<T,E>
java.lang.Object
com.coachconnect.util.Result<T,E>
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,E> Result <T, E> failure(E error) Creates a failure result with the given error.getError()Gets the error value.getValue()Gets the success value.booleanChecks if this result is a failure.booleanChecks if this result is successful.Maps the success value to a new value.static <T,E> Result <T, E> success(T value) Creates a successful result with the given value.
-
Method Details
-
success
Creates a successful result with the given value.- Type Parameters:
T- The type of the success valueE- The type of the error value- Parameters:
value- The success value- Returns:
- A successful Result
-
failure
Creates a failure result with the given error.- Type Parameters:
T- The type of the success valueE- The type of the error value- Parameters:
error- The error value- Returns:
- A failure Result
-
isSuccess
public boolean isSuccess()Checks if this result is successful.- Returns:
- true if the result is successful, false otherwise
-
isFailure
public boolean isFailure()Checks if this result is a failure.- Returns:
- true if the result is a failure, false otherwise
-
getValue
Gets the success value.- Returns:
- The success value
- Throws:
IllegalStateException- if the result is a failure
-
getError
Gets the error value.- Returns:
- The error value
- Throws:
IllegalStateException- if the result is successful
-
map
Maps the success value to a new value.- Type Parameters:
U- The type of the new success value- Parameters:
mapper- A function to map the success value- Returns:
- A new Result with the mapped value, or the original failure
-