Java Reference
In-Depth Information
public void ifNotPresent(Consumer<? super Exception> consumer) {
Objects.requireNonNull(consumer, "the consumer to apply");
exception.ifPresent(consumer);
}
/**
* Executes the given function against the result, if we have a result.
*
* @param function The function to apply; never {@code null}.
* @return The result of processing the function, which may be
* this exception, the exception during processing, or the
* object returned by the function; never {@code null}.
*/
public <RESULT2_T> Result<RESULT2_T> map(
Function<RESULT_T, RESULT2_T> function
) {
Objects.requireNonNull(function, "mapping function");
try {
return new Result<>(function.apply(getOrDie()));
} catch (Exception e) {
return new Result<>(e);
}
}
/**
* Applies the given consumer if there is a result; otherwise, does nothing.
*
* @param resultHandler The handler for results; never {@code null}
* @return {@code this} for chaining
*/
public Result<RESULT_T> whenResult(Consumer<RESULT_T> resultHandler) {
Objects.requireNonNull(resultHandler, "result handler");
result.ifPresent(resultHandler);
return this;
}
/**
* Applies the given consumer if there is an exception; otherwise,
* does nothing.
*
* @param exceptionHandler The handler for exceptions; never {@code null}
* @return {@code this} for chaining
*/
public Result<RESULT_T> whenException(Consumer<Exception> exceptionHandler) {
Objects.requireNonNull(exceptionHandler, "exception handler");
exception.ifPresent(exceptionHandler);
return this;
}
/**
* Applies the given consumer if there is an exception of the given type;
* otherwise, does nothing.
*
Search WWH ::




Custom Search