SuccessType - the return type for a successful operation.public interface ServiceResult<SuccessType> extends Result<SuccessType,java.lang.String>
ServiceResult type is an attempt at the function construct of
Either. In this implementation a
ServiceResult
can define either success or failure (error) using the same type.| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getErrorMessage()
The return message of a failed operation.
|
SuccessType |
getMessage()
The return message of a successful operation.
|
default ServiceResult<SuccessType> |
ifFailure(java.util.function.Consumer<? super java.lang.String> consumer)
If the result of the operation has failed, invoke the specified consumer with the value,
otherwise do nothing.
|
default ServiceResult<SuccessType> |
ifSuccessful(java.util.function.Consumer<? super SuccessType> consumer)
Executes the provided
Consumer if this ServiceResult is a success. |
<T> T |
map(java.util.function.Function<SuccessType,T> successFunction,
java.util.function.Function<java.lang.String,T> errorFunction)
A mapping function that maps to either
SuccessType or FailureType depending on
success or
failure of the operation. |
isFailure, isSuccessful<T> T map(java.util.function.Function<SuccessType,T> successFunction, java.util.function.Function<java.lang.String,T> errorFunction)
ResultSuccessType or FailureType depending on
success or
failure of the operation.map in interface Result<SuccessType,java.lang.String>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 typeTSuccessType getMessage()
ResultSuccessTypegetMessage in interface Result<SuccessType,java.lang.String>java.lang.String getErrorMessage()
ResultFailureTypegetErrorMessage in interface Result<SuccessType,java.lang.String>default ServiceResult<SuccessType> ifSuccessful(java.util.function.Consumer<? super SuccessType> consumer)
Consumer if this ServiceResult is a success.consumer - the Consumer to be executed on success.ServiceResultdefault ServiceResult<SuccessType> ifFailure(java.util.function.Consumer<? super java.lang.String> consumer)
consumer - block to be executed if a value is presentServiceResultjava.lang.NullPointerException - if value is present and consumer is
null