Interface BiFunctionWithException<T,U,R,E extends Exception>
-
- Type Parameters:
T
- the type of the first argument to the functionU
- the type of the second argument to the functionR
- the type of the result of the functionE
- the type of the potential exception of the function
- All Superinterfaces:
ExceptionHandlerSupport<BiFunction<T,U,R>,BiFunction<T,U,Optional<R>>,BiFunctionWithException<T,U,R,E>>
,ObjectReturnExceptionHandlerSupport<BiFunction<T,U,R>,BiFunction<T,U,Optional<R>>,BiFunction<T,U,CompletionStage<R>>,R,BiFunctionWithException<T,U,R,E>>
- All Known Subinterfaces:
BinaryOperatorWithException<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 BiFunctionWithException<T,U,R,E extends Exception> extends ObjectReturnExceptionHandlerSupport<BiFunction<T,U,R>,BiFunction<T,U,Optional<R>>,BiFunction<T,U,CompletionStage<R>>,R,BiFunctionWithException<T,U,R,E>>
Represents a function that accepts two arguments, may thrown exception and produces a result. This is the two-arity specialization ofFunctionWithException
.General contract
R apply(T t, U u) throws E
- The functional method.- uncheck - Return a
BiFunction<T,U,R>
- lift - Return a
BiFunction<T,U,<Optional<R>>
- ignore - Return a
BiFunction<T,U,R>
- See Also:
BiFunction
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <V> BiFunctionWithException<T,U,V,E>
andThen(FunctionWithException<? super R,? extends V,? extends E> after)
Returns a composedFunctionWithException
that first applies thisFunctionWithException
to its input, and then applies theafter
FunctionWithException
to the result.R
apply(T t, U u)
Applies this function to the given arguments.default BiConsumerWithException<T,U,E>
asBiConsumer()
Converts aBiFunctionWithException
to aBiConsumerWithException
.static <T,U,R,E extends Exception>
BiConsumerWithException<T,U,E>asBiConsumer(BiFunctionWithException<T,U,R,E> function)
Converts aBiFunctionWithException
to aBiConsumerWithException
.static <T,U,R,E extends Exception>
FunctionWithException<T,R,E>asFunction(BiFunctionWithException<T,U,R,E> function, U u)
Converts aBiFunctionWithException
to aFunctionWithException
.default FunctionWithException<T,R,E>
asFunction(U u)
Converts aBiFunctionWithException
to aFunctionWithException
.static <T,U,R,E extends Exception>
BiFunctionWithException<T,U,R,E>failing(Supplier<E> exceptionBuilder)
Returns aFunctionWithException
that always throw exception.default BiFunction<T,U,R>
ignore()
Converts thisBiFunctionWithException
to a liftedBiFunction
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.static <T,U,R,E extends Exception>
BiFunction<T,U,R>ignored(BiFunctionWithException<T,U,R,E> function)
Converts aBiFunctionWithException
to a liftedBiFunction
returningnull
in case of exception.static <T,U,R,E extends Exception>
BiFunction<T,U,R>ignored(BiFunctionWithException<T,U,R,E> function, R defaultValue)
Converts aBiFunctionWithException
to a liftedBiFunction
returning a default in case of exception.default BiFunction<T,U,Optional<R>>
lift()
Converts thisBiFunctionWithException
to a liftedBiFunction
usingOptional
as return value.static <T,U,R,E extends Exception>
BiFunction<T,U,Optional<R>>lifted(BiFunctionWithException<T,U,R,E> function)
Converts aBiFunctionWithException
to a liftedBiFunction
usingOptional
as return value.default BiFunction<T,U,CompletionStage<R>>
stage()
Convert thisBiFunctionWithException
to a liftedBiFunction
that usesCompletionStage
as return value.static <T,U,R,E extends Exception>
BiFunction<T,U,CompletionStage<R>>staged(BiFunctionWithException<T,U,R,E> function)
Convert thisBiFunctionWithException
to a liftedBiFunction
returnCompletionStage
as return value.default BiFunction<T,U,R>
uncheck()
Converts thisBiFunctionWithException
to aBiFunction
that wraps exception toRuntimeException
.static <T,U,R,E extends Exception>
BiFunction<T,U,R>unchecked(BiFunctionWithException<T,U,R,E> function)
Converts aBiFunctionWithException
to aBiFunction
that convert exception toRuntimeException
.static <T,U,R,E extends Exception>
BiFunction<T,U,R>unchecked(BiFunctionWithException<T,U,R,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aBiFunctionWithException
to aBiFunction
that convert 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, U u) throws E extends Exception
Applies this function to the given arguments.- Parameters:
t
- the first function argumentu
- the second function argument- Returns:
- the function result
- Throws:
E
- any exceptionE extends Exception
- See Also:
BiFunction.apply(Object,Object)
-
uncheck
default BiFunction<T,U,R> uncheck()
Converts thisBiFunctionWithException
to aBiFunction
that wraps exception toRuntimeException
.- Specified by:
uncheck
in interfaceExceptionHandlerSupport<T,U,R>
- Specified by:
uncheck
in interfaceObjectReturnExceptionHandlerSupport<BiFunction<T,U,R>,BiFunction<T,U,Optional<R>>,BiFunction<T,U,CompletionStage<R>>,R,BiFunctionWithException<T,U,R,E extends Exception>>
- Returns:
- the unchecked function
- See Also:
unchecked(BiFunctionWithException)
,unchecked(BiFunctionWithException, Function)
,BiFunction
-
lift
default BiFunction<T,U,Optional<R>> lift()
Converts thisBiFunctionWithException
to a liftedBiFunction
usingOptional
as return value.- Specified by:
lift
in interfaceExceptionHandlerSupport<T,U,R>
- Specified by:
lift
in interfaceObjectReturnExceptionHandlerSupport<BiFunction<T,U,R>,BiFunction<T,U,Optional<R>>,BiFunction<T,U,CompletionStage<R>>,R,BiFunctionWithException<T,U,R,E extends Exception>>
- Returns:
- the lifted function
- See Also:
lifted(BiFunctionWithException)
,BiFunction
-
ignore
default BiFunction<T,U,R> ignore()
Converts thisBiFunctionWithException
to a liftedBiFunction
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.- Specified by:
ignore
in interfaceExceptionHandlerSupport<T,U,R>
- Specified by:
ignore
in interfaceObjectReturnExceptionHandlerSupport<BiFunction<T,U,R>,BiFunction<T,U,Optional<R>>,BiFunction<T,U,CompletionStage<R>>,R,BiFunctionWithException<T,U,R,E extends Exception>>
- Returns:
- the function that ignore error
- See Also:
ignored(BiFunctionWithException)
,BiFunction
-
stage
default BiFunction<T,U,CompletionStage<R>> stage()
Convert thisBiFunctionWithException
to a liftedBiFunction
that usesCompletionStage
as return value.- Specified by:
stage
in interfaceObjectReturnExceptionHandlerSupport<BiFunction<T,U,R>,BiFunction<T,U,Optional<R>>,BiFunction<T,U,CompletionStage<R>>,R,BiFunctionWithException<T,U,R,E extends Exception>>
- Returns:
- the lifted function
- See Also:
staged(BiFunctionWithException)
,BiFunction
,CompletionStage
-
andThen
default <V> BiFunctionWithException<T,U,V,E> andThen(FunctionWithException<? super R,? extends V,? extends E> after)
Returns a composedFunctionWithException
that first applies thisFunctionWithException
to its input, and then applies theafter
FunctionWithException
to the result. If evaluation of eitherFunctionWithException
throws an exception, it is relayed to the caller of the composed function.- Type Parameters:
V
- the type of output of theafter
FunctionWithException
, and of the composedFunctionWithException
- Parameters:
after
- the function to apply after thisFunctionWithException
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:
BiFunction.andThen(Function)
-
failing
static <T,U,R,E extends Exception> BiFunctionWithException<T,U,R,E> failing(Supplier<E> exceptionBuilder)
Returns aFunctionWithException
that always throw exception.- Type Parameters:
T
- the type of the first argument to the functionU
- the type of the second argument 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,U,R,E extends Exception> BiFunction<T,U,R> unchecked(BiFunctionWithException<T,U,R,E> function)
Converts aBiFunctionWithException
to aBiFunction
that convert exception toRuntimeException
.For example :
BiFunction<String, String, String> biFunctionThrowingRuntimeException = BiFunctionWithException .unchecked(biFouctionThrowingException);
Will generate aBiFunction
throwingRuntimeException
in case of error.- Type Parameters:
T
- the type of the first argument to the functionU
- the type of the second argument 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(BiFunctionWithException, Function)
-
unchecked
static <T,U,R,E extends Exception> BiFunction<T,U,R> unchecked(BiFunctionWithException<T,U,R,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aBiFunctionWithException
to aBiFunction
that convert exception toRuntimeException
by using the provided mapping function.For example :
BiFunction<String, String, String> functionThrowingRuntimeException = BiFunctionWithException .unchecked(fonctionThrowingException, IllegalArgumentException::new);
Will generate aBiFunction
throwingIllegalArgumentException
in case of error.- Type Parameters:
T
- the type of the first argument to the functionU
- the type of the second argument 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(BiFunctionWithException)
-
lifted
static <T,U,R,E extends Exception> BiFunction<T,U,Optional<R>> lifted(BiFunctionWithException<T,U,R,E> function)
Converts aBiFunctionWithException
to a liftedBiFunction
usingOptional
as return value.- Type Parameters:
T
- the type of the first argument to the functionU
- the type of the second argument 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,U,R,E extends Exception> BiFunction<T,U,R> ignored(BiFunctionWithException<T,U,R,E> function)
Converts aBiFunctionWithException
to a liftedBiFunction
returningnull
in case of exception.- Type Parameters:
T
- the type of the first argument to the functionU
- the type of the second argument 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,U,R,E extends Exception> BiFunction<T,U,R> ignored(BiFunctionWithException<T,U,R,E> function, R defaultValue)
Converts aBiFunctionWithException
to a liftedBiFunction
returning a default in case of exception.- Type Parameters:
T
- the type of the first argument to the functionU
- the type of the second argument 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 error- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- Since:
- 3.0.0
- See Also:
ignore()
,ignored(BiFunctionWithException)
-
staged
static <T,U,R,E extends Exception> BiFunction<T,U,CompletionStage<R>> staged(BiFunctionWithException<T,U,R,E> function)
Convert thisBiFunctionWithException
to a liftedBiFunction
returnCompletionStage
as return value.- Type Parameters:
T
- the type of the first argument to the functionU
- the type of the second argument 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()
-
asBiConsumer
static <T,U,R,E extends Exception> BiConsumerWithException<T,U,E> asBiConsumer(BiFunctionWithException<T,U,R,E> function)
Converts aBiFunctionWithException
to aBiConsumerWithException
.- Type Parameters:
T
- the type of the first argument to the operationU
- the type of the second argument to the operationR
- the type of the return value of the functionE
- the type of the potential exception of the operation- Parameters:
function
- to be converter- Returns:
- the consumer
- Throws:
NullPointerException
- if function is null- Since:
- 1.2.0
-
asBiConsumer
default BiConsumerWithException<T,U,E> asBiConsumer()
Converts aBiFunctionWithException
to aBiConsumerWithException
.- Returns:
- the consumer
- Since:
- 1.2.0
-
asFunction
static <T,U,R,E extends Exception> FunctionWithException<T,R,E> asFunction(BiFunctionWithException<T,U,R,E> function, U u)
Converts aBiFunctionWithException
to aFunctionWithException
.- Type Parameters:
T
- the type of the first argument to the operationU
- the type of the second argument to the operationR
- the type of the return value of the functionE
- the type of the potential exception of the operation- Parameters:
function
- to be converteru
- the second parameter of theBiFunctionWithException
that will be used inside the new {code FunctionWithException}.- Returns:
- the consumer
- Throws:
NullPointerException
- if function is null- Since:
- 1.2.0
-
asFunction
default FunctionWithException<T,R,E> asFunction(U u)
Converts aBiFunctionWithException
to aFunctionWithException
.- Parameters:
u
- the second parameter of theBiFunctionWithException
that will be used inside the new {code FunctionWithException}.- Returns:
- the consumer
- Since:
- 1.2.0
-
-