Class Results
java.lang.Object
com.leakyabstractions.result.core.Results
This class consists exclusively of static methods that return
Result instances.- Author:
- Guillermo Calvo
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <S,F> Result <S, F> failure(F failure) Creates a new failedResult.ofCallable(Callable<? extends S> task) ofCallable(Callable<? extends T> task, Function<? super T, ? extends S> mapper) static <S,F> Result <S, F> ofNullable(S success, F failure) Creates a newResultbased 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 successfulResult.
-
Method Details
-
success
Creates a new successfulResult.- Type Parameters:
S- the success type of theResultF- the failure type of theResult- Parameters:
success- the success value- Returns:
- a successful
Resultholdingsuccess - Throws:
NullPointerException- ifsuccessisnull
-
failure
Creates a new failedResult.- Type Parameters:
S- the success type of theResultF- the failure type of theResult- Parameters:
failure- the failure value- Returns:
- a failed
Resultholdingfailure - Throws:
NullPointerException- iffailureisnull
-
ofNullable
Creates a newResultbased on a possibly-null success value and a non-null failure value.- Type Parameters:
S- the success type of theResultF- the failure type of theResult- Parameters:
success- the success value to use if non-nullfailure- the failure value to use ifsuccessisnull- Returns:
- a successful
Resultholdingsuccessif non-null; otherwise, a failedResultholdingfailure - Throws:
NullPointerException- if bothsuccessandfailurearenull
-
ofNullable
- Type Parameters:
S- the success type of theResultF- the failure type of theResult- Parameters:
success- the success value to use if non-nullfailureSupplier- theSupplierthat produces a failure value- Returns:
- a successful
Resultholdingsuccessif non-null; otherwise, a failedResultholding the value produced byfailureSupplier - Throws:
NullPointerException- if bothsuccessandfailureSupplierarenull, or iffailureSupplierreturnsnull
-
ofOptional
- Type Parameters:
S- the success type of theResultF- the failure type of theResult- Parameters:
success- theOptionalsuccess value to use if non-emptyfailure- the failure value to use ifsuccessis empty- Returns:
- a successful
Resultholding theOptionalsuccess value if non-empty; otherwise, a failedResultholdingfailure - Throws:
NullPointerException- ifsuccessisnull; or ifsuccessis empty andfailureisnull
-
ofOptional
public static <S,F> Result<S,F> ofOptional(Optional<S> success, Supplier<? extends F> failureSupplier) - Type Parameters:
S- the success type of the resultF- the failure type of the result- Parameters:
success- theOptionalsuccess value to use if non-emptyfailureSupplier- theSupplierthat produces a failure value- Returns:
- a successful
Resultholding theOptionalsuccess value if non-empty; otherwise, a failedResultholding the value produced byfailureSupplier - Throws:
NullPointerException- ifsuccessisnull; or ifsuccessis empty andfailureSupplierisnullor returnsnull
-
ofCallable
- Type Parameters:
S- the success type of theResult- Parameters:
task- theCallablethat produces a success value, or throws anExceptionif unable to do so- Returns:
- a successful
Resultholding the value produced bytaskif it completed as intended; otherwise a failedResultholding theExceptionthrown bytask - Throws:
NullPointerException- iftaskisnullor returnsnull
-
ofCallable
public static <S,T> Result<S,Exception> ofCallable(Callable<? extends T> task, Function<? super T, ? extends S> mapper) - Type Parameters:
S- the success type of theResultT- the type returned by thetask- Parameters:
task- theCallablethat produces a possibly-null value, or throws anExceptionif unable to do somapper- the mappingFunctionthat transforms the value produced bytaskinto a success value, or throws anExceptionif unable to do so- Returns:
- a successful
Resultholding the value produced bytaskand transformed bymapperif both completed as intended; otherwise a failedResultholding theExceptionthrown by either one - Throws:
NullPointerException- if eithertaskormapperisnull, or ifmapperreturnsnull
-