public class Failure<T> extends Try<T>
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
Optional<Try<T>> |
filter(Predicate<T> predicate)
Applies a filter, where a match returns Success and Failure otherwise.
|
<U> Try<U> |
flatMap(ThrowingFunction<? super T,? extends Try<U>,? extends Exception> mapper)
Applies a function on two values.
|
void |
forEach(ThrowingConsumer<? super T,? extends Exception> consumer)
Accepts a consuming function and applies it to the value if it is a Success.
|
Exception |
getException() |
int |
hashCode() |
<U> Try<U> |
map(ThrowingFunction<? super T,? extends U,? extends Exception> mapper)
Applies a function on a value of type Success.
|
T |
orElse(T defaultValue)
Returns the value of the Success, or a default value of the same type if this is a Failure.
|
T |
orElseGet(Supplier<? extends T> defaultValue)
Returns the value of the Success, or lazily falls back to a supplied value of the same type
|
<E extends Exception> |
orElseRethrow()
Escapes the Try and enters a regular try-catch flow by rethowing the caught exception when a Failure
|
<X extends Exception,Y extends Exception> |
orElseThrow(Function<X,Y> ExceptionMapper)
Escapes the Try and enters a regular try-catch flow
|
Try<T> |
peek(ThrowingConsumer<? super T,? extends Exception> consumer)
Same as forEach but returns the Try for further chaining
|
Try<T> |
peekFailure(Consumer<Failure<T>> consumer)
Does nothing on Success, but accepts a consumer on Failure
|
<U> U |
recover(Function<? super T,? extends U> successFunc,
Function<Exception,? extends U> failureFunc)
Accepts two functions, the first applied if Success - returning the value,
the other executed if Failure, returning a fallback value.
|
Either<? extends Exception,T> |
toEither()
Creates an Either where the Left is the Failure and Right is the Success from this Try
|
Optional<T> |
toOptional()
Creates an Optional wrapping the value if Success.
|
String |
toString() |
public Failure(Exception e)
public Exception getException()
public <U> Try<U> map(ThrowingFunction<? super T,? extends U,? extends Exception> mapper)
Trypublic <U> Try<U> flatMap(ThrowingFunction<? super T,? extends Try<U>,? extends Exception> mapper)
Trypublic Optional<Try<T>> filter(Predicate<T> predicate)
Trypublic void forEach(ThrowingConsumer<? super T,? extends Exception> consumer)
Trypublic Try<T> peek(ThrowingConsumer<? super T,? extends Exception> consumer)
Trypublic Try<T> peekFailure(Consumer<Failure<T>> consumer)
TrypeekFailure in class Try<T>consumer - Consuming function with a failurepublic T orElse(T defaultValue)
Trypublic T orElseGet(Supplier<? extends T> defaultValue)
Trypublic Optional<T> toOptional()
TrytoOptional in class Try<T>public <U> U recover(Function<? super T,? extends U> successFunc, Function<Exception,? extends U> failureFunc)
Trypublic Either<? extends Exception,T> toEither()
Trypublic <X extends Exception,Y extends Exception> T orElseThrow(Function<X,Y> ExceptionMapper) throws Y extends Exception
TryorElseThrow in class Try<T>X - any ExceptionY - any ExceptionExceptionMapper - Function to transform the Exception if this is a FailureY - any ExceptionY extends Exceptionpublic <E extends Exception> T orElseRethrow() throws E extends Exception
TryorElseRethrow in class Try<T>E - any ExceptionE - any ExceptionE extends ExceptionCopyright © 2014–2016. All rights reserved.