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 composedFunctionWithExceptionthat first applies thisFunctionWithExceptionto its input, and then applies theafterFunctionWithExceptionto the result.Rapply(T t, U u)Applies this function to the given arguments.default BiConsumerWithException<T,U,E>asBiConsumer()Converts aBiFunctionWithExceptionto aBiConsumerWithException.static <T,U,R,E extends Exception>
BiConsumerWithException<T,U,E>asBiConsumer(BiFunctionWithException<T,U,R,E> function)Converts aBiFunctionWithExceptionto aBiConsumerWithException.static <T,U,R,E extends Exception>
FunctionWithException<T,R,E>asFunction(BiFunctionWithException<T,U,R,E> function, U u)Converts aBiFunctionWithExceptionto aFunctionWithException.default FunctionWithException<T,R,E>asFunction(U u)Converts aBiFunctionWithExceptionto aFunctionWithException.static <T,U,R,E extends Exception>
BiFunctionWithException<T,U,R,E>failing(Supplier<E> exceptionBuilder)Returns aFunctionWithExceptionthat always throw exception.default BiFunction<T,U,R>ignore()Converts thisBiFunctionWithExceptionto a liftedBiFunctionreturningnull(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 aBiFunctionWithExceptionto a liftedBiFunctionreturningnullin case of exception.static <T,U,R,E extends Exception>
BiFunction<T,U,R>ignored(BiFunctionWithException<T,U,R,E> function, R defaultValue)Converts aBiFunctionWithExceptionto a liftedBiFunctionreturning a default in case of exception.default BiFunction<T,U,Optional<R>>lift()Converts thisBiFunctionWithExceptionto a liftedBiFunctionusingOptionalas return value.static <T,U,R,E extends Exception>
BiFunction<T,U,Optional<R>>lifted(BiFunctionWithException<T,U,R,E> function)Converts aBiFunctionWithExceptionto a liftedBiFunctionusingOptionalas return value.default BiFunction<T,U,CompletionStage<R>>stage()Convert thisBiFunctionWithExceptionto a liftedBiFunctionthat usesCompletionStageas return value.static <T,U,R,E extends Exception>
BiFunction<T,U,CompletionStage<R>>staged(BiFunctionWithException<T,U,R,E> function)Convert thisBiFunctionWithExceptionto a liftedBiFunctionreturnCompletionStageas return value.default BiFunction<T,U,R>uncheck()Converts thisBiFunctionWithExceptionto aBiFunctionthat wraps exception toRuntimeException.static <T,U,R,E extends Exception>
BiFunction<T,U,R>unchecked(BiFunctionWithException<T,U,R,E> function)Converts aBiFunctionWithExceptionto aBiFunctionthat 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 aBiFunctionWithExceptionto aBiFunctionthat convert 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, 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 thisBiFunctionWithExceptionto aBiFunctionthat wraps exception toRuntimeException.- Specified by:
uncheckin interfaceExceptionHandlerSupport<T,U,R>- Specified by:
uncheckin 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 thisBiFunctionWithExceptionto a liftedBiFunctionusingOptionalas return value.- Specified by:
liftin interfaceExceptionHandlerSupport<T,U,R>- Specified by:
liftin 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 thisBiFunctionWithExceptionto a liftedBiFunctionreturningnull(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()) in case of exception.- Specified by:
ignorein interfaceExceptionHandlerSupport<T,U,R>- Specified by:
ignorein 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 thisBiFunctionWithExceptionto a liftedBiFunctionthat usesCompletionStageas return value.- Specified by:
stagein 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 composedFunctionWithExceptionthat first applies thisFunctionWithExceptionto its input, and then applies theafterFunctionWithExceptionto the result. If evaluation of eitherFunctionWithExceptionthrows an exception, it is relayed to the caller of the composed function.- Type Parameters:
V- the type of output of theafterFunctionWithException, and of the composedFunctionWithException- Parameters:
after- the function to apply after thisFunctionWithExceptionis applied- Returns:
- a composed function that first applies this function and then applies
the
afterfunction - 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 aFunctionWithExceptionthat 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 aBiFunctionWithExceptionto aBiFunctionthat convert exception toRuntimeException.For example :
BiFunction<String, String, String> biFunctionThrowingRuntimeException = BiFunctionWithException .unchecked(biFouctionThrowingException);Will generate aBiFunctionthrowingRuntimeExceptionin 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 aBiFunctionWithExceptionto aBiFunctionthat convert exception toRuntimeExceptionby using the provided mapping function.For example :
BiFunction<String, String, String> functionThrowingRuntimeException = BiFunctionWithException .unchecked(fonctionThrowingException, IllegalArgumentException::new);Will generate aBiFunctionthrowingIllegalArgumentExceptionin 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 aBiFunctionWithExceptionto a liftedBiFunctionusingOptionalas 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 aBiFunctionWithExceptionto a liftedBiFunctionreturningnullin 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 aBiFunctionWithExceptionto a liftedBiFunctionreturning 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 thisBiFunctionWithExceptionto a liftedBiFunctionreturnCompletionStageas 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 aBiFunctionWithExceptionto 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 aBiFunctionWithExceptionto 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 aBiFunctionWithExceptionto 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 theBiFunctionWithExceptionthat 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 aBiFunctionWithExceptionto aFunctionWithException.- Parameters:
u- the second parameter of theBiFunctionWithExceptionthat will be used inside the new {code FunctionWithException}.- Returns:
- the consumer
- Since:
- 1.2.0
-
-