Modifier and Type | Method and Description |
---|---|
static <S,F> Result<S,F> |
failure(F failure)
Creates a new failed result with a given value.
|
static <S> Result<S,Exception> |
ofCallable(Callable<? extends S> callable)
If the given
callable produces a success value, returns a new successful result with it; otherwise
returns a new failed result with the exception thrown by callable . |
static <S,F> Result<S,F> |
ofNullable(S value,
F failure)
If the given
value is not null , returns a new successful result with it; otherwise returns a new
failed result with failure . |
static <S,F> Result<S,F> |
ofNullable(S value,
Supplier<? extends F> failureSupplier)
If the given
value is not null , returns a new successful result with it; otherwise returns a new
failed result with a value produced by the given supplier function. |
static <S,F> Result<S,F> |
ofOptional(Optional<S> optional,
F failure)
If the given
optional is not empty, returns a new successful result with its value; otherwise returns a
new failed result with failure . |
static <S,F> Result<S,F> |
ofOptional(Optional<S> optional,
Supplier<? extends F> failureSupplier)
If the given
optional is not empty, returns a new successful result with its value; otherwise returns a
new failed result with a value produced by the given supplier function. |
static <S,F> Result<S,F> |
success(S success)
Creates a new successful result with a given value.
|
public static <S,F> Result<S,F> success(S success)
S
- the success type of the resultF
- the failure type of the resultsuccess
- the success valueNullPointerException
- if success
is null
public static <S,F> Result<S,F> failure(F failure)
S
- the success type of the resultF
- the failure type of the resultfailure
- the failure valueNullPointerException
- if failure
is null
public static <S,F> Result<S,F> ofNullable(S value, F failure)
value
is not null
, returns a new successful result with it; otherwise returns a new
failed result with failure
.S
- the success type of the resultF
- the failure type of the resultvalue
- the value to check if null
failure
- the failure value to use in case value
is null
NullPointerException
- if both value
and failure
are null
public static <S,F> Result<S,F> ofNullable(S value, Supplier<? extends F> failureSupplier)
value
is not null
, returns a new successful result with it; otherwise returns a new
failed result with a value produced by the given supplier function.S
- the success type of the resultF
- the failure type of the resultvalue
- the value to check if null
failureSupplier
- the supplier function that produces a failure valueNullPointerException
- if both value
and failureSupplier
are null
, or if failureSupplier
returns null
public static <S,F> Result<S,F> ofOptional(Optional<S> optional, F failure)
optional
is not empty, returns a new successful result with its value; otherwise returns a
new failed result with failure
.S
- the success type of the resultF
- the failure type of the resultoptional
- the optional to check if emptyfailure
- the failure value to use in case optional
is emptyNullPointerException
- if optional
is null
; or if optional
is empty and
failure
is null
public static <S,F> Result<S,F> ofOptional(Optional<S> optional, Supplier<? extends F> failureSupplier)
optional
is not empty, returns a new successful result with its value; otherwise returns a
new failed result with a value produced by the given supplier function.S
- the success type of the resultF
- the failure type of the resultoptional
- the optional to check if emptyfailureSupplier
- the supplier function that produces a failure valueNullPointerException
- if optional
is null
; or if optional
is empty and
failureSupplier
is null
; or if failureSupplier
returns null
public static <S> Result<S,Exception> ofCallable(Callable<? extends S> callable)
callable
produces a success value, returns a new successful result with it; otherwise
returns a new failed result with the exception thrown by callable
.S
- the success type of the resultcallable
- the task that produces a success value, or throws an exception if unable to do soNullPointerException
- if callable
is null
; or if callable
returns null