Package 

Class Try

  • All Implemented Interfaces:

    
    public class Try<Success extends Object, Failure extends Throwable>
    
                        

    A Result type which can be used as a return type.

    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract Boolean isSuccess()
      abstract Boolean isFailure()
      abstract Success getOrThrow() Returns the encapsulated value if this instance represents success or throws the encapsulated Throwable exception if it is failure.
      abstract Success getOrNull() Returns the encapsulated value if this instance represents success or null if it is failure.
      abstract Failure exceptionOrNull() Returns the encapsulated Throwable exception if this instance represents failure or null if it is success.
      final <R extends Any> Try<R, Failure> map(Function1<Success, R> transform) Returns the encapsulated result of the given transform function applied to the encapsulated value if this instance represents success or the original encapsulated Throwable exception if it is failure.
      final <F extends Throwable> Try<Success, F> mapFailure(Function1<Failure, F> transform) Returns the encapsulated result of the given transform function applied to the encapsulated failure if this instance represents failure or the original encapsulated success value if it is a success.
      final <R extends Any> R fold(Function1<Success, R> onSuccess, Function1<Throwable, R> onFailure) Returns the result of onSuccess for the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failure.
      final Try<Success, Failure> onSuccess(Function1<Success, Unit> action) Performs the given action on the encapsulated value if this instance represents success.
      final Try<Success, Failure> onFailure(Function1<Failure, Unit> action) Performs the given action on the encapsulated Throwable exception if this instance represents failure.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • getOrThrow

         abstract Success getOrThrow()

        Returns the encapsulated value if this instance represents success or throws the encapsulated Throwable exception if it is failure.

      • getOrNull

         abstract Success getOrNull()

        Returns the encapsulated value if this instance represents success or null if it is failure.

      • exceptionOrNull

         abstract Failure exceptionOrNull()

        Returns the encapsulated Throwable exception if this instance represents failure or null if it is success.

      • map

         final <R extends Any> Try<R, Failure> map(Function1<Success, R> transform)

        Returns the encapsulated result of the given transform function applied to the encapsulated value if this instance represents success or the original encapsulated Throwable exception if it is failure.

      • mapFailure

         final <F extends Throwable> Try<Success, F> mapFailure(Function1<Failure, F> transform)

        Returns the encapsulated result of the given transform function applied to the encapsulated failure if this instance represents failure or the original encapsulated success value if it is a success.

      • fold

         final <R extends Any> R fold(Function1<Success, R> onSuccess, Function1<Throwable, R> onFailure)

        Returns the result of onSuccess for the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failure.

      • onSuccess

         final Try<Success, Failure> onSuccess(Function1<Success, Unit> action)

        Performs the given action on the encapsulated value if this instance represents success. Returns the original Try unchanged.