Interface Consumer<T>

Type Parameters:
T - the accepted type
All Superinterfaces:
Consumer<T>
All Known Implementing Classes:
CacheEntriesTask, CacheKeysTask, Consumer.ExceptionLogger

public interface Consumer<T> extends Consumer<T>
An enhanced unary consumer.
Author:
Paul Ferraro
  • Field Details

  • Method Details

    • andThen

      default Consumer<T> andThen(Consumer<? super T> after)
      Specified by:
      andThen in interface Consumer<T>
    • when

      default Consumer<T> when(Predicate<T> predicate)
      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

      default Consumer<T> 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.
      Parameters:
      predicate - a predicate used to determine the parameter of this consumer
      defaultValue - 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

      default <V> Consumer<V> compose(Function<V,T> mapper)
      Composes a consumer that invokes this consumer using result of the specified function.
      Type Parameters:
      V - the mapped type
      Parameters:
      mapper - a mapping function
      Returns:
      a mapped consumer
    • compose

      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.
      Type Parameters:
      V1 - the former parameter type
      V2 - 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

      default Consumer<T> handle(BiConsumer<T, RuntimeException> handler)
      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

      default <R> Function<T,R> thenReturn(Supplier<R> factory)
      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

      default <M> Consumer<T> withMonitor(Function<T,M> monitorFunction)
      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

      static <V> Consumer<V> empty()
      Returns a consumer that performs no action.
      Type Parameters:
      V - the consumed type
      Returns:
      an empty consumer
    • close

      static <V extends AutoCloseable> Consumer<V> close()
      Returns a consumer that silently closes its object.
      Type Parameters:
      V - the auto-closeable type
      Returns:
      an closing consumer
    • log

      static <E extends Exception> Consumer<E> log(System.Logger.Level level)
      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

      static <E extends Exception> Consumer<E> error()
      Returns a consumer that logs an exception at the System.Logger.Level.ERROR level.
      Type Parameters:
      E - the exception type
      Returns:
      an exception logging consumer
    • warning

      static <E extends Exception> Consumer<E> warning()
      Returns a consumer that logs an exception at the System.Logger.Level.WARNING level.
      Type Parameters:
      E - the exception type
      Returns:
      an exception logging consumer
    • info

      static <E extends Exception> Consumer<E> info()
      Returns a consumer that logs an exception at the System.Logger.Level.INFO level.
      Type Parameters:
      E - the exception type
      Returns:
      an exception logging consumer
    • debug

      static <E extends Exception> Consumer<E> debug()
      Returns a consumer that logs an exception at the System.Logger.Level.DEBUG level.
      Type Parameters:
      E - the exception type
      Returns:
      an exception logging consumer
    • close

      static <V extends AutoCloseable> Consumer<V> close(Consumer<Exception> handler)
      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

      static <V> Consumer<V> run(Runnable task)
      Returns a consumer that runs the specified task, ignoring its parameter.
      Type Parameters:
      V - the ignored parameter type
      Parameters:
      task - a runnable task
      Returns:
      a consumer that runs the specified task, ignoring its parameter.
    • acceptAll

      static <V> Consumer<V> acceptAll(Iterable<? extends Consumer<? super V>> consumers)
      Returns a composite consumer that delegates to zero or more consumers.
      Type Parameters:
      V - the consumed type
      Parameters:
      consumers - zero or more consumers
      Returns:
      a composite consumer
    • 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.