Interface BiConsumerWithException<T,U,E extends Exception>
-
- Type Parameters:
T
- the type of the first argument to the operationU
- the type of the second argument to the operationE
- the type of the potential exception of the operation
- All Superinterfaces:
ExceptionHandlerSupport<BiConsumer<T,U>,BiConsumer<T,U>,BiConsumerWithException<T,U,E>>
,NoReturnExceptionHandlerSupport<BiConsumer<T,U>,BiFunction<T,U,CompletionStage<Void>>,BiConsumerWithException<T,U,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 BiConsumerWithException<T,U,E extends Exception> extends NoReturnExceptionHandlerSupport<BiConsumer<T,U>,BiFunction<T,U,CompletionStage<Void>>,BiConsumerWithException<T,U,E>>
Represents an operation that accepts two input arguments and returns no result and may throw exception. Unlike most other functional interfaces,BiConsumerWithException
is expected to operate via side-effects.General contract
void accept(T t,U u) throws E
- The functional method.- uncheck - Return a
Biconsumer<T,U>
- lift - Return a
Biconsumer<T,U>
- ignore - Return a
Biconsumer<T,U>
- See Also:
BiConsumer
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
accept(T t, U u)
Performs this operation on the given arguments.default BiConsumerWithException<T,U,E>
andThen(BiConsumerWithException<? super T,? super U,? extends E> after)
Returns a composedBiConsumerWithException
that performs, in sequence, this operation followed by theafter
operation.default <R> BiFunctionWithException<T,U,R,E>
asBiFunction()
Converts aBiConsumerWithException
to aBiFunctionWithException
returningnull
.static <T,U,R,E extends Exception>
BiFunctionWithException<T,U,R,E>asBiFunction(BiConsumerWithException<T,U,E> consumer)
Converts aBiConsumerWithException
to aBiFunctionWithException
returningnull
.static <T,U,E extends Exception>
BiConsumerWithException<T,U,E>failing(Supplier<E> exceptionBuilder)
Returns aBiConsumerWithException
that always throw exception.default BiConsumer<T,U>
ignore()
Converts thisBiConsumerWithException
to a liftedBiConsumer
that ignore exception.static <T,U,E extends Exception>
BiConsumer<T,U>ignored(BiConsumerWithException<T,U,E> consumer)
Converts aBiConsumerWithException
to a liftedBiConsumer
ignoring exception.static <T,U,E extends Exception>
BiConsumer<T,U>lifted(BiConsumerWithException<T,U,E> consumer)
Converts aBiConsumerWithException
to a liftedBiConsumer
ignoring exception.default BiFunction<T,U,CompletionStage<Void>>
stage()
Converts thisBiConsumerWithException
to a stagedBiFunction
that return aCompletionStage
.static <T,U,E extends Exception>
BiFunction<T,U,CompletionStage<Void>>staged(BiConsumerWithException<T,U,E> consumer)
Converts aBiConsumerWithException
to a stagedBiFunction
.default BiConsumer<T,U>
uncheck()
Converts thisBiConsumerWithException
to aBiConsumer
that wraps exception intoRuntimeException
.static <T,U,E extends Exception>
BiConsumer<T,U>unchecked(BiConsumerWithException<T,U,E> consumer)
Converts aBiConsumerWithException
to aBiConsumer
that wraps exception toRuntimeException
.static <T,U,E extends Exception>
BiConsumer<T,U>unchecked(BiConsumerWithException<T,U,E> consumer, Function<Exception,RuntimeException> exceptionMapper)
Converts aBiConsumerWithException
to aBiConsumer
that wraps 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.NoReturnExceptionHandlerSupport
lift, notThrowingHandler, throwingHandler
-
-
-
-
Method Detail
-
accept
void accept(T t, U u) throws E extends Exception
Performs this operation on the given arguments.- Parameters:
t
- the first input argumentu
- the second input argument- Throws:
E
- any exceptionE extends Exception
- See Also:
BiConsumer.accept(Object,Object)
-
uncheck
default BiConsumer<T,U> uncheck()
Converts thisBiConsumerWithException
to aBiConsumer
that wraps exception intoRuntimeException
.- Specified by:
uncheck
in interfaceExceptionHandlerSupport<T,U,E extends Exception>
- Specified by:
uncheck
in interfaceNoReturnExceptionHandlerSupport<T,U,E extends Exception>
- Returns:
- the unchecked operation
- See Also:
unchecked(BiConsumerWithException)
,unchecked(BiConsumerWithException, Function)
,BiConsumer
-
ignore
default BiConsumer<T,U> ignore()
Converts thisBiConsumerWithException
to a liftedBiConsumer
that ignore exception.- Specified by:
ignore
in interfaceExceptionHandlerSupport<T,U,E extends Exception>
- Specified by:
ignore
in interfaceNoReturnExceptionHandlerSupport<T,U,E extends Exception>
- Returns:
- the operation that ignore error
- See Also:
ignored(BiConsumerWithException)
,BiConsumer
-
stage
default BiFunction<T,U,CompletionStage<Void>> stage()
Converts thisBiConsumerWithException
to a stagedBiFunction
that return aCompletionStage
.
-
andThen
default BiConsumerWithException<T,U,E> andThen(BiConsumerWithException<? super T,? super U,? extends E> after)
Returns a composedBiConsumerWithException
that performs, in sequence, this operation followed by theafter
operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, theafter
operation will not be performed.- Parameters:
after
- the operation to perform after this operation- Returns:
- a composed
BiConsumerWithException
that performs in sequence this operation followed by theafter
operation - Throws:
NullPointerException
- ifafter
is null- See Also:
BiConsumer.andThen(BiConsumer)
-
failing
static <T,U,E extends Exception> BiConsumerWithException<T,U,E> failing(Supplier<E> exceptionBuilder)
Returns aBiConsumerWithException
that always throw exception.- Type Parameters:
T
- the type of the first argument to the operationU
- the type of the second argument to the operationE
- the type of the potential exception of the operation- Parameters:
exceptionBuilder
- the supplier to create the exception- Returns:
- an operation that always throw exception
-
unchecked
static <T,U,E extends Exception> BiConsumer<T,U> unchecked(BiConsumerWithException<T,U,E> consumer)
Converts aBiConsumerWithException
to aBiConsumer
that wraps exception toRuntimeException
.For example :
BiConsumerWithException<String, String, IOException> consumerThrowingException = ...; BiConsumer<String, String> consumerThrowingRuntimeException = ConsumerWithException.unchecked(consumerThrowingException); myMap.forEach(consumerThrowingRuntimeException);
In case of exception insideconsumerThrowingRuntimeException
an instance ofWrappedException
with the original exception as cause will be thrown.- Type Parameters:
T
- the type of the first argument to the operationU
- the type of the second argument to the operationE
- the type of the potential exception of the operation- Parameters:
consumer
- to be unchecked- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if consumer is null- See Also:
uncheck()
,unchecked(BiConsumerWithException, Function)
-
unchecked
static <T,U,E extends Exception> BiConsumer<T,U> unchecked(BiConsumerWithException<T,U,E> consumer, Function<Exception,RuntimeException> exceptionMapper)
Converts aBiConsumerWithException
to aBiConsumer
that wraps exception toRuntimeException
by using the provided mapping function.For example :
BiConsumerWithException<String, String, IOException> consumerThrowingException = ...; BiConsumer<String, String> consumerThrowingRuntimeException = ConsumerWithException.unchecked( consumerThrowingException, IllegalArgumentException::new); myMap.forEach(consumerThrowingRuntimeException)
In case of exception insideconsumerThrowingRuntimeException
an instance ofIllegalArgumentException
with the original exception as cause will be thrown.- Type Parameters:
T
- the type of the first argument to the operationU
- the type of the second argument to the operationE
- the type of the potential exception of the operation- Parameters:
consumer
- the be uncheckedexceptionMapper
- a function to convert the exception to the runtime exception.- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if consumer or exceptionMapper is null- See Also:
uncheck()
,unchecked(BiConsumerWithException)
-
lifted
static <T,U,E extends Exception> BiConsumer<T,U> lifted(BiConsumerWithException<T,U,E> consumer)
Converts aBiConsumerWithException
to a liftedBiConsumer
ignoring exception.For example :
BiConsumerWithException<String, String, IOException> consumerThrowingException = ...; BiConsumer<String, String> consumerThrowingRuntimeException = ConsumerWithException.lifted(consumerThrowingException); myMap.forEach(consumerThrowingRuntimeException);
In case of exception insideconsumerThrowingRuntimeException
the exception will be ignored.- Type Parameters:
T
- the type of the first argument to the operationU
- the type of the second argument to the operationE
- the type of the potential exception of the operation- Parameters:
consumer
- to be lifted- Returns:
- the lifted operation
- Throws:
NullPointerException
- if consumer is null- See Also:
NoReturnExceptionHandlerSupport.lift()
-
ignored
static <T,U,E extends Exception> BiConsumer<T,U> ignored(BiConsumerWithException<T,U,E> consumer)
Converts aBiConsumerWithException
to a liftedBiConsumer
ignoring exception.For example :
BiConsumerWithException<String, String, IOException> consumerThrowingException = ...; BiConsumer<String, String> consumerThrowingRuntimeException = ConsumerWithException.ignored(consumerThrowingException); myMap.forEach(consumerThrowingRuntimeException);
In case of exception insideconsumerThrowingRuntimeException
the exception will be ignored.- Type Parameters:
T
- the type of the first argument to the operationU
- the type of the second argument to the operationE
- the type of the potential exception of the operation- Parameters:
consumer
- to be lifted- Returns:
- the lifted operation
- Throws:
NullPointerException
- if consumer is null- See Also:
ignore()
-
staged
static <T,U,E extends Exception> BiFunction<T,U,CompletionStage<Void>> staged(BiConsumerWithException<T,U,E> consumer)
Converts aBiConsumerWithException
to a stagedBiFunction
.- Type Parameters:
T
- the type of the first argument to the operationU
- the type of the second argument to the operationE
- the type of the potential exception- Parameters:
consumer
- to be staged- Returns:
- the staged operation
- Throws:
NullPointerException
- if consumer is null- Since:
- 1.1.0
-
asBiFunction
static <T,U,R,E extends Exception> BiFunctionWithException<T,U,R,E> asBiFunction(BiConsumerWithException<T,U,E> consumer)
Converts aBiConsumerWithException
to aBiFunctionWithException
returningnull
.- 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:
consumer
- to be converter- Returns:
- the function
- Throws:
NullPointerException
- if consumer is null
-
asBiFunction
default <R> BiFunctionWithException<T,U,R,E> asBiFunction()
Converts aBiConsumerWithException
to aBiFunctionWithException
returningnull
.- Type Parameters:
R
- the type of the return value of the function- Returns:
- the function
- Since:
- 1.2.0
-
-