Class Result<T,E extends Throwable>

java.lang.Object
com.landawn.abacus.util.Result<T,E>
Type Parameters:
T -
E -
All Implemented Interfaces:
Immutable
Direct Known Subclasses:
Result.R

@Immutable public class Result<T,E extends Throwable> extends Object implements Immutable
Author:
Haiyang Li
  • Method Details

    • of

      public static <T, E extends Throwable> Result<T,E> of(T value, E exception)
      Type Parameters:
      T -
      E -
      Parameters:
      value -
      exception -
      Returns:
    • isFailure

      public boolean isFailure()
      Checks if is failure.
      Returns:
      true, if is failure
    • isSuccess

      public boolean isSuccess()
      Checks if is success.
      Returns:
      true, if is success
    • ifFailure

      public <E2 extends Throwable> void ifFailure(Throwables.Consumer<? super E,E2> actionOnFailure) throws E2
      Type Parameters:
      E2 -
      Parameters:
      actionOnFailure -
      Throws:
      E2 - the e2
    • ifFailureOrElse

      public <E2 extends Throwable, E3 extends Throwable> void ifFailureOrElse(Throwables.Consumer<? super E,E2> actionOnFailure, Throwables.Consumer<? super T,E3> actionOnSuccess) throws E2, E3
      If failure or else.
      Type Parameters:
      E2 -
      E3 -
      Parameters:
      actionOnFailure -
      actionOnSuccess -
      Throws:
      E2 - the e2
      E3 - the e3
    • ifSuccess

      public <E2 extends Throwable> void ifSuccess(Throwables.Consumer<? super T,E2> actionOnSuccess) throws E2
      Type Parameters:
      E2 -
      Parameters:
      actionOnSuccess -
      Throws:
      E2 - the e2
    • ifSuccessOrElse

      public <E2 extends Throwable, E3 extends Throwable> void ifSuccessOrElse(Throwables.Consumer<? super T,E2> actionOnSuccess, Throwables.Consumer<? super E,E3> actionOnFailure) throws E2, E3
      If success or else.
      Type Parameters:
      E2 -
      E3 -
      Parameters:
      actionOnSuccess -
      actionOnFailure -
      Throws:
      E2 - the e2
      E3 - the e3
    • orElse

      @Deprecated public T orElse(T defaultValueIfErrorOccurred)
      Deprecated.
      Parameters:
      defaultValueIfErrorOccurred -
      Returns:
    • orElseGet

      @Deprecated public <E2 extends Throwable> T orElseGet(Throwables.Supplier<? extends T,E2> otherIfErrorOccurred) throws E2
      Type Parameters:
      E2 -
      Parameters:
      otherIfErrorOccurred -
      Returns:
      Throws:
      E2
    • orElseIfFailure

      public T orElseIfFailure(T defaultValueIfErrorOccurred)
      Parameters:
      defaultValueIfErrorOccurred -
      Returns:
    • orElseGetIfFailure

      public <E2 extends Throwable> T orElseGetIfFailure(Throwables.Supplier<? extends T,E2> otherIfErrorOccurred) throws E2
      Type Parameters:
      E2 -
      Parameters:
      otherIfErrorOccurred -
      Returns:
      Throws:
      E2
    • orElseThrow

      public T orElseThrow() throws E
      Or else throw.
      Returns:
      Throws:
      E - the e
    • orElseThrow

      public <E2 extends Throwable> T orElseThrow(Function<? super E,E2> exceptionSupplierIfErrorOccurred) throws E2
      Or else throw.
      Type Parameters:
      E2 -
      Parameters:
      exceptionSupplierIfErrorOccurred -
      Returns:
      Throws:
      E2 - the e2
    • orElseThrow

      public <E2 extends Throwable> T orElseThrow(E2 exception) throws E2
      Type Parameters:
      E2 -
      Parameters:
      exception -
      Returns:
      Throws:
      E2
    • orElseThrow

      public <E2 extends Throwable> T orElseThrow(Supplier<? extends E2> exceptionSupplier) throws E2
      Type Parameters:
      E2 -
      Parameters:
      exceptionSupplier -
      Returns:
      Throws:
      E2
    • getException

      @Beta public E getException()
      Returns the Exception if occurred, otherwise null is returned.
      Returns:
    • getExceptionIfPresent

      @Deprecated @Beta public u.Optional<E> getExceptionIfPresent()
      Deprecated.
      replaced by getException
      Returns the Exception if occurred, otherwise an empty Optional is returned.
      Returns:
    • toPair

      public Pair<T,E> toPair()
      Returns:
    • toTuple

      public Tuple.Tuple2<T,E> toTuple()
      Returns:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      Parameters:
      obj -
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns: