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 ofBiFunctionWithExceptionfor 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
Optionalis 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 atoStringmethod 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 thisBinaryOperatorWithExceptionto a liftedBinaryOperatorreturningnullin case of exception.static <T,E extends Exception>
BinaryOperator<T>ignored(BinaryOperatorWithException<T,E> function)Converts aBinaryOperatorWithExceptionto a liftedBinaryOperatorreturningnullin case of exception.static <T,E extends Exception>
BiFunction<T,T,Optional<T>>lifted(BinaryOperatorWithException<T,E> function)Converts aBinaryOperatorWithExceptionto a liftedFunctionreturning an optional in case of exception.default BinaryOperator<T>uncheck()Converts thisBinaryOperatorWithExceptionto aBinaryOperatorthat convert exception toRuntimeException.static <T,E extends Exception>
BinaryOperator<T>unchecked(BinaryOperatorWithException<T,E> function)Converts aBinaryOperatorWithExceptionto aBinaryOperatorthat convert exception toRuntimeException.static <T,E extends Exception>
BinaryOperator<T>unchecked(BinaryOperatorWithException<T,E> function, Function<Exception,RuntimeException> exceptionMapper)Converts aBinaryOperatorWithExceptionto aBinaryOperatorthat convert exception toRuntimeExceptionby 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 thisBinaryOperatorWithExceptionto aBinaryOperatorthat convert exception toRuntimeException.- Specified by:
uncheckin interfaceBiFunctionWithException<T,T,T,E extends Exception>- Specified by:
uncheckin interfaceExceptionHandlerSupport<BiFunction<T,T,T>,BiFunction<T,T,Optional<T>>,BiFunctionWithException<T,T,T,E extends Exception>>- Specified by:
uncheckin 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 thisBinaryOperatorWithExceptionto a liftedBinaryOperatorreturningnullin case of exception.- Specified by:
ignorein interfaceBiFunctionWithException<T,T,T,E extends Exception>- Specified by:
ignorein interfaceExceptionHandlerSupport<BiFunction<T,T,T>,BiFunction<T,T,Optional<T>>,BiFunctionWithException<T,T,T,E extends Exception>>- Specified by:
ignorein 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:ExceptionHandlerSupportAdd atoStringmethod to the existing interface based on the receivedSupplier.- Specified by:
documentedin 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
toStringusing 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 aBinaryOperatorWithExceptionto aBinaryOperatorthat 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 aBinaryOperatorWithExceptionto aBinaryOperatorthat convert exception toRuntimeExceptionby 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 aBinaryOperatorWithExceptionto a liftedFunctionreturning 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 aBinaryOperatorWithExceptionto a liftedBinaryOperatorreturningnullin 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()
-
-