Interface BinaryOperatorWithException<T,E extends Exception>
-
- Type Parameters:
T
- the type of the operands and result of the operatorE
- the type of the potential exception of the function
- All Superinterfaces:
BiFunctionWithException<T,T,T,E>
,ExceptionHandlerSupport<BiFunction<T,T,T>,BiFunction<T,T,Optional<T>>,BiFunctionWithException<T,T,T,E>>
,ObjectReturnExceptionHandlerSupport<BiFunction<T,T,T>,BiFunction<T,T,Optional<T>>,BiFunction<T,T,CompletionStage<T>>,T,BiFunctionWithException<T,T,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 BinaryOperatorWithException<T,E extends Exception> extends BiFunctionWithException<T,T,T,E>
Represents an operation upon two operands of the same type, that may throw exception, producing a result of the same type as the operands. This is a specialization ofBiFunctionWithException
for the case where the operands and the result are all of the same type.As this interface must return the same type of the input, a lifted version which returns
Optional
is not possible.General contract
T apply(T t, T u) throws E
- The functional method.- uncheck - Return a
BinaryOperator<T>
- lift - Return a
BiFunction<T,T,<Optional<T>>
- ignore - Return a
BinaryOperator<T>
- See Also:
BiFunctionWithException
,BinaryOperator
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description default BinaryOperatorWithException<T,E>
documented(Supplier<String> toString)
Add atoString
method to the existing interface based on the receivedSupplier
.static <T,E extends Exception>
BinaryOperatorWithException<T,E>failing(Supplier<E> exceptionBuilder)
Returns a binary operator that always throw exception.default BinaryOperator<T>
ignore()
Converts thisBinaryOperatorWithException
to a liftedBinaryOperator
returningnull
in case of exception.static <T,E extends Exception>
BinaryOperator<T>ignored(BinaryOperatorWithException<T,E> function)
Converts aBinaryOperatorWithException
to a liftedBinaryOperator
returningnull
in case of exception.static <T,E extends Exception>
BiFunction<T,T,Optional<T>>lifted(BinaryOperatorWithException<T,E> function)
Converts aBinaryOperatorWithException
to a liftedFunction
returning an optional in case of exception.default BinaryOperator<T>
uncheck()
Converts thisBinaryOperatorWithException
to aBinaryOperator
that convert exception toRuntimeException
.static <T,E extends Exception>
BinaryOperator<T>unchecked(BinaryOperatorWithException<T,E> function)
Converts aBinaryOperatorWithException
to aBinaryOperator
that convert exception toRuntimeException
.static <T,E extends Exception>
BinaryOperator<T>unchecked(BinaryOperatorWithException<T,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aBinaryOperatorWithException
to aBinaryOperator
that convert exception toRuntimeException
by using the provided mapping function.-
Methods inherited from interface ch.powerunit.extensions.exceptions.BiFunctionWithException
andThen, apply, asBiConsumer, asFunction, lift, stage
-
Methods inherited from interface ch.powerunit.extensions.exceptions.ExceptionHandlerSupport
exceptionMapper
-
Methods inherited from interface ch.powerunit.extensions.exceptions.ObjectReturnExceptionHandlerSupport
defaultValue, notThrowingHandler, throwingHandler
-
-
-
-
Method Detail
-
uncheck
default BinaryOperator<T> uncheck()
Converts thisBinaryOperatorWithException
to aBinaryOperator
that convert exception toRuntimeException
.- Specified by:
uncheck
in interfaceBiFunctionWithException<T,T,T,E extends Exception>
- Specified by:
uncheck
in interfaceExceptionHandlerSupport<BiFunction<T,T,T>,BiFunction<T,T,Optional<T>>,BiFunctionWithException<T,T,T,E extends Exception>>
- Specified by:
uncheck
in interfaceObjectReturnExceptionHandlerSupport<BiFunction<T,T,T>,BiFunction<T,T,Optional<T>>,BiFunction<T,T,CompletionStage<T>>,T,BiFunctionWithException<T,T,T,E extends Exception>>
- Returns:
- the unchecked function
- See Also:
unchecked(BinaryOperatorWithException)
,unchecked(BinaryOperatorWithException, Function)
-
ignore
default BinaryOperator<T> ignore()
Converts thisBinaryOperatorWithException
to a liftedBinaryOperator
returningnull
in case of exception.- Specified by:
ignore
in interfaceBiFunctionWithException<T,T,T,E extends Exception>
- Specified by:
ignore
in interfaceExceptionHandlerSupport<BiFunction<T,T,T>,BiFunction<T,T,Optional<T>>,BiFunctionWithException<T,T,T,E extends Exception>>
- Specified by:
ignore
in interfaceObjectReturnExceptionHandlerSupport<BiFunction<T,T,T>,BiFunction<T,T,Optional<T>>,BiFunction<T,T,CompletionStage<T>>,T,BiFunctionWithException<T,T,T,E extends Exception>>
- Returns:
- the function that ignore error
- See Also:
ignored(BinaryOperatorWithException)
-
documented
default BinaryOperatorWithException<T,E> documented(Supplier<String> toString)
Description copied from interface:ExceptionHandlerSupport
Add atoString
method to the existing interface based on the receivedSupplier
.- Specified by:
documented
in interfaceExceptionHandlerSupport<BiFunction<T,T,T>,BiFunction<T,T,Optional<T>>,BiFunctionWithException<T,T,T,E extends Exception>>
- Parameters:
toString
- the supplier to be used- Returns:
- a new interface, with
toString
using the received supplier.
-
failing
static <T,E extends Exception> BinaryOperatorWithException<T,E> failing(Supplier<E> exceptionBuilder)
Returns a binary operator that always throw exception.- Type Parameters:
T
- the type of the operands and result of the operatorE
- the type of the exception- Parameters:
exceptionBuilder
- the supplier to create the exception- Returns:
- a function that always throw exception
-
unchecked
static <T,E extends Exception> BinaryOperator<T> unchecked(BinaryOperatorWithException<T,E> function)
Converts aBinaryOperatorWithException
to aBinaryOperator
that convert exception toRuntimeException
.- Type Parameters:
T
- the type of the operands and result of the operatorE
- 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(BinaryOperatorWithException, Function)
-
unchecked
static <T,E extends Exception> BinaryOperator<T> unchecked(BinaryOperatorWithException<T,E> function, Function<Exception,RuntimeException> exceptionMapper)
Converts aBinaryOperatorWithException
to aBinaryOperator
that convert exception toRuntimeException
by using the provided mapping function.- Type Parameters:
T
- the type of the operands and result of the operatorE
- 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(BinaryOperatorWithException)
-
lifted
static <T,E extends Exception> BiFunction<T,T,Optional<T>> lifted(BinaryOperatorWithException<T,E> function)
Converts aBinaryOperatorWithException
to a liftedFunction
returning an optional in case of exception.- Type Parameters:
T
- the type of the operands and result of the operatorE
- the type of the potential exception- Parameters:
function
- the be unchecked- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- See Also:
ignore()
-
ignored
static <T,E extends Exception> BinaryOperator<T> ignored(BinaryOperatorWithException<T,E> function)
Converts aBinaryOperatorWithException
to a liftedBinaryOperator
returningnull
in case of exception.- Type Parameters:
T
- the type of the operands and result of the operatorE
- the type of the potential exception- Parameters:
function
- the be unchecked- Returns:
- the lifted function
- Throws:
NullPointerException
- if function is null- See Also:
ignore()
-
-