Class Try.Delayed<A>
- All Implemented Interfaces:
Externalizable, Serializable, Iterable<A>
- Since:
- 4.4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicReference<Function<Unit, Try<A>>> private static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate <B> Try<B> composeDelayed(Function<Try<A>, Try<B>> f) eval()filterOrElse(Predicate<? super A> p, Supplier<Exception> orElseSupplier) Return aSuccessif this is aSuccessand the contained values satisfies the given predicate.<B> Try<B> Binds the given function across the success value if it is one.<B> BApplies the function to the wrapped value, applying failureF it this is a Failure and successF if this is a Success.voidPerform the givenConsumer(side-effect) for the successif successvalue.(package private) static <A> Try.Delayed<A> fromSupplier(Supplier<Try<A>> delayed) Returns the contained value if this is a success otherwise call the supplier and return its value.booleanReturnstrueif this failure, otherwisefalsebooleanReturnstrueif this success, otherwisefalse<B> Try<B> Maps the given function to the value from this `Success` or returns this unchanged if a `Failure`.If this is a success, return the same success.voidApplies the given function `f` if this is a `Failure` with certain exception type otherwise leaves this unchanged.Applies the given function `f` if this is a `Failure` otherwise this unchanged if a 'Success'.recoverWith(Class<X> exceptionType, Function<? super X, Try<A>> f) Binds the given function across certain exception type if it is one, otherwise this unchanged.recoverWith(Function<? super Exception, Try<A>> f) Binds the given function across the failure value if it is one, otherwise this unchanged if a 'Success'.toEither()Convert this Try to anEither, becoming a left if this is a failure and a right if this is a success.toOption()Convert this Try to an Option.Create aOptionalfrom this try.toStream()Create aStreamfrom this try.voidMethods inherited from class Try
delayed, failure, flatten, iterator, orElse, sequence, sequence, successfulMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
spliterator
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
runReference
-
-
Constructor Details
-
Delayed
public Delayed() -
Delayed
-
-
Method Details
-
fromSupplier
-
getRunner
-
eval
-
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. -
composeDelayed
-
flatMap
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
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
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
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
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 Exception> Try<A> recoverWith(Class<X> exceptionType, 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
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
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
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
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
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
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
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
Description copied from class:TryCreate aStreamfrom this try.Note that for
Try.delayed(Supplier)this is an evaluating operation.- Specified by:
toStreamin classTry<A>- Returns:
Stream.of(Object)with the value if success,Stream.empty()if failure.
-
forEach
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
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-