| Modifier and Type | Class and Description |
|---|---|
static class |
Try.CallingFailureOnSuccessValue |
static class |
Try.CallingSuccessOnFailureValue |
static interface |
Try.FunctionThrowingException<A> |
static class |
Try.LambdaException |
static class |
Try.UnmatchedFilterPredicate |
| Modifier and Type | Method and Description |
|---|---|
static <A> Try<A> |
doTry(Try.FunctionThrowingException<A> fn)
Create a Try object from a function that could potentially throw an exception and fail.
|
Throwable |
failure()
Returns the failure value if this is a failure.
|
Try<T> |
filter(java.util.function.Predicate<T> predicate)
Apply the predicate to the success value to determine whether this should really be a failure
|
<A> Try<A> |
flatMap(java.util.function.Function<T,Try<A>> fn)
Perform a flatmap over this instance
|
void |
foreach(java.util.function.Consumer<T> consumer)
Apply the supplied function to the success value if this is a success
|
static <A> Try<A> |
fromFailure(Throwable failureVal)
Create a failure instance of Try
|
static <A> Try<A> |
fromSuccess(A successVal)
Create a success instance of Try
|
T |
get()
Return the success value if this is a success or throw the failure value if this is a failure
|
T |
getOrElse(T defaultVal)
Return the success value or the supplied default if this is a failure instance
|
boolean |
isFailure()
Returns true if this instance holds a failure value
|
boolean |
isSuccess()
Returns true if this instance holds a success value
|
<A> Try<A> |
map(java.util.function.Function<T,A> fn)
Perform a map over this instance
|
Try<T> |
orElse(Try<T> defaultVal)
Return this instance if it is a success instance.
|
T |
success()
Returns the success value if this is a success.
|
Optional<T> |
toOptional()
Convert this to an
Optional |
public boolean isSuccess()
public boolean isFailure()
public T success()
Try.CallingSuccessOnFailureValuepublic Throwable failure()
Try.CallingFailureOnSuccessValuepublic <A> Try<A> flatMap(java.util.function.Function<T,Try<A>> fn)
A - Return type of flatmap functionfn - flatmap functionpublic <A> Try<A> map(java.util.function.Function<T,A> fn)
A - Return type of map functionfn - map functionpublic T get() throws Throwable
Throwable - if this is a failure instancepublic T getOrElse(T defaultVal)
defaultVal - Default value to return in case of failurepublic Try<T> orElse(Try<T> defaultVal)
defaultVal - Default value to return in case this is a failurepublic Optional<T> toOptional()
Optionalpublic Try<T> filter(java.util.function.Predicate<T> predicate)
predicate - Predicate to applypublic void foreach(java.util.function.Consumer<T> consumer)
consumer - Function to applypublic static <A> Try<A> fromSuccess(A successVal)
A - Type of the success valuesuccessVal - success value to wrap inside the Trypublic static <A> Try<A> fromFailure(Throwable failureVal)
A - Type of the success value if this were a successfailureVal - failure value to wrap inside the Trypublic static <A> Try<A> doTry(Try.FunctionThrowingException<A> fn)
A - Type of the return value from the functionfn - Function that could potentially throw an exceptionCopyright © 2015. All rights reserved.