Package org.mycore.common.function
Interface MCRThrowFunction<T,R,E extends Throwable>
- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the exception that is throw by this function-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Represents a function that accepts one argument and produces a result and throws an Exception.
Use toFunction()
or toFunction(BiFunction, Class)
to transform this
MCRThrowFunction into a Function that can be handled throughout Java 8.
- Since:
- 2015.12
-
Method Summary
Modifier and TypeMethodDescriptiondefault <V> MCRThrowFunction<T,
V, E> andThen
(MCRThrowFunction<? super R, ? extends V, ? extends E> after) Returns a composed function that first applies this function to its input, and then applies theafter
function to the result.Applies this function to the given argument.default <V> MCRThrowFunction<V,
R, E> compose
(MCRThrowFunction<? super V, ? extends T, ? extends E> before) Returns a composed function that first applies thebefore
function to its input, and then applies this function to the result.Returns a Function that applies <T> and catches any exception and wraps it into aRuntimeException
if needed.toFunction
(BiFunction<T, E, R> throwableHandler, Class<? super E> exClass) Returns a function that catches <E> and forwards it to thethrowableHandler
together with the Exception.
-
Method Details
-
apply
Applies this function to the given argument. -
compose
default <V> MCRThrowFunction<V,R, composeE> (MCRThrowFunction<? super V, ? extends T, ? extends E> before) Returns a composed function that first applies thebefore
function to its input, and then applies this function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.- Type Parameters:
V
- the type of input to thebefore
function, and to the composed function- Parameters:
before
- the function to apply before this function is applied- Returns:
- a composed function that first applies the
before
function and then applies this function - Throws:
NullPointerException
- if before is null- See Also:
-
andThen
default <V> MCRThrowFunction<T,V, andThenE> (MCRThrowFunction<? super R, ? extends V, ? extends E> after) Returns a composed function that first applies this function to its input, and then applies theafter
function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.- Type Parameters:
V
- the type of output of theafter
function, and of the composed function- Parameters:
after
- the function to apply after this function is applied- Returns:
- a composed function that first applies this function and then
applies the
after
function - Throws:
NullPointerException
- if after is null- See Also:
-
toFunction
Returns a function that catches <E> and forwards it to thethrowableHandler
together with the Exception. Use this method if you want to react on the certain Exceptions and return a result or rethrow a specific RuntimeExption.- Parameters:
throwableHandler
- a BiFunction that handles original Input and caught ExceptionexClass
- class of exception to catch
-
toFunction
Returns a Function that applies <T> and catches any exception and wraps it into aRuntimeException
if needed. Use this if you just want no specific exception handling.
-