VMware GemFire Java API Reference
Package org.apache.geode.services.result
Interface ServiceResult<SuccessType>
-
- Type Parameters:
SuccessType- the return type for a successful operation.
- All Superinterfaces:
Result<SuccessType,java.lang.String>
public interface ServiceResult<SuccessType> extends Result<SuccessType,java.lang.String>
TheServiceResulttype is an attempt at the function construct of Either. In this implementation aServiceResultcan define either success or failure (error) using the same type.- Since:
- 1.14.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.lang.StringgetErrorMessage()The return message of a failed operation.SuccessTypegetMessage()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 providedConsumerif thisServiceResultis a success.<T> Tmap(java.util.function.Function<SuccessType,T> successFunction, java.util.function.Function<java.lang.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 Detail
-
map
<T> T map(java.util.function.Function<SuccessType,T> successFunction, java.util.function.Function<java.lang.String,T> errorFunction)
Description copied from interface:ResultA mapping function that maps to eitherSuccessTypeorFailureTypedepending on success or failure of the operation.- Specified by:
mapin interfaceResult<SuccessType,java.lang.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,java.lang.String>- Returns:
- the result of the operation
-
getErrorMessage
java.lang.String getErrorMessage()
Description copied from interface:ResultThe return message of a failed operation. The return type is of typeFailureType- Specified by:
getErrorMessagein interfaceResult<SuccessType,java.lang.String>- Returns:
- the failure message of why the operation did not succeed.
-
ifSuccessful
default ServiceResult<SuccessType> ifSuccessful(java.util.function.Consumer<? super SuccessType> consumer)
Executes the providedConsumerif thisServiceResultis a success.- Parameters:
consumer- theConsumerto be executed on success.- Returns:
- this
ServiceResult
-
ifFailure
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.- Parameters:
consumer- block to be executed if a value is present- Returns:
- this
ServiceResult - Throws:
java.lang.NullPointerException- if value is present andconsumeris null
-
-