SuccessType - the result type for a successful operation. Not used by the Failure
type but required by the ServiceResultpublic class Failure<SuccessType> extends java.lang.Object implements ServiceResult<SuccessType>
ServiceResult represents a failed operation. It contains the
errorMessage for the failure.ServiceResult,
Success| 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.
|
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.
|
boolean |
isFailure()
Returns a boolean to indicate the success or failure of the operation
|
<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. |
static <T> Failure<T> |
of(java.lang.String errorMessage)
Creates a
Failure object containing the errorMessage |
static <T> Failure<T> |
of(java.lang.String errorMessage,
java.lang.Throwable throwable)
Creates a
Failure object containing the errorMessage |
static <T> Failure<T> |
of(java.lang.Throwable throwable)
Creates a
Failure object containing the throwable |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitifSuccessfulisSuccessfulpublic static <T> Failure<T> of(java.lang.String errorMessage)
Failure object containing the errorMessageT - the type of the resulterrorMessage - the error message describing the reason for failure.Failure instance containing the errorMessagepublic static <T> Failure<T> of(java.lang.Throwable throwable)
Failure object containing the throwableT - the type of the resultthrowable - the error message describing the reason for failure.Failure instance containing the throwablepublic static <T> Failure<T> of(java.lang.String errorMessage, java.lang.Throwable throwable)
Failure object containing the errorMessageT - the type of the resulterrorMessage - the error message describing the reason for failure.throwable - the throwable that caused the failureFailure instance containing the errorMessagepublic <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>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,java.lang.String>getMessage in interface ServiceResult<SuccessType>public java.lang.String getErrorMessage()
ResultFailureTypegetErrorMessage in interface Result<SuccessType,java.lang.String>getErrorMessage in interface ServiceResult<SuccessType>public ServiceResult<SuccessType> ifFailure(java.util.function.Consumer<? super java.lang.String> consumer)
ServiceResultifFailure in interface ServiceResult<SuccessType>consumer - block to be executed if a value is presentServiceResultpublic boolean isFailure()
ResultisFailure in interface Result<SuccessType,java.lang.String>