Class Try.Delayed<A>
- java.lang.Object
-
- io.atlassian.fugue.Try<A>
-
- io.atlassian.fugue.Try.Delayed<A>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicReference<java.util.function.Function<Unit,Try<A>>>runReferenceprivate static longserialVersionUID
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private <B> Try<B>composeDelayed(java.util.function.Function<Try<A>,Try<B>> f)private Try<A>eval()Try<A>filterOrElse(java.util.function.Predicate<? super A> p, java.util.function.Supplier<java.lang.Exception> orElseSupplier)Return aSuccessif this is aSuccessand the contained values satisfies the given predicate.<B> Try<B>flatMap(java.util.function.Function<? super A,Try<B>> f)Binds the given function across the success value if it is one.<B> Bfold(java.util.function.Function<? super java.lang.Exception,B> failureF, java.util.function.Function<A,B> successF)Applies the function to the wrapped value, applying failureF it this is a Failure and successF if this is a Success.voidforEach(java.util.function.Consumer<? super A> action)Perform the givenConsumer(side-effect) for the successif successvalue.(package private) static <A> Try.Delayed<A>fromSupplier(java.util.function.Supplier<Try<A>> delayed)AgetOrElse(java.util.function.Supplier<A> s)Returns the contained value if this is a success otherwise call the supplier and return its value.private java.util.function.Function<Unit,Try<A>>getRunner()booleanisFailure()Returnstrueif this failure, otherwisefalsebooleanisSuccess()Returnstrueif this success, otherwisefalse<B> Try<B>map(java.util.function.Function<? super A,? extends B> f)Maps the given function to the value from this `Success` or returns this unchanged if a `Failure`.Try<A>orElse(java.util.function.Supplier<? extends Try<? extends A>> orElse)If this is a success, return the same success.voidreadExternal(java.io.ObjectInput in)<X extends java.lang.Exception>
Try<A>recover(java.lang.Class<X> exceptionType, java.util.function.Function<? super X,A> f)Applies the given function `f` if this is a `Failure` with certain exception type otherwise leaves this unchanged.Try<A>recover(java.util.function.Function<? super java.lang.Exception,A> f)Applies the given function `f` if this is a `Failure` otherwise this unchanged if a 'Success'.<X extends java.lang.Exception>
Try<A>recoverWith(java.lang.Class<X> exceptionType, java.util.function.Function<? super X,Try<A>> f)Binds the given function across certain exception type if it is one, otherwise this unchanged.Try<A>recoverWith(java.util.function.Function<? super java.lang.Exception,Try<A>> f)Binds the given function across the failure value if it is one, otherwise this unchanged if a 'Success'.Either<java.lang.Exception,A>toEither()Convert this Try to anEither, becoming a left if this is a failure and a right if this is a success.Option<A>toOption()Convert this Try to an Option.java.util.Optional<A>toOptional()Create aOptionalfrom this try.java.util.stream.Stream<A>toStream()Create aStreamfrom this try.voidwriteExternal(java.io.ObjectOutput out)-
Methods inherited from class io.atlassian.fugue.Try
delayed, failure, flatten, iterator, orElse, sequence, sequence, successful
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
fromSupplier
static <A> Try.Delayed<A> fromSupplier(java.util.function.Supplier<Try<A>> delayed)
-
isFailure
public boolean isFailure()
Description copied from class:TryReturnstrueif this failure, otherwisefalseNote that for
Try.delayed(Supplier)this is an evaluating operation.
-
isSuccess
public boolean isSuccess()
Description copied from class:TryReturnstrueif this success, otherwisefalseNote that for
Try.delayed(Supplier)this is an evaluating operation.
-
flatMap
public <B> Try<B> flatMap(java.util.function.Function<? super A,Try<B>> f)
Description copied from class:TryBinds the given function across the success value if it is one.Note that for
Try.delayed(Supplier)this is not an evaluating operation.
-
map
public <B> Try<B> map(java.util.function.Function<? super A,? extends B> f)
Description copied from class:TryMaps 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.
-
recover
public Try<A> recover(java.util.function.Function<? super java.lang.Exception,A> f)
Description copied from class:TryApplies 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.
-
recover
public <X extends java.lang.Exception> Try<A> recover(java.lang.Class<X> exceptionType, java.util.function.Function<? super X,A> f)
Description copied from class:TryApplies 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.
-
recoverWith
public Try<A> recoverWith(java.util.function.Function<? super java.lang.Exception,Try<A>> f)
Description copied from class:TryBinds 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:
recoverWithin classTry<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 java.lang.Exception> Try<A> recoverWith(java.lang.Class<X> exceptionType, java.util.function.Function<? super X,Try<A>> f)
Description copied from class:TryBinds 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:
recoverWithin classTry<A>- Type Parameters:
X- exception type- Parameters:
exceptionType- exception classf- 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(java.util.function.Supplier<A> s)
Description copied from class:TryReturns 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.
-
orElse
public Try<A> orElse(java.util.function.Supplier<? extends Try<? extends A>> orElse)
Description copied from class:TryIf this is a success, return the same success. Otherwise, return value supplied byorElse.Note that for
Try.delayed(Supplier)this is not an evaluating operation.
-
filterOrElse
public Try<A> filterOrElse(java.util.function.Predicate<? super A> p, java.util.function.Supplier<java.lang.Exception> orElseSupplier)
Description copied from class:TryReturn aSuccessif this is aSuccessand the contained values satisfies the given predicate.If this is a
Successbut the predicate is not satisfied, return aFailurewith the value provided by the orElseSupplier.Return a
Failureif this aFailurewith the contained value.Note that for
Try.delayed(Supplier)this is not an evaluating operation.- Specified by:
filterOrElsein classTry<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(java.util.function.Function<? super java.lang.Exception,B> failureF, java.util.function.Function<A,B> successF)Description copied from class:TryApplies 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.
-
toEither
public Either<java.lang.Exception,A> toEither()
Description copied from class:TryConvert this Try to anEither, 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.
-
toOption
public Option<A> toOption()
Description copied from class:TryConvert this Try to an Option. ReturnsSomewith a value if it is a success, otherwiseNone.Note that for
Try.delayed(Supplier)this is an evaluating operation.
-
toOptional
public java.util.Optional<A> toOptional()
Description copied from class:TryCreate aOptionalfrom this try.Note that for
Try.delayed(Supplier)this is an evaluating operation.- Specified by:
toOptionalin classTry<A>- Returns:
Optional.of(Object)with the value if success,Optional.empty()if failure.
-
toStream
public java.util.stream.Stream<A> toStream()
Description copied from class:TryCreate aStreamfrom this try.Note that for
Try.delayed(Supplier)this is an evaluating operation.
-
forEach
public void forEach(java.util.function.Consumer<? super A> action)
Description copied from class:TryPerform the givenConsumer(side-effect) for the successif successvalue.Note that for
Try.delayed(Supplier)this is an evaluating operation.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
-