Interface ThrowingConsumer5<A,B,C,D,E>

Type Parameters:
A - The type of the first argument to the operation.
B - The type of the second argument to the operation.
C - The type of the third argument to the operation.
D - The type of the fourth argument to the operation.
E - The type of the fifth argument to the operation.
All Superinterfaces:
Consumer5<A,B,C,D,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 ThrowingConsumer5<A,B,C,D,E> extends Consumer5<A,B,C,D,E>
A functional interface representing an operation that accepts five arguments, returns no result, and may throw a checked exception.

This interface extends Consumer5 to allow the functional method to throw checked exceptions. The default apply(Object, Object, Object, Object, Object) method wraps any checked exceptions in a RuntimeException, making it compatible with standard Consumer5 usage while still allowing the implementation to throw checked exceptions via acceptThrows(Object, Object, Object, Object, Object).

Features:
Use Cases:
  • Five-argument operations that may throw I/O exceptions
  • Validation operations that may throw validation exceptions
  • Side-effect operations that may fail with checked exceptions
  • Operations that need to propagate checked exceptions
Usage:

// Lambda with exception ThrowingConsumer5<String,Integer,Boolean,Double,Long> fileWriter = (path, content, append, timeout, timestamp) -> { if (append) { Files.write(Paths.get(path), content.getBytes(), StandardOpenOption.APPEND); } else { Files.write(Paths.get(path), content.getBytes()); } }; // Using acceptThrows to get checked exception try { fileWriter.acceptThrows("/tmp/output.txt", "Hello World", true, 5.0, 1234567890L); } catch (IOException e) { // Handle checked exception } // Using apply wraps exception in RuntimeException fileWriter.apply("/tmp/output.txt", "Hello World", true, 5.0, 1234567890L); // May throw RuntimeException

Exception Handling:
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    acceptThrows(A a, B b, C c, D d, E e)
    Performs this operation on the given arguments, potentially throwing a checked exception.
    andThen(ThrowingConsumer5<? super A,? super B,? super C,? super D,? super E> after)
    Returns a composed ThrowingConsumer5 that performs, in sequence, this operation followed by the after operation.
    default void
    apply(A a, B b, C c, D d, E e)
    Performs this operation on the given arguments, wrapping any checked exceptions in a RuntimeException.

    Methods inherited from interface org.apache.juneau.commons.function.Consumer5

    andThen
  • Method Details

    • apply

      default void apply(A a, B b, C c, D d, E e)
      Performs this operation on the given arguments, wrapping any checked exceptions in a RuntimeException.

      This is the default implementation that makes this interface compatible with Consumer5. It calls acceptThrows(Object, Object, Object, Object, Object) and wraps any checked exceptions.

      Specified by:
      apply in interface Consumer5<A,B,C,D,E>
      Parameters:
      a - The first operation argument.
      b - The second operation argument.
      c - The third operation argument.
      d - The fourth operation argument.
      e - The fifth operation argument.
      Throws:
      RuntimeException - if acceptThrows(Object, Object, Object, Object, Object) throws a checked exception.
    • andThen

      default ThrowingConsumer5<A,B,C,D,E> andThen(ThrowingConsumer5<? super A,? super B,? super C,? super D,? super E> after)
      Returns a composed ThrowingConsumer5 that performs, in sequence, this operation followed by the after operation.

      This method enables operation composition, allowing you to chain multiple operations together. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, the after operation will not be performed.

      Parameters:
      after - The operation to perform after this operation. Must not be null.
      Returns:
      A composed ThrowingConsumer5 that performs in sequence this operation followed by the after operation.
      Throws:
      NullPointerException - if after is null.
    • acceptThrows

      void acceptThrows(A a, B b, C c, D d, E e) throws Exception
      Performs this operation on the given arguments, potentially throwing a checked exception.

      This is the functional method that implementations must provide. It allows checked exceptions to be thrown directly, unlike the standard Consumer5.apply(Object, Object, Object, Object, Object) method.

      Example:

      ThrowingConsumer5<String,Integer,Boolean,Double,Long> validator = (name, age, active, score, timestamp) -> { if (name == null || name.isEmpty()) { throw new ValidationException("Name cannot be empty"); } if (age < 0) { throw new ValidationException("Age cannot be negative"); } }; try { validator.acceptThrows("", -1, true, 0.0, 0L); } catch (ValidationException e) { // Handle checked exception }

      Parameters:
      a - The first operation argument.
      b - The second operation argument.
      c - The third operation argument.
      d - The fourth operation argument.
      e - The fifth operation argument.
      Throws:
      Exception - If an error occurs during operation execution.