ServiceResult (Apache Geode 2.0.2)
Description: declaration: package: org.apache.geode.services.result, interface: ServiceResult

Package org.apache.geode.services.result

# Interface ServiceResult<SuccessType>

Type Parameters:
  `SuccessType` - the return type for a successful operation.

All Superinterfaces:
  `Result<SuccessType,String>`

All Known Implementing Classes:
  `Failure`, `Success`

public interface ServiceResult<SuccessType> extends Result<SuccessType,String>
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 Type
  Method
  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.

  ### Methods inherited from interface org.apache.geode.services.result.Result

  `isFailure, isSuccessful`

- ## Method Details

  - ### map

    <T> T map(Function<SuccessType,T> successFunction, Function<String,T> errorFunction)
    Description copied from interface: `Result`
    A mapping function that maps to either `SuccessType` or `FailureType` depending on success or failure of the operation.
    Specified by:
      `map` in interface `Result<SuccessType,String>`
    Type Parameters:
      `T` - the resultant type
    Parameters:
      `successFunction` - the mapping function to map the SuccessType to the resultant type
      `errorFunction` - the mapping function to map the FailureType to the resultant error type
    Returns:
      result of type `T`

  - ### getMessage

    SuccessType getMessage()
    Description copied from interface: `Result`
    The return message of a successful operation. The return type is of type `SuccessType`
    Specified by:
      `getMessage` in interface `Result<SuccessType,String>`
    Returns:
      the result of the operation

  - ### getErrorMessage

    String getErrorMessage()
    Description copied from interface: `Result`
    The return message of a failed operation. The return type is of type `FailureType`
    Specified by:
      `getErrorMessage` in interface `Result<SuccessType,String>`
    Returns:
      the failure message of why the operation did not succeed.

  - ### ifSuccessful

    default ServiceResult<SuccessType> ifSuccessful(Consumer<? super SuccessType> consumer)
    Executes the provided `Consumer` if this `ServiceResult` is a success.
    Parameters:
      `consumer` - the `Consumer` to be executed on success.
    Returns:
      this `ServiceResult`

  - ### ifFailure

    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.
    Parameters:
      `consumer` - block to be executed if a value is present
    Returns:
      this `ServiceResult`
    Throws:
      `NullPointerException` - if value is present and `consumer` is null