Package org.apache.geode.services.result
Interface ServiceResult<SuccessType>
- Type Parameters:
SuccessType- the return type for a successful operation.
The
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.- Since:
- 1.14.0
-
Method Summary
Modifier and TypeMethodDescriptionThe return message of a failed operation.The return message of a successful operation.default ServiceResult<SuccessType>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 providedConsumerif thisServiceResultis a success.<T> Tmap(Function<SuccessType, T> successFunction, Function<String, T> errorFunction) A mapping function that maps to eitherSuccessTypeorFailureTypedepending on success or failure of the operation.Methods inherited from interface org.apache.geode.services.result.Result
isFailure, isSuccessful
-
Method Details
-
map
Description copied from interface:ResultA mapping function that maps to eitherSuccessTypeorFailureTypedepending on success or failure of the operation.- Specified by:
mapin interfaceResult<SuccessType,String> - Type Parameters:
T- the resultant type- Parameters:
successFunction- the mapping function to map the SuccessType to the resultant typeerrorFunction- the mapping function to map the FailureType to the resultant error type- Returns:
- result of type
T
-
getMessage
SuccessType getMessage()Description copied from interface:ResultThe return message of a successful operation. The return type is of typeSuccessType- Specified by:
getMessagein interfaceResult<SuccessType,String> - Returns:
- the result of the operation
-
getErrorMessage
String getErrorMessage()Description copied from interface:ResultThe return message of a failed operation. The return type is of typeFailureType- Specified by:
getErrorMessagein interfaceResult<SuccessType,String> - Returns:
- the failure message of why the operation did not succeed.
-
ifSuccessful
Executes the providedConsumerif thisServiceResultis a success.- Parameters:
consumer- theConsumerto be executed on success.- Returns:
- this
ServiceResult
-
ifFailure
If the result of the operation has failed, invoke the specified consumer with the value, otherwise do nothing.- Parameters:
consumer- block to be executed if a value is present- Returns:
- this
ServiceResult - Throws:
NullPointerException- if value is present andconsumeris null
-