Interface ConsumerWithException<T,E extends Exception>
-
- Type Parameters:
T- the type of the input to the operationE- the type of the potential exception of the operation
- All Superinterfaces:
ExceptionHandlerSupport<Consumer<T>,Consumer<T>,ConsumerWithException<T,E>>,NoReturnExceptionHandlerSupport<Consumer<T>,Function<T,CompletionStage<Void>>,ConsumerWithException<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 ConsumerWithException<T,E extends Exception> extends NoReturnExceptionHandlerSupport<Consumer<T>,Function<T,CompletionStage<Void>>,ConsumerWithException<T,E>>
Represents an operation that accepts a single input argument, may thrown exception and returns no result. Unlike most other functional interfaces,ConsumerWithExceptionis expected to operate via side-effects.General contract
void accept(T t) throws E- The functional method.- uncheck - Return a
Consumer<T> - lift - Return a
Consumer<T> - ignore - Return a
Consumer<T>
- See Also:
Consumer
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaccept(T t)Performs this operation on the given argument.default ConsumerWithException<T,E>andThen(ConsumerWithException<? super T,? extends E> after)Returns a composedConsumerWithExceptionthat performs, in sequence, this operation followed by theafteroperation.default <R> FunctionWithException<T,R,E>asFunction()Converts aConsumerWithExceptionto aFunctionWithExceptionreturningnull.static <T,R,E extends Exception>
FunctionWithException<T,R,E>asFunction(ConsumerWithException<T,E> consumer)Converts aConsumerWithExceptionto aFunctionWithExceptionreturningnull.static <T,E extends Exception>
ConsumerWithException<T,E>failing(Supplier<E> exceptionBuilder)Returns aConsumerWithExceptionthat always throw exception.default Consumer<T>ignore()Converts thisConsumerWithExceptionto a liftedConsumerthat ignore exception.static <T,E extends Exception>
Consumer<T>ignored(ConsumerWithException<T,E> consumer)Converts aConsumerWithExceptionto a liftedConsumerignoring exception.static <T,E extends Exception>
Consumer<T>lifted(ConsumerWithException<T,E> consumer)Converts aConsumerWithExceptionto a liftedConsumerignoring exception.default Function<T,CompletionStage<Void>>stage()Converts thisConsumerWithExceptionto a stagedFunctionthat return aCompletionStage.static <T,E extends Exception>
Function<T,CompletionStage<Void>>staged(ConsumerWithException<T,E> consumer)Converts aConsumerWithExceptionto a stagedFunction.default Consumer<T>uncheck()Converts thisConsumerWithExceptionto aConsumerthat wraps exception toRuntimeException.static <T,E extends Exception>
Consumer<T>unchecked(ConsumerWithException<T,E> consumer)Converts aConsumerWithExceptionto aConsumerthat wraps exception toRuntimeException.static <T,E extends Exception>
Consumer<T>unchecked(ConsumerWithException<T,E> consumer, Function<Exception,RuntimeException> exceptionMapper)Converts aConsumerWithExceptionto aConsumerthat wraps 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.NoReturnExceptionHandlerSupport
lift, notThrowingHandler, throwingHandler
-
-
-
-
Method Detail
-
accept
void accept(T t) throws E extends Exception
Performs this operation on the given argument.- Parameters:
t- the input argument- Throws:
E- any exceptionE extends Exception- See Also:
Consumer.accept(Object)
-
uncheck
default Consumer<T> uncheck()
Converts thisConsumerWithExceptionto aConsumerthat wraps exception toRuntimeException.- Specified by:
uncheckin interfaceExceptionHandlerSupport<Consumer<T>,Consumer<T>,ConsumerWithException<T,E extends Exception>>- Specified by:
uncheckin interfaceNoReturnExceptionHandlerSupport<Consumer<T>,Function<T,CompletionStage<Void>>,ConsumerWithException<T,E extends Exception>>- Returns:
- the unchecked operation
- See Also:
unchecked(ConsumerWithException),unchecked(ConsumerWithException, Function),Consumer
-
ignore
default Consumer<T> ignore()
Converts thisConsumerWithExceptionto a liftedConsumerthat ignore exception.- Specified by:
ignorein interfaceExceptionHandlerSupport<Consumer<T>,Consumer<T>,ConsumerWithException<T,E extends Exception>>- Specified by:
ignorein interfaceNoReturnExceptionHandlerSupport<Consumer<T>,Function<T,CompletionStage<Void>>,ConsumerWithException<T,E extends Exception>>- Returns:
- the operation that ignore error
- See Also:
ignored(ConsumerWithException),Consumer
-
stage
default Function<T,CompletionStage<Void>> stage()
Converts thisConsumerWithExceptionto a stagedFunctionthat return aCompletionStage.- Specified by:
stagein interfaceNoReturnExceptionHandlerSupport<Consumer<T>,Function<T,CompletionStage<Void>>,ConsumerWithException<T,E extends Exception>>- Returns:
- the staged operation.
- Since:
- 1.1.0
-
andThen
default ConsumerWithException<T,E> andThen(ConsumerWithException<? super T,? extends E> after)
Returns a composedConsumerWithExceptionthat performs, in sequence, this operation followed by theafteroperation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, theafteroperation will not be performed.- Parameters:
after- the operation to perform after this operation- Returns:
- a composed
ConsumerWithExceptionthat performs in sequence this operation followed by theafteroperation - Throws:
NullPointerException- ifafteris null- See Also:
Consumer.andThen(Consumer)
-
failing
static <T,E extends Exception> ConsumerWithException<T,E> failing(Supplier<E> exceptionBuilder)
Returns aConsumerWithExceptionthat always throw exception.- Type Parameters:
T- the type of the input to the operationE- the type of the exception- Parameters:
exceptionBuilder- the supplier to create the exception- Returns:
- an operation that always throw exception
-
unchecked
static <T,E extends Exception> Consumer<T> unchecked(ConsumerWithException<T,E> consumer)
Converts aConsumerWithExceptionto aConsumerthat wraps exception toRuntimeException.For example :
ConsumerWithException<String, IOException> consumerThrowingException = ...; Consumer<String> consumerThrowingRuntimeException = ConsumerWithException.unchecked(consumerThrowingException); Stream....forEach(consumerThrowingRuntimeException);
In case of exception insideconsumerThrowingRuntimeExceptionan instance ofWrappedExceptionwith the original exception as cause will be thrown.- Type Parameters:
T- the type of the input to the operationE- the type of the potential exception- Parameters:
consumer- to be unchecked- Returns:
- the unchecked exception
- Throws:
NullPointerException- if consumer is null- See Also:
uncheck(),unchecked(ConsumerWithException, Function)
-
unchecked
static <T,E extends Exception> Consumer<T> unchecked(ConsumerWithException<T,E> consumer, Function<Exception,RuntimeException> exceptionMapper)
Converts aConsumerWithExceptionto aConsumerthat wraps exception toRuntimeExceptionby using the provided mapping function.For example :
ConsumerWithException<String, IOException> consumerThrowingException = ...; Consumer<String> consumerThrowingRuntimeException = ConsumerWithException.unchecked( consumerThrowingException, IllegalArgumentException::new ); Stream....forEach(consumerThrowingRuntimeException);In case of exception insideconsumerThrowingRuntimeExceptionan instance ofIllegalArgumentExceptionwith the original exception as cause will be thrown.- Type Parameters:
T- the type of the input to the operationE- the type of the potential exception- 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(ConsumerWithException)
-
lifted
static <T,E extends Exception> Consumer<T> lifted(ConsumerWithException<T,E> consumer)
Converts aConsumerWithExceptionto a liftedConsumerignoring exception.- Type Parameters:
T- the type of the input to the operationE- the type of the potential exception- Parameters:
consumer- to be lifted- Returns:
- the lifted operation
- Throws:
NullPointerException- if consumer is null- See Also:
NoReturnExceptionHandlerSupport.lift()
-
ignored
static <T,E extends Exception> Consumer<T> ignored(ConsumerWithException<T,E> consumer)
Converts aConsumerWithExceptionto a liftedConsumerignoring exception.- Type Parameters:
T- the type of the input to the operationE- the type of the potential exception- Parameters:
consumer- to be lifted- Returns:
- the lifted operation
- Throws:
NullPointerException- if consumer is null- See Also:
ignore()
-
staged
static <T,E extends Exception> Function<T,CompletionStage<Void>> staged(ConsumerWithException<T,E> consumer)
Converts aConsumerWithExceptionto a stagedFunction.- Type Parameters:
T- the type of the input 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
-
asFunction
static <T,R,E extends Exception> FunctionWithException<T,R,E> asFunction(ConsumerWithException<T,E> consumer)
Converts aConsumerWithExceptionto aFunctionWithExceptionreturningnull.- Type Parameters:
T- the type of the input to the operationR- the type of the return valueE- the type of the potential exception- Parameters:
consumer- the consumer to be converted- Returns:
- the function
- Throws:
NullPointerException- if consumer is null
-
asFunction
default <R> FunctionWithException<T,R,E> asFunction()
Converts aConsumerWithExceptionto aFunctionWithExceptionreturningnull.- Type Parameters:
R- the type of the return value- Returns:
- the function
- Since:
- 1.2.0
-
-