Class Try<S,E extends Exception>

java.lang.Object
org.ehrbase.openehr.sdk.util.functional.Either<S,E>
org.ehrbase.openehr.sdk.util.functional.Try<S,E>
Direct Known Subclasses:
Try.Failure, Try.Success

public abstract class Try<S,E extends Exception> extends Either<S,E>
  • Constructor Details

    • Try

      protected Try(Object result)
  • Method Details

    • success

      public static <S1, E1 extends Exception> Try.Success<S1,E1> success(S1 result)
    • failure

      public static <S1, E1 extends Exception> Try.Failure<S1,E1> failure(E1 failure)
    • isLeft

      public boolean isLeft()
      Specified by:
      isLeft in class Either<S,E extends Exception>
    • isRight

      public boolean isRight()
      Specified by:
      isRight in class Either<S,E extends Exception>
    • isSuccess

      public abstract boolean isSuccess()
    • isFailure

      public abstract boolean isFailure()
    • get

      public abstract Object get()
      Specified by:
      get in class Either<S,E extends Exception>
    • getOrThrow

      public abstract S getOrThrow() throws E
      Throws:
      E extends Exception
    • getAsSuccess

      public abstract Try.Success<S,E> getAsSuccess()
    • getAsFailure

      public abstract Try.Failure<S,E> getAsFailure()
    • map

      public abstract <T> T map(BiFunction<S,E,T> map)
      Convenience method to transform the internal state
      Specified by:
      map in class Either<S,E extends Exception>
      Parameters:
      map - function which maps the internal state to the specified type The function must be null safe in both arguments
      Returns:
      the mapped internal state
    • consume

      public abstract void consume(BiConsumer<S,E> con)
      Convenience method to consume the internal state
      Specified by:
      consume in class Either<S,E extends Exception>
      Parameters:
      con - consumer which consumes the internal state The consumer must be null safe in both arguments