SuccessType
- the return type for a successful operation.public interface ServiceResult<SuccessType> extends Result<SuccessType,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 |
---|---|
String |
getErrorMessage()
The return message of a failed operation.
|
SuccessType |
getMessage()
The return message of a successful operation.
|
default ServiceResult<SuccessType> |
ifFailure(Consumer<? super String> consumer)
If the result of the operation has failed, invoke the specified consumer with the value,
otherwise do nothing.
|
default ServiceResult<SuccessType> |
ifSuccessful(Consumer<? super SuccessType> consumer)
Executes the provided
Consumer if this ServiceResult is a success. |
<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. |
isFailure, isSuccessful
<T> T map(Function<SuccessType,T> successFunction, Function<String,T> errorFunction)
Result
SuccessType
or FailureType
depending on
success or
failure of the operation.map
in interface Result<SuccessType,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 typeT
SuccessType getMessage()
Result
SuccessType
getMessage
in interface Result<SuccessType,String>
String getErrorMessage()
Result
FailureType
getErrorMessage
in interface Result<SuccessType,String>
default ServiceResult<SuccessType> ifSuccessful(Consumer<? super SuccessType> consumer)
Consumer
if this ServiceResult
is a success.consumer
- the Consumer
to be executed on success.ServiceResult
default ServiceResult<SuccessType> ifFailure(Consumer<? super String> consumer)
consumer
- block to be executed if a value is presentServiceResult
NullPointerException
- if value is present and consumer
is
null