Class Try.Success<A>

java.lang.Object
io.atlassian.fugue.Try<A>
io.atlassian.fugue.Try.Success<A>
All Implemented Interfaces:
Serializable, Iterable<A>
Enclosing class:
Try<A>

private static final class Try.Success<A> extends Try<A>
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • value

      private final A value
  • Constructor Details

    • Success

      Success(A value)
  • Method Details

    • map

      public <B> Try<B> map(Function<? super A,? extends B> f)
      Description copied from class: Try
      Maps the given function to the value from this `Success` or returns this unchanged if a `Failure`.

      Note that for Try.delayed(Supplier) this is not an evaluating operation.

      Specified by:
      map in class Try<A>
      Type Parameters:
      B - result type
      Parameters:
      f - the function to apply
      Returns:
      `f` applied to the `Success`, otherwise returns this if this is a `Failure`.
    • isFailure

      public boolean isFailure()
      Description copied from class: Try
      Returns true if this failure, otherwise false

      Note that for Try.delayed(Supplier) this is an evaluating operation.

      Specified by:
      isFailure in class Try<A>
      Returns:
      true if this failure, otherwise false
    • isSuccess

      public boolean isSuccess()
      Description copied from class: Try
      Returns true if this success, otherwise false

      Note that for Try.delayed(Supplier) this is an evaluating operation.

      Specified by:
      isSuccess in class Try<A>
      Returns:
      true if this success, otherwise false
    • flatMap

      public <B> Try<B> flatMap(Function<? super A,Try<B>> f)
      Description copied from class: Try
      Binds the given function across the success value if it is one.

      Note that for Try.delayed(Supplier) this is not an evaluating operation.

      Specified by:
      flatMap in class Try<A>
      Type Parameters:
      B - result type
      Parameters:
      f - the function to bind.
      Returns:
      A new Try value after binding with the function applied if this is a Success, otherwise returns this if this is a `Failure`.
    • recover

      public Try<A> recover(Function<? super Exception,A> f)
      Description copied from class: Try
      Applies the given function `f` if this is a `Failure` otherwise this unchanged if a 'Success'. This is like map for the failure.

      Note that for Try.delayed(Supplier) this is not an evaluating operation.

      Specified by:
      recover in class Try<A>
      Parameters:
      f - the function to apply
      Returns:
      `f` applied to the `Failure`, otherwise returns this if this is a `Success`.
    • recover

      public <X extends Exception> Try<A> recover(Class<X> exceptionType, Function<? super X,A> f)
      Description copied from class: Try
      Applies the given function `f` if this is a `Failure` with certain exception type otherwise leaves this unchanged. This is like map for exceptions types.

      Note that for Try.delayed(Supplier) this is not an evaluating operation.

      Specified by:
      recover in class Try<A>
      Type Parameters:
      X - exception type
      Parameters:
      exceptionType - exception class
      f - the function to apply
      Returns:
      `f` applied to the `Failure`, otherwise returns this if this is a `Success` or the exception does not match the exception type.
    • recoverWith

      public Try<A> recoverWith(Function<? super Exception,Try<A>> f)
      Description copied from class: Try
      Binds the given function across the failure value if it is one, otherwise this unchanged if a 'Success'. This is like flatmap for the failure.

      Note that for Try.delayed(Supplier) this is not an evaluating operation.

      Specified by:
      recoverWith in class Try<A>
      Parameters:
      f - the function to bind.
      Returns:
      A new Try value after binding with the function applied if this is a `Failure`, otherwise returns this if this is a `Success`.
    • recoverWith

      public <X extends Exception> Try<A> recoverWith(Class<X> exceptionType, Function<? super X,Try<A>> f)
      Description copied from class: Try
      Binds the given function across certain exception type if it is one, otherwise this unchanged. This is like flatmap for exceptions types.

      Note that for Try.delayed(Supplier) this is not an evaluating operation.

      Specified by:
      recoverWith in class Try<A>
      Type Parameters:
      X - exception type
      Parameters:
      exceptionType - exception class
      f - the function to apply
      Returns:
      A new Try value after binding with the function applied if this is a `Failure`, otherwise returns this if this is a `Success` or the exception does not match the exception type.
    • getOrElse

      public A getOrElse(Supplier<A> s)
      Description copied from class: Try
      Returns the contained value if this is a success otherwise call the supplier and return its value.

      Note that for Try.delayed(Supplier) this is an evaluating operation.

      Specified by:
      getOrElse in class Try<A>
      Parameters:
      s - called if this is a failure
      Returns:
      the wrapped value or the value from the Supplier
    • orElse

      public Try<A> orElse(Supplier<? extends Try<? extends A>> orElse)
      Description copied from class: Try
      If this is a success, return the same success. Otherwise, return value supplied by orElse.

      Note that for Try.delayed(Supplier) this is not an evaluating operation.

      Specified by:
      orElse in class Try<A>
      Parameters:
      orElse - try to return if this is failure
      Returns:
      this or orElse
    • filterOrElse

      public Try<A> filterOrElse(Predicate<? super A> p, Supplier<Exception> orElseSupplier)
      Description copied from class: Try
      Return a Success if this is a Success and the contained values satisfies the given predicate.

      If this is a Success but the predicate is not satisfied, return a Failure with the value provided by the orElseSupplier.

      Return a Failure if this a Failure with the contained value.

      Note that for Try.delayed(Supplier) this is not an evaluating operation.

      Specified by:
      filterOrElse in class Try<A>
      Parameters:
      p - The predicate function to test on the right contained value.
      orElseSupplier - The supplier to execute when is a success, and predicate is unsatisfied
      Returns:
      a new Try that will be either the existing success/failure or a failure with result of orElseSupplier
    • fold

      public <B> B fold(Function<? super Exception,B> failureF, Function<A,B> successF)
      Description copied from class: Try
      Applies the function to the wrapped value, applying failureF it this is a Failure and successF if this is a Success.

      Note that for Try.delayed(Supplier) this is an evaluating operation.

      Specified by:
      fold in class Try<A>
      Type Parameters:
      B - the destination type
      Parameters:
      failureF - the function to apply if this is a Failure
      successF - the function to apply if this is a Success
      Returns:
      the result of the applied function
    • toEither

      public Either<Exception,A> toEither()
      Description copied from class: Try
      Convert this Try to an Either, becoming a left if this is a failure and a right if this is a success.

      Note that for Try.delayed(Supplier) this is an evaluating operation.

      Specified by:
      toEither in class Try<A>
      Returns:
      this value wrapped in right if a success, and the exception wrapped in a left if a failure.
    • toOption

      public Option<A> toOption()
      Description copied from class: Try
      Convert this Try to an Option. Returns Some with a value if it is a success, otherwise None.

      Note that for Try.delayed(Supplier) this is an evaluating operation.

      Specified by:
      toOption in class Try<A>
      Returns:
      The success's value in Some if it exists, otherwise None
    • toOptional

      public Optional<A> toOptional()
      Description copied from class: Try
      Create a Optional from this try.

      Note that for Try.delayed(Supplier) this is an evaluating operation.

      Specified by:
      toOptional in class Try<A>
      Returns:
      Optional.of(Object) with the value if success, Optional.empty() if failure.
    • toStream

      public Stream<A> toStream()
      Description copied from class: Try
      Create a Stream from this try.

      Note that for Try.delayed(Supplier) this is an evaluating operation.

      Specified by:
      toStream in class Try<A>
      Returns:
      Stream.of(Object) with the value if success, Stream.empty() if failure.
    • forEach

      public void forEach(Consumer<? super A> action)
      Description copied from class: Try
      Perform the given Consumer (side-effect) for the success if success value.

      Note that for Try.delayed(Supplier) this is an evaluating operation.

      Specified by:
      forEach in interface Iterable<A>
      Specified by:
      forEach in class Try<A>
      Parameters:
      action - the Consumer to apply on the success value
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object