Interface Consumer3<A,B,C>
- 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.
- All Known Subinterfaces:
ThrowingConsumer3<A,B, C>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
This interface extends the standard Java Consumer pattern to support
three-argument consumers. It's useful when you need to pass operations with three parameters to methods
that expect functional interfaces, such as in iteration, builders, or callback patterns.
Features:
- Functional interface - can be used with lambda expressions and method references
- Composition support - provides
andThen(Consumer3)for operation chaining - Side-effect operations - designed for operations that perform side effects rather than return values
Use Cases:
- Three-argument operations in iteration patterns
- Builder methods that accept three-parameter operations
- Callback patterns with three parameters
- Event handlers that process three values
Usage:
See Also:
Consumer2- Two-argument consumerConsumer4- Four-argument consumerConsumer5- Five-argument consumer- juneau-commons Basics
-
Method Summary
-
Method Details
-
andThen
Returns a composedConsumer3that performs, in sequence, this operation followed by theafteroperation.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
afteroperation will not be performed.Example:
Consumer3<String,Integer,Boolean>
log = (s ,i ,b ) ->logger .info(s +": " +i +", " +b ); Consumer3<String,Integer,Boolean>store = (s ,i ,b ) ->cache .put(s ,i ,b ); Consumer3<String,Integer,Boolean>logAndStore =log .andThen(store );logAndStore .apply("data" , 100,true );// Logs and stores - Parameters:
after- The operation to perform after this operation. Must not benull .- Returns:
- A composed
Consumer3that performs in sequence this operation followed by theafteroperation. - Throws:
NullPointerException- ifafterisnull .
-
apply
Performs this operation on the given arguments.Example:
Consumer3<String,Integer,Boolean>
handler = (key ,value ,flag ) -> {map .put(key ,value );if (flag )cache .invalidate(key ); };handler .apply("user" , 12345,true );- Parameters:
a- The first operation argument.b- The second operation argument.c- The third operation argument.
-