Interface FunctionWithException<T,R,E extends Exception>
-
- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the potential exception of the function
- All Superinterfaces:
ExceptionHandlerSupport<Function<T,R>,Function<T,Optional<R>>,FunctionWithException<T,R,E>>
,ObjectReturnExceptionHandlerSupport<Function<T,R>,Function<T,Optional<R>>,Function<T,CompletionStage<R>>,R,FunctionWithException<T,R,E>>
- All Known Subinterfaces:
UnaryOperatorWithException<T,E>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface FunctionWithException<T,R,E extends Exception> extends ObjectReturnExceptionHandlerSupport<Function<T,R>,Function<T,Optional<R>>,Function<T,CompletionStage<R>>,R,FunctionWithException<T,R,E>>
Represents a function that accepts one argument, may throw exception and produces a result.General contract
R apply(T t) throws E
- The functional method.- uncheck - Return a
Function<T, R>
- lift - Return a
Function<T, Optional<R>>
- ignore - Return a
Function<T, R>
- See Also:
Function
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <V> FunctionWithException<T,V,E>
andThen(FunctionWithException<? 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.R
apply(T t)
Applies this function to the given argument.default <U> BiFunctionWithException<T,U,R,E>
asBiFunction()
Converts aFunctionWithException
to aBiFunctionWithException
.static <T,U,R,E extends Exception>
BiFunctionWithException<T,U,R,E>asBiFunction(FunctionWithException<T,R,E> function)
Converts aFunctionWithException
to aBiFunctionWithException
.static <T,R,E extends Exception>
Callable<R>asCallable(FunctionWithException<T,R,E> function, T t)
Converts aFunctionWithException
to aCallable
.default Callable<R>
asCallable(T t)
Converts aFunctionWithException
to aCallable
.default ConsumerWithException<T,E>
asConsumer()
Converts aFunctionWithException
to aConsumerWithException
.static <T,R,E extends Exception>
ConsumerWithException<T,E>asConsumer(FunctionWithException<T,R,E> function)
Converts aFunctionWithException
to aConsumerWithException
.static <T,R,E extends Exception>
RunnableWithException<E>asRunnable(FunctionWithException<T,R,E> function, T t)
Converts aFunctionWithException
to aRunnableWithException
.default RunnableWithException<E>
asRunnable(T t)
Converts aFunctionWithException
to aRunnableWithException
.static <T,R,E extends Exception>
SupplierWithException<R,E>asSupplier(FunctionWithException<T,R,E> function, T t)
Converts aFunctionWithException
to aSupplierWithException
.default SupplierWithException<R,E>
asSupplier(T t)
Converts aFunctionWithException
to aSupplierWithException
.default <V> FunctionWithException<V,R,E>
compose(FunctionWithException<? 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.static <T,R,E extends Exception>
FunctionWithException<T,R,E>failing(Supplier<E> exceptionBuilder)
Returns a function that always throw exception.static <T,E extends Exception>
FunctionWithException<T,T,E>identity()
Returns a function that always returns its input argument.default Function<T,R>
ignore()
Converts thisFunctionWithException
to a liftedFunction
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.static <T,R,E extends Exception>
Function<T,R>ignored(FunctionWithException<T,R,E> function)
Converts aFunctionWithException
to a liftedFunction
returningnull
in case of exception.static <T,R,E extends Exception>
Function<T,R>ignored(FunctionWithException<T,R,E> function, R defaultValue)
Converts aFunctionWithException
to a liftedFunction
returning a default value in case of exception.default Function<T,Optional<R>>
lift()
Converts thisFunctionWithException
to a liftedFunction
usingOptional
as return value.static <T,R,E extends Exception>
Function<T,Optional<R>>lifted(FunctionWithException<T,R,E> function)
Converts aFunctionWithException
to a liftedFunction
usingOptional
as return value.default Function<T,CompletionStage<R>>
stage()
Convert thisFunctionWithException
to a liftedFunction
returnCompletionStage
as return value.static <T,R,E extends Exception>
Function<T,CompletionStage<R>>staged(FunctionWithException<T,R,E> function)
Convert thisFunctionWithException
to a liftedFunction
returnCompletionStage
as return value.default Function<T,R>
uncheck()
Converts thisFunctionWithException
to aFunction
that convert exception toRuntimeException
.static <T,R,E extends Exception>
Function<T,R>unchecked(FunctionWithException<T,R,E> function)
Converts aFunctionWithException
to aFunction
that convert exception toRuntimeException
.static <T,R,E extends Exception>
Function<T,R>unchecked(FunctionWithException<T,R,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aFunctionWithException
to aFunction
that wraps exception toRuntimeException
by using the provided mapping function.-
Methods inherited from interface ch.powerunit.extensions.exceptions.ExceptionHandlerSupport
documented, exceptionMapper
-
Methods inherited from interface ch.powerunit.extensions.exceptions.ObjectReturnExceptionHandlerSupport
defaultValue, notThrowingHandler, throwingHandler
-
-
-
-
Method Detail
-
apply
R apply(T t) throws E extends Exception
Applies this function to the given argument.- Parameters:
t
- the function argument- Returns:
- the function result
- Throws:
E
- any exceptionE extends Exception
- See Also:
Function.apply(Object)
-
uncheck
default Function<T,R> uncheck()
Converts thisFunctionWithException
to aFunction
that convert exception toRuntimeException
.- Specified by:
uncheck
in interfaceExceptionHandlerSupport<T,R,E extends Exception>
- Specified by:
uncheck
in interfaceObjectReturnExceptionHandlerSupport<Function<T,R>,Function<T,Optional<R>>,Function<T,CompletionStage<R>>,R,FunctionWithException<T,R,E extends Exception>>
- Returns:
- the unchecked function
- See Also:
unchecked(FunctionWithException)
,unchecked(FunctionWithException, Function)
,Function
-
lift
default Function<T,Optional<R>> lift()
Converts thisFunctionWithException
to a liftedFunction
usingOptional
as return value.- Specified by:
lift
in interfaceExceptionHandlerSupport<T,R,E extends Exception>
- Specified by:
lift
in interfaceObjectReturnExceptionHandlerSupport<Function<T,R>,Function<T,Optional<R>>,Function<T,CompletionStage<R>>,R,FunctionWithException<T,R,E extends Exception>>
- Returns:
- the lifted function
- See Also:
lifted(FunctionWithException)
,Function
-
ignore
default Function<T,R> ignore()
Converts thisFunctionWithException
to a liftedFunction
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.- Specified by:
ignore
in interfaceExceptionHandlerSupport<T,R,E extends Exception>
- Specified by:
ignore
in interfaceObjectReturnExceptionHandlerSupport<Function<T,R>,Function<T,Optional<R>>,Function<T,CompletionStage<R>>,R,FunctionWithException<T,R,E extends Exception>>
- Returns:
- the function that ignore error
- See Also:
ignored(FunctionWithException)
,Function
-
stage
default Function<T,CompletionStage<R>> stage()
Convert thisFunctionWithException
to a liftedFunction
returnCompletionStage
as return value.- Specified by:
stage
in interfaceObjectReturnExceptionHandlerSupport<Function<T,R>,Function<T,Optional<R>>,Function<T,CompletionStage<R>>,R,FunctionWithException<T,R,E extends Exception>>
- Returns:
- the lifted function
- See Also:
staged(FunctionWithException)
,CompletionStage
-
compose
default <V> FunctionWithException<V,R,E> compose(FunctionWithException<? 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(FunctionWithException)
,Function.compose(Function)
-
andThen
default <V> FunctionWithException<T,V,E> andThen(FunctionWithException<? 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:
compose(FunctionWithException)
,Function.andThen(Function)
-
identity
static <T,E extends Exception> FunctionWithException<T,T,E> identity()
Returns a function that always returns its input argument.- Type Parameters:
T
- the type of the input and output objects to the functionE
- the type of the potential exception- Returns:
- a function that always returns its input argument
- See Also:
Function.identity()
-
failing
static <T,R,E extends Exception> FunctionWithException<T,R,E> failing(Supplier<E> exceptionBuilder)
Returns a function that always throw exception.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the exception- Parameters:
exceptionBuilder
- the supplier to create the exception- Returns:
- a function that always throw exception
-
unchecked
static <T,R,E extends Exception> Function<T,R> unchecked(FunctionWithException<T,R,E> function)
Converts aFunctionWithException
to aFunction
that convert exception toRuntimeException
.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be unchecked- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if function is null- See Also:
uncheck()
,unchecked(FunctionWithException, Function)
-
unchecked
static <T,R,E extends Exception> Function<T,R> unchecked(FunctionWithException<T,R,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aFunctionWithException
to aFunction
that wraps exception toRuntimeException
by using the provided mapping function.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- the be uncheckedexceptionMapper
- a function to convert the exception to the runtime exception.- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if function or exceptionMapper is null- See Also:
uncheck()
,unchecked(FunctionWithException)
-
lifted
static <T,R,E extends Exception> Function<T,Optional<R>> lifted(FunctionWithException<T,R,E> function)
Converts aFunctionWithException
to a liftedFunction
usingOptional
as return value.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be lifted- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- See Also:
lift()
-
ignored
static <T,R,E extends Exception> Function<T,R> ignored(FunctionWithException<T,R,E> function)
Converts aFunctionWithException
to a liftedFunction
returningnull
in case of exception.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be lifted- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- See Also:
ignore()
-
ignored
static <T,R,E extends Exception> Function<T,R> ignored(FunctionWithException<T,R,E> function, R defaultValue)
Converts aFunctionWithException
to a liftedFunction
returning a default value in case of exception.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be lifteddefaultValue
- the value to be returned in case of exception.- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- Since:
- 3.0.0
- See Also:
ignore()
,ignored(FunctionWithException)
-
staged
static <T,R,E extends Exception> Function<T,CompletionStage<R>> staged(FunctionWithException<T,R,E> function)
Convert thisFunctionWithException
to a liftedFunction
returnCompletionStage
as return value.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be lifted- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- See Also:
stage()
-
asConsumer
static <T,R,E extends Exception> ConsumerWithException<T,E> asConsumer(FunctionWithException<T,R,E> function)
Converts aFunctionWithException
to aConsumerWithException
.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be converter- Returns:
- the consumer
- Throws:
NullPointerException
- if function is null- Since:
- 1.2.0
-
asConsumer
default ConsumerWithException<T,E> asConsumer()
Converts aFunctionWithException
to aConsumerWithException
.- Returns:
- the consumer
- Since:
- 1.2.0
-
asBiFunction
static <T,U,R,E extends Exception> BiFunctionWithException<T,U,R,E> asBiFunction(FunctionWithException<T,R,E> function)
Converts aFunctionWithException
to aBiFunctionWithException
.- Type Parameters:
T
- the type of the input to the functionU
- the type of the second input to the functionR
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be converter- Returns:
- the function
- Throws:
NullPointerException
- if function is null- Since:
- 1.2.0
-
asBiFunction
default <U> BiFunctionWithException<T,U,R,E> asBiFunction()
Converts aFunctionWithException
to aBiFunctionWithException
.- Type Parameters:
U
- the type of the second input to the function- Returns:
- the function
- Since:
- 1.2.0
-
asSupplier
static <T,R,E extends Exception> SupplierWithException<R,E> asSupplier(FunctionWithException<T,R,E> function, T t)
Converts aFunctionWithException
to aSupplierWithException
.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be convertert
- The input to the function.- Returns:
- the supplier
- Throws:
NullPointerException
- if function is null- Since:
- 1.2.0
-
asSupplier
default SupplierWithException<R,E> asSupplier(T t)
Converts aFunctionWithException
to aSupplierWithException
.- Parameters:
t
- The input to the function.- Returns:
- the supplier
- Since:
- 1.2.0
-
asCallable
static <T,R,E extends Exception> Callable<R> asCallable(FunctionWithException<T,R,E> function, T t)
Converts aFunctionWithException
to aCallable
.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be convertert
- The input to the function.- Returns:
- the callable
- Throws:
NullPointerException
- if function is null- Since:
- 1.2.0
-
asCallable
default Callable<R> asCallable(T t)
Converts aFunctionWithException
to aCallable
.- Parameters:
t
- The input to the function.- Returns:
- the callable
- Since:
- 1.2.0
-
asRunnable
static <T,R,E extends Exception> RunnableWithException<E> asRunnable(FunctionWithException<T,R,E> function, T t)
Converts aFunctionWithException
to aRunnableWithException
.- Type Parameters:
T
- the type of the input to the functionR
- the type of the result of the functionE
- the type of the potential exception- Parameters:
function
- to be convertert
- The input to the function.- Returns:
- the Runnable
- Throws:
NullPointerException
- if function is null- Since:
- 1.2.0
-
asRunnable
default RunnableWithException<E> asRunnable(T t)
Converts aFunctionWithException
to aRunnableWithException
.- Parameters:
t
- The input to the function.- Returns:
- the Runnable
- Since:
- 1.2.0
-
-