Try.ResourceHandler<R extends AutoCloseable>, Try.ResourceHandler2<R1 extends AutoCloseable,R2 extends AutoCloseable>, Try.ResourceHandler3<R1 extends AutoCloseable,R2 extends AutoCloseable,R3 extends AutoCloseable>, Try.ResourceHandler4<R1 extends AutoCloseable,R2 extends AutoCloseable,R3 extends AutoCloseable,R4 extends AutoCloseable>, Try.Value<V>| Constructor and Description |
|---|
Value() |
| Modifier and Type | Method and Description |
|---|---|
<T> Try.Value<T> |
flatMap(Throwing.Function<V,Try.Value<T>> mapper)
Flat map the success value.
|
abstract V |
get()
Gets the success result or
Throwing.sneakyThrow(Throwable) the exception. |
<T> Try.Value<T> |
map(Throwing.Function<V,T> mapper)
Map the success value.
|
Try.Value<V> |
onComplete(Throwing.Consumer<Throwable> action)
Always run the given action, works like a finally clause.
|
Try.Value<V> |
onComplete(Throwing.Consumer2<V,Throwable> action)
Always run the given action, works like a finally clause.
|
Try.Value<V> |
onComplete(Throwing.Runnable action)
Always run the given action, works like a finally clause.
|
Try.Value<V> |
onFailure(Consumer<? super Throwable> action)
Run the given action if and only if this is a failure.
|
Try.Value<V> |
onSuccess(Consumer<V> action)
Run the given action if and only if this is a success.
|
Try.Value<V> |
onSuccess(Runnable action)
Run the given action if and only if this is a success.
|
V |
orElse(V value)
Get the success value or use the given default value on failure.
|
V |
orElseGet(Supplier<V> value)
Get the success value or use the given function on failure.
|
V |
orElseThrow(Throwing.Function<Throwable,Throwable> provider)
Get the success value or throw an exception created by the exception provider.
|
<X extends Throwable> |
recover(Class<X> exception,
Throwing.Function<X,V> fn)
Recover from failure if and only if the exception is a subclass of the given exception filter.
|
<X extends Throwable> |
recover(Class<X> exception,
V value)
Recover from failure if and only if the exception is a subclass of the given exception filter.
|
Try.Value<V> |
recover(Throwing.Function<Throwable,V> fn)
Recover from failure.
|
<X extends Throwable> |
recoverWith(Class<X> exception,
Throwing.Function<X,Try.Value<V>> fn)
Recover from failure if and only if the exception is a subclass of the given exception filter.
|
Try.Value<V> |
recoverWith(Throwing.Function<Throwable,Try.Value<V>> fn)
Recover from failure.
|
Optional<V> |
toOptional()
Get an empty optional in case of failure.
|
<X extends Throwable> |
unwrap(Class<? extends X> type)
In case of failure unwrap the exception provided by calling
Throwable.getCause(). |
Try.Value<V> |
unwrap(Throwing.Predicate<Throwable> predicate)
In case of failure unwrap the exception provided by calling
Throwable.getCause(). |
<X extends Throwable> |
wrap(Class<? extends X> predicate,
Throwing.Function<X,Throwable> wrapper)
In case of failure wrap an exception matching the given predicate to something else.
|
Try.Value<V> |
wrap(Throwing.Function<Throwable,Throwable> wrapper)
In case of failure wrap an exception matching the given predicate to something else.
|
<X extends Throwable> |
wrap(Throwing.Predicate<X> predicate,
Throwing.Function<X,Throwable> wrapper)
In case of failure wrap an exception matching the given predicate to something else.
|
public abstract V get()
Throwing.sneakyThrow(Throwable) the exception.Throwing.sneakyThrow(Throwable) the exception.public V orElseGet(Supplier<V> value)
value - Default value provider.public V orElse(V value)
value - Default value.public V orElseThrow(Throwing.Function<Throwable,Throwable> provider)
provider - Exception provider.public Try.Value<V> onComplete(Throwing.Runnable action)
onComplete in class Tryaction - Finally action.public Try.Value<V> onComplete(Throwing.Consumer<Throwable> action)
TryonComplete in class Tryaction - Finally action.public Try.Value<V> onComplete(Throwing.Consumer2<V,Throwable> action)
action - Finally action.public Try.Value<V> onFailure(Consumer<? super Throwable> action)
public Try.Value<V> onSuccess(Runnable action)
public Try.Value<V> onSuccess(Consumer<V> action)
action - Success listener.public Try.Value<V> recoverWith(Throwing.Function<Throwable,Try.Value<V>> fn)
fn - Recover function.public <X extends Throwable> Try.Value<V> recoverWith(Class<X> exception, Throwing.Function<X,Try.Value<V>> fn)
X - Exception type.exception - Exception filter.fn - Recover function.public Try.Value<V> recover(Throwing.Function<Throwable,V> fn)
fn - Recover function.public <X extends Throwable> Try.Value<V> recover(Class<X> exception, V value)
X - Exception type.exception - Exception filter.value - Recover value.public <X extends Throwable> Try.Value<V> recover(Class<X> exception, Throwing.Function<X,V> fn)
X - Exception type.exception - Exception filter.fn - Recover function.public <T> Try.Value<T> flatMap(Throwing.Function<V,Try.Value<T>> mapper)
T - New type.mapper - Mapper.public <T> Try.Value<T> map(Throwing.Function<V,T> mapper)
T - New type.mapper - Mapper.public Optional<V> toOptional()
public <X extends Throwable> Try.Value<V> unwrap(Class<? extends X> type)
TryThrowable.getCause().
Useful for clean/shorter stackstrace.
Example for InvocationTargetException:
Try.run(() -> {
Method m = ...;
m.invoke(...); //might throw InvocationTargetException
}).unwrap(InvocationTargetException.class)
.throwException();
public Try.Value<V> unwrap(Throwing.Predicate<Throwable> predicate)
TryThrowable.getCause().
Useful for clean/shorter stackstrace.
Example for InvocationTargetException:
Try.run(() -> {
Method m = ...;
m.invoke(...); //might throw InvocationTargetException
}).unwrap(InvocationTargetException.class::isInstance)
.throwException();
public Try.Value<V> wrap(Throwing.Function<Throwable,Throwable> wrapper)
Trypublic <X extends Throwable> Try.Value<V> wrap(Class<? extends X> predicate, Throwing.Function<X,Throwable> wrapper)
Trypublic <X extends Throwable> Try.Value<V> wrap(Throwing.Predicate<X> predicate, Throwing.Function<X,Throwable> wrapper)
TryCopyright © 2017. All rights reserved.