SuccessType - the result type for a successful operation.public class Success<SuccessType> extends Object implements ServiceResult<SuccessType>
ServiceResult represents a successful operation. It contains the
return value of type SuccessTypeServiceResult,
Failure| Modifier and Type | Field and Description |
|---|---|
static Success<Boolean> |
SUCCESS_TRUE |
| Modifier and Type | Method and Description |
|---|---|
String |
getErrorMessage()
The return message of a failed operation.
|
SuccessType |
getMessage()
The return message of a successful operation.
|
ServiceResult<SuccessType> |
ifSuccessful(Consumer<? super SuccessType> consumer)
Executes the provided
Consumer if this ServiceResult is a success. |
boolean |
isSuccessful()
Returns a boolean to indicate the success or failure of the operation
|
<T> T |
map(Function<SuccessType,T> successFunction,
Function<String,T> errorFunction)
A mapping function that maps to either
SuccessType or FailureType depending on
success or
failure of the operation. |
static <T> Success<T> |
of(T result)
Creates a
Success object containing the errorMessage |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitifFailure@Immutable public static final Success<Boolean> SUCCESS_TRUE
public static <T> Success<T> of(T result)
Success object containing the errorMessageT - the type of the resultresult - the return value of the successful operationSuccess instance containing the return valuepublic <T> T map(Function<SuccessType,T> successFunction, Function<String,T> errorFunction)
ResultSuccessType or FailureType depending on
success or
failure of the operation.map in interface Result<SuccessType,String>map in interface ServiceResult<SuccessType>T - the resultant typesuccessFunction - the mapping function to map the SuccessType to the resultant typeerrorFunction - the mapping function to map the FailureType to the resultant error typeTpublic SuccessType getMessage()
ResultSuccessTypegetMessage in interface Result<SuccessType,String>getMessage in interface ServiceResult<SuccessType>public String getErrorMessage()
ResultFailureTypegetErrorMessage in interface Result<SuccessType,String>getErrorMessage in interface ServiceResult<SuccessType>public boolean isSuccessful()
ResultisSuccessful in interface Result<SuccessType,String>public ServiceResult<SuccessType> ifSuccessful(Consumer<? super SuccessType> consumer)
ServiceResultConsumer if this ServiceResult is a success.ifSuccessful in interface ServiceResult<SuccessType>consumer - the Consumer to be executed on success.ServiceResult