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 theafterfunction to the result.Rapply(T t)Applies this function to the given argument.default <U> BiFunctionWithException<T,U,R,E>asBiFunction()Converts aFunctionWithExceptionto aBiFunctionWithException.static <T,U,R,E extends Exception>
BiFunctionWithException<T,U,R,E>asBiFunction(FunctionWithException<T,R,E> function)Converts aFunctionWithExceptionto aBiFunctionWithException.static <T,R,E extends Exception>
Callable<R>asCallable(FunctionWithException<T,R,E> function, T t)Converts aFunctionWithExceptionto aCallable.default Callable<R>asCallable(T t)Converts aFunctionWithExceptionto aCallable.default ConsumerWithException<T,E>asConsumer()Converts aFunctionWithExceptionto aConsumerWithException.static <T,R,E extends Exception>
ConsumerWithException<T,E>asConsumer(FunctionWithException<T,R,E> function)Converts aFunctionWithExceptionto aConsumerWithException.static <T,R,E extends Exception>
RunnableWithException<E>asRunnable(FunctionWithException<T,R,E> function, T t)Converts aFunctionWithExceptionto aRunnableWithException.default RunnableWithException<E>asRunnable(T t)Converts aFunctionWithExceptionto aRunnableWithException.static <T,R,E extends Exception>
SupplierWithException<R,E>asSupplier(FunctionWithException<T,R,E> function, T t)Converts aFunctionWithExceptionto aSupplierWithException.default SupplierWithException<R,E>asSupplier(T t)Converts aFunctionWithExceptionto aSupplierWithException.default <V> FunctionWithException<V,R,E>compose(FunctionWithException<? super V,? extends T,? extends E> before)Returns a composed function that first applies thebeforefunction 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 thisFunctionWithExceptionto a liftedFunctionreturningnull(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 aFunctionWithExceptionto a liftedFunctionreturningnullin case of exception.static <T,R,E extends Exception>
Function<T,R>ignored(FunctionWithException<T,R,E> function, R defaultValue)Converts aFunctionWithExceptionto a liftedFunctionreturning a default value in case of exception.default Function<T,Optional<R>>lift()Converts thisFunctionWithExceptionto a liftedFunctionusingOptionalas return value.static <T,R,E extends Exception>
Function<T,Optional<R>>lifted(FunctionWithException<T,R,E> function)Converts aFunctionWithExceptionto a liftedFunctionusingOptionalas return value.default Function<T,CompletionStage<R>>stage()Convert thisFunctionWithExceptionto a liftedFunctionreturnCompletionStageas return value.static <T,R,E extends Exception>
Function<T,CompletionStage<R>>staged(FunctionWithException<T,R,E> function)Convert thisFunctionWithExceptionto a liftedFunctionreturnCompletionStageas return value.default Function<T,R>uncheck()Converts thisFunctionWithExceptionto aFunctionthat convert exception toRuntimeException.static <T,R,E extends Exception>
Function<T,R>unchecked(FunctionWithException<T,R,E> function)Converts aFunctionWithExceptionto aFunctionthat convert exception toRuntimeException.static <T,R,E extends Exception>
Function<T,R>unchecked(FunctionWithException<T,R,E> function, Function<Exception,RuntimeException> exceptionMapper)Converts aFunctionWithExceptionto aFunctionthat wraps exception toRuntimeExceptionby 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 thisFunctionWithExceptionto aFunctionthat convert exception toRuntimeException.- Specified by:
uncheckin interfaceExceptionHandlerSupport<T,R,E extends Exception>- Specified by:
uncheckin 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 thisFunctionWithExceptionto a liftedFunctionusingOptionalas return value.- Specified by:
liftin interfaceExceptionHandlerSupport<T,R,E extends Exception>- Specified by:
liftin 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 thisFunctionWithExceptionto a liftedFunctionreturningnull(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()) in case of exception.- Specified by:
ignorein interfaceExceptionHandlerSupport<T,R,E extends Exception>- Specified by:
ignorein 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 thisFunctionWithExceptionto a liftedFunctionreturnCompletionStageas return value.- Specified by:
stagein 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 thebeforefunction 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 thebeforefunction, and to the composed function- Parameters:
before- the function to apply before this function is applied- Returns:
- a composed function that first applies the
beforefunction 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 theafterfunction 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 theafterfunction, 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
afterfunction - 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 aFunctionWithExceptionto aFunctionthat 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 aFunctionWithExceptionto aFunctionthat wraps exception toRuntimeExceptionby 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 aFunctionWithExceptionto a liftedFunctionusingOptionalas 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 aFunctionWithExceptionto a liftedFunctionreturningnullin 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 aFunctionWithExceptionto a liftedFunctionreturning 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 thisFunctionWithExceptionto a liftedFunctionreturnCompletionStageas 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 aFunctionWithExceptionto 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 aFunctionWithExceptionto 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 aFunctionWithExceptionto 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 aFunctionWithExceptionto 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 aFunctionWithExceptionto 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 aFunctionWithExceptionto 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 aFunctionWithExceptionto 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 aFunctionWithExceptionto 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 aFunctionWithExceptionto 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 aFunctionWithExceptionto aRunnableWithException.- Parameters:
t- The input to the function.- Returns:
- the Runnable
- Since:
- 1.2.0
-
-