Interface Consumer4<A,B,C,D>
- 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.
- All Known Subinterfaces:
BeanPropertyConsumer,ThrowingConsumer4<A,B, C, D>
- 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
four-argument consumers. It's useful when you need to pass operations with four 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(Consumer4)for operation chaining - Side-effect operations - designed for operations that perform side effects rather than return values
Use Cases:
- Four-argument operations in iteration patterns
- Builder methods that accept four-parameter operations
- Callback patterns with four parameters
- Event handlers that process four values
Usage:
See Also:
Consumer2- Two-argument consumerConsumer3- Three-argument consumerConsumer5- Five-argument consumer- juneau-commons Basics
-
Method Summary
Modifier and TypeMethodDescriptionReturns a composedConsumer4that performs, in sequence, this operation followed by theafteroperation.voidPerforms this operation on the given arguments.
-
Method Details
-
andThen
Returns a composedConsumer4that 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:
Consumer4<String,Integer,Boolean,Double>
log = (s ,i ,b ,d ) ->logger .info(s +": " +i +", " +b +", " +d ); Consumer4<String,Integer,Boolean,Double>store = (s ,i ,b ,d ) ->cache .put(s ,i ,b ,d ); Consumer4<String,Integer,Boolean,Double>logAndStore =log .andThen(store );logAndStore .apply("data" , 100,true , 50.0);// Logs and stores - Parameters:
after- The operation to perform after this operation. Must not benull .- Returns:
- A composed
Consumer4that performs in sequence this operation followed by theafteroperation. - Throws:
NullPointerException- ifafterisnull .
-
apply
Performs this operation on the given arguments.Example:
Consumer4<String,Integer,Boolean,Double>
handler = (key ,value ,flag ,weight ) -> {map .put(key ,value );if (flag )cache .invalidate(key );stats .record(weight ); };handler .apply("user" , 12345,true , 1.5);- Parameters:
a- The first operation argument.b- The second operation argument.c- The third operation argument.d- The fourth operation argument.
-