T - the result typepublic abstract class Result<T>
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T> Result<T> |
empty()
Returns an empty result
|
static <T> Result<T> |
eval(FailableFunction0<T> supplier)
Evaluates a given expression and returns a result according to the
expression result.
|
abstract java.lang.Throwable |
exception()
Returns the exception contained in the result
|
abstract <E> Result<E> |
flatMap(FailableFunction1<T,Result<E>> mapper)
Applies the mapping function to the value of the result and returns the
result returned by the mapping function.
|
abstract Result<T> |
flatMapException(FailableFunction1<java.lang.Throwable,Result<T>> mapper)
Applies the mapping function to the exception and returns the result
returned by it.
|
abstract T |
get()
Returns the value contained in the result
|
void |
ifEmpty(java.lang.Runnable runner)
Invokes the runnable if the result is empty
|
void |
ifErroneous(java.util.function.Consumer<java.lang.Throwable> consumer)
Evaluates the consumer with the exception if it exists
|
void |
ifPresent(java.util.function.Consumer<T> consumer)
Evaluates the consumer with the value if it exists
|
abstract boolean |
isEmpty()
Indicates if the result is an empty result.
|
abstract boolean |
isErroneous()
Indicates if the result is an error result.
|
abstract boolean |
isPresent()
Indicates if a value is present.
|
abstract <E> Result<E> |
map(FailableFunction1<T,E> mapper)
Applies the mapping function to the value of the result (if it exists).
|
abstract Result<T> |
mapException(FailableFunction1<java.lang.Throwable,T> mapper)
Applies the mapping function to the exception.
|
static <T> Result<T> |
of(T value)
Wraps a non-null value into a value result.
|
static <T> Result<T> |
ofException(java.lang.Throwable e)
Wraps an exception into an error result.
|
static <T> Result<T> |
ofNullable(T value)
Wraps a value into a value result.
|
T |
orNull()
Returns the value if it exists or
null otherwise |
public static <T> Result<T> empty()
public static <T> Result<T> of(T value)
value - the value to wrappublic static <T> Result<T> ofNullable(T value)
value - the value to wrappublic static <T> Result<T> ofException(java.lang.Throwable e)
e - the exception to wrappublic static <T> Result<T> eval(FailableFunction0<T> supplier)
supplier - the supplier to evaluatepublic abstract T get() throws java.util.NoSuchElementException
java.util.NoSuchElementException - if the result is no value resultpublic abstract java.lang.Throwable exception()
throws java.util.NoSuchElementException
java.util.NoSuchElementException - if the result is no error resultpublic abstract boolean isPresent()
true iff the result is a value resultpublic abstract boolean isErroneous()
true iff the result is an error resultpublic abstract boolean isEmpty()
true iff the result is an empty resultpublic abstract <E> Result<E> map(FailableFunction1<T,E> mapper)
mapper - the mapping functionpublic abstract <E> Result<E> flatMap(FailableFunction1<T,Result<E>> mapper)
mapper - the mapping functionpublic abstract Result<T> mapException(FailableFunction1<java.lang.Throwable,T> mapper)
mapper - the mapping functionpublic abstract Result<T> flatMapException(FailableFunction1<java.lang.Throwable,Result<T>> mapper)
mapper - the mapping functionpublic void ifPresent(java.util.function.Consumer<T> consumer)
consumer - the consumerpublic void ifErroneous(java.util.function.Consumer<java.lang.Throwable> consumer)
consumer - the consumerpublic void ifEmpty(java.lang.Runnable runner)
runner - the runnerpublic T orNull()
null otherwiseCopyright © 2018. All Rights Reserved.