public class Success<T> extends Try<T>
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
<U> Try<U> |
flatMap(ThrowingFunction<? super T,? extends Try<U>,? extends Throwable> mapper)
Applies a function on two values.
|
void |
forEach(ThrowingConsumer<? super T,? extends Throwable> consumer)
Accepts a consuming function and applies it to the value if it is a Success.
|
int |
hashCode() |
<U> Try<U> |
map(ThrowingFunction<? super T,? extends U,? extends Throwable> 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 Throwable> |
orElseRethrow()
Escapes the Try and enters a regular try-catch flow by rethowing the caught exception when a Failure
|
<X extends Throwable,Y extends Throwable> |
orElseThrow(Function<X,Y> throwableMapper)
Escapes the Try and enters a regular try-catch flow
|
Try<T> |
peek(ThrowingConsumer<? super T,? extends Throwable> 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<Throwable,? 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 Throwable,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 Success(T t)
public <U> Try<U> map(ThrowingFunction<? super T,? extends U,? extends Throwable> mapper)
Trypublic <U> Try<U> flatMap(ThrowingFunction<? super T,? extends Try<U>,? extends Throwable> mapper)
Trypublic void forEach(ThrowingConsumer<? super T,? extends Throwable> consumer)
Trypublic Try<T> peek(ThrowingConsumer<? super T,? extends Throwable> 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<Throwable,? extends U> failureFunc)
Trypublic Either<? extends Throwable,T> toEither()
Trypublic <X extends Throwable,Y extends Throwable> T orElseThrow(Function<X,Y> throwableMapper) throws Y extends Throwable
TryorElseThrow in class Try<T>X - any ThrowableY - any ThrowablethrowableMapper - Function to transform the Throwable if this is a FailureY - any ThrowableY extends Throwablepublic <E extends Throwable> T orElseRethrow() throws E extends Throwable
TryorElseRethrow in class Try<T>E - any ThrowableE - any ThrowableE extends ThrowableCopyright © 2014–2015. All rights reserved.