Java Reference
In-Depth Information
);
return ex;
}
);
}
/**
* Executes the given function against this result, if we have a result.
*
* @param function The function to apply; never {@code null}
* @return The result of the function in an {@link java.util.Optional} if
* we have a result, or the empty optional if there was no result.
*/
public <RETURN_T> Optional<RETURN_T> ifPresent(
Function<? super RESULT_T, RETURN_T> function
) {
Objects.requireNonNull(function, "the function to apply");
return result.map(function);
}
/**
* Executes the given consumer against this result, if we have a result.
* Otherwise, does nothing.
*
* @param consumer The consumer to apply; never {@code null}
*/
public void ifPresent(Consumer<? super RESULT_T> consumer) {
Objects.requireNonNull(consumer, "the consumer to apply");
result.ifPresent(consumer);
}
/**
* Executes the given function against this exception, if we have one.
*
* @param function The function to apply; never {@code null}
* @return The result of the function in an {@link java.util.Optional} if
* we have an exception, or the empty optional if there was no exception.
*/
public <RETURN_T> Optional<RETURN_T> ifNotPresent(
Function<? super Exception, RETURN_T> function
) {
Objects.requireNonNull(function, "the function to apply");
return exception.map(function);
}
/**
* Executes the given consumer against this exception, if we have
* an exception. Otherwise, does nothing.
*
* @param consumer The consumer to apply; never {@code null}
*/
Search WWH ::




Custom Search