public class Results extends Object
Result instances.Creating Results,
Result| Modifier and Type | Method and Description |
|---|---|
static <S,F> Result<S,F> |
failure(F failure)
Creates a new failed
Result. |
static <S> Result<S,Exception> |
ofCallable(Callable<? extends S> task)
|
static <S,F> Result<S,F> |
ofNullable(S success,
F failure)
Creates a new
Result based on a possibly-null success value and a non-null failure value. |
static <S,F> Result<S,F> |
ofNullable(S success,
Supplier<? extends F> failureSupplier)
|
static <S,F> Result<S,F> |
ofOptional(Optional<S> success,
F failure)
|
static <S,F> Result<S,F> |
ofOptional(Optional<S> success,
Supplier<? extends F> failureSupplier)
|
static <S,F> Result<S,F> |
success(S success)
Creates a new successful
Result. |
public static <S,F> Result<S,F> success(S success)
Result.S - the success type of the ResultF - the failure type of the Resultsuccess - the success valueResult holding successNullPointerException - if success is nullpublic static <S,F> Result<S,F> failure(F failure)
Result.S - the success type of the ResultF - the failure type of the Resultfailure - the failure valueResult holding failureNullPointerException - if failure is nullpublic static <S,F> Result<S,F> ofNullable(S success, F failure)
Result based on a possibly-null success value and a non-null failure value.S - the success type of the ResultF - the failure type of the Resultsuccess - the success value to use if non-nullfailure - the failure value to use if success is nullResult holding success if non-null; otherwise, a failed Result
holding failureNullPointerException - if both success and failure are nullpublic static <S,F> Result<S,F> ofNullable(S success, Supplier<? extends F> failureSupplier)
S - the success type of the ResultF - the failure type of the Resultsuccess - the success value to use if non-nullfailureSupplier - the Supplier that produces a failure valueResult holding success if non-null; otherwise, a failed Result
holding the value produced by failureSupplierNullPointerException - if both success and failureSupplier are null, or if failureSupplier returns nullpublic static <S,F> Result<S,F> ofOptional(Optional<S> success, F failure)
S - the success type of the ResultF - the failure type of the Resultsuccess - the Optional success value to use if non-emptyfailure - the failure value to use if success is emptyResult holding the Optional success value if non-empty; otherwise, a failed
Result holding failureNullPointerException - if success is null; or if success is empty and
failure is nullpublic static <S,F> Result<S,F> ofOptional(Optional<S> success, Supplier<? extends F> failureSupplier)
S - the success type of the resultF - the failure type of the resultsuccess - the Optional success value to use if non-emptyfailureSupplier - the Supplier that produces a failure valueResult holding the Optional success value if non-empty; otherwise, a failed
Result holding the value produced by failureSupplierNullPointerException - if success is null; or if success is empty and
failureSupplier is null or returns nullpublic static <S> Result<S,Exception> ofCallable(Callable<? extends S> task)
S - the success type of the Resulttask - the Callable that produces a success value, or throws an Exception if unable to do soResult holding the value produced by task if it completed as intended;
otherwise a failed Result holding the Exception thrown by taskNullPointerException - if task is null or returns null