Interface ServiceOutcome<T>

All Superinterfaces:
ServiceResult
All Known Implementing Classes:
ServiceOutcomeImpl

@ExperimentalApi public interface ServiceOutcome<T> extends ServiceResult
An outcome from service which contains either value or validation errors.
Since:
6.7
  • Method Details

    • isValid

      boolean isValid()
      Specified by:
      isValid in interface ServiceResult
      Returns:
      true if there are no errors, false otherwise.
    • isInvalid

      boolean isInvalid()
      Specified by:
      isInvalid in interface ServiceResult
      Returns:
      true if there are errors, false otherwise.
    • getErrors

      @Nonnull ErrorCollection getErrors()
      Specified by:
      getErrors in interface ServiceResult
      Returns:
      an ErrorCollection that contains any errors that happened as a result of the validations.
    • getValue

      @Nonnull T getValue()
      Returns:
      the value that was returned by the service, or throws an NoSuchElementException if outcome is non valid.
    • get

      @Deprecated @Nonnull default T get()
      Deprecated.
      Returns:
      the value that was returned by the service, or throws an NoSuchElementException if outcome is non valid.
    • fold

      <B> B fold(Function<ErrorCollection,B> onErrorFunction, Function<T,B> onSuccessFunction)
      If the ServiceOutcome is valid, apply the on success function, otherwise apply the error function.
      Type Parameters:
      B - the result type
      Parameters:
      onErrorFunction - function executed if ServiceOutcome is invalid.
      onSuccessFunction - function executed if ServiceOutcome in valid.
      Returns:
      the value returned by either or .