Interface Consumer<T>
- Type Parameters:
T- the accepted type
- All Superinterfaces:
Consumer<T>
- All Known Implementing Classes:
CacheEntriesTask, CacheKeysTask, Consumer.ExceptionLogger
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classConsumer.ExceptionLogger<E extends Exception>A consumer of an exception that logs its parameter. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Consumer<?> A consumer that does nothing with its parameterstatic final Function<System.Logger.Level, Consumer<Exception>> A function returning the exception logger for a given levelstatic final Map<System.Logger.Level, Consumer<Exception>> A map of exception logging consumers per level -
Method Summary
Modifier and TypeMethodDescriptionstatic <V> Consumer<V> Returns a composite consumer that delegates to zero or more consumers.static <V extends AutoCloseable>
Consumer<V> close()Returns a consumer that silently closes its object.static <V extends AutoCloseable>
Consumer<V> Returns a consumer that silently closes its object using the specified exception handler.default <V1,V2> BiConsumer <V1, V2> compose(BiFunction<V1, V2, T> mapper) Composes a binary consumer that invokes this consumer using result of the specified binary function.default <V> Consumer<V> Composes a consumer that invokes this consumer using result of the specified function.debug()Returns a consumer that logs an exception at theSystem.Logger.Level.DEBUGlevel.static <V> Consumer<V> empty()Returns a consumer that performs no action.error()Returns a consumer that logs an exception at theSystem.Logger.Level.ERRORlevel.handle(BiConsumer<T, RuntimeException> handler) Returns a new consumer that delegates to the specified handler in the event of an exception.info()Returns a consumer that logs an exception at theSystem.Logger.Level.INFOlevel.log(System.Logger.Level level) Returns a consumer that logs an exception at the specified level.static <V> Consumer<V> Returns a consumer that runs the specified task, ignoring its parameter.thenReturn(Supplier<R> factory) Returns a function that returns the value from the specified supplier after accepting its parameter via this consumer.throwing(Function<E, ? extends RuntimeException> exceptionFactory) Returns a consumer that wraps an exception as a runtime exception via the specified factory.warning()Returns a consumer that logs an exception at theSystem.Logger.Level.WARNINGlevel.Returns a consumer that conditionally invokes this consumer when allowed by the specified predicate.withDefault(Predicate<T> predicate, Supplier<T> defaultValue) Returns a consumer that accepts the value returned by the specified default provider if its value does not match the specified predicate.withMonitor(Function<T, M> monitorFunction) Returns a new consumer that accepts its value while holding the monitor returned by the specified function.
-
Field Details
-
EMPTY
A consumer that does nothing with its parameter -
EXCEPTION_LOGGERS
A map of exception logging consumers per level -
EXCEPTION_LOGGER
A function returning the exception logger for a given level
-
-
Method Details
-
andThen
-
when
Returns a consumer that conditionally invokes this consumer when allowed by the specified predicate.- Parameters:
predicate- a predicate that determines whether or not to invoke this consumer- Returns:
- a consumer that conditionally invokes this consumer when allowed by the specified predicate.
-
withDefault
Returns a consumer that accepts the value returned by the specified default provider if its value does not match the specified predicate.- Parameters:
predicate- a predicate used to determine the parameter of this consumerdefaultValue- a provider of the default parameter value- Returns:
- a consumer that accepts the value returned by the specified default provider if its value does not match the specified predicate.
-
compose
-
compose
Composes a binary consumer that invokes this consumer using result of the specified binary function.- Type Parameters:
V1- the former parameter typeV2- the latter parameter type- Parameters:
mapper- a mapping function- Returns:
- a binary consumer that invokes this consumer using result of the specified binary function.
-
handle
Returns a new consumer that delegates to the specified handler in the event of an exception.- Parameters:
handler- an exception handler- Returns:
- a new consumer that delegates to the specified handler in the event of an exception.
-
thenReturn
Returns a function that returns the value from the specified supplier after accepting its parameter via this consumer.- Type Parameters:
R- the return type- Parameters:
factory- a factory of the function return value- Returns:
- a function that returns the value from the specified supplier after accepting its parameter via this consumer.
-
withMonitor
Returns a new consumer that accepts its value while holding the monitor returned by the specified function.- Type Parameters:
M- a function returning an object monitor- Parameters:
monitorFunction- a function returning an object monitor.- Returns:
- a new consumer that accepts its value while holding the monitor returned by the specified function.
-
empty
Returns a consumer that performs no action.- Type Parameters:
V- the consumed type- Returns:
- an empty consumer
-
close
Returns a consumer that silently closes its object.- Type Parameters:
V- the auto-closeable type- Returns:
- an closing consumer
-
log
Returns a consumer that logs an exception at the specified level.- Type Parameters:
E- the exception type- Parameters:
level- the log level- Returns:
- an exception logging consumer
-
error
Returns a consumer that logs an exception at theSystem.Logger.Level.ERRORlevel.- Type Parameters:
E- the exception type- Returns:
- an exception logging consumer
-
warning
Returns a consumer that logs an exception at theSystem.Logger.Level.WARNINGlevel.- Type Parameters:
E- the exception type- Returns:
- an exception logging consumer
-
info
Returns a consumer that logs an exception at theSystem.Logger.Level.INFOlevel.- Type Parameters:
E- the exception type- Returns:
- an exception logging consumer
-
debug
Returns a consumer that logs an exception at theSystem.Logger.Level.DEBUGlevel.- Type Parameters:
E- the exception type- Returns:
- an exception logging consumer
-
close
Returns a consumer that silently closes its object using the specified exception handler.- Type Parameters:
V- the auto-closeable type- Parameters:
handler- an exception handler- Returns:
- a silent closing consumer
-
run
-
acceptAll
-
throwing
static <E extends Throwable> Consumer<E> throwing(Function<E, ? extends RuntimeException> exceptionFactory) Returns a consumer that wraps an exception as a runtime exception via the specified factory.- Type Parameters:
E- the exception type- Parameters:
exceptionFactory- a runtime exception wrapper- Returns:
- a consumer that wraps an exception as a runtime exception via the specified factory.
-