Interface ThrowingFunction4<A,B,C,D,R>
- Type Parameters:
A- The type of the first argument to the function.B- The type of the second argument to the function.C- The type of the third argument to the function.D- The type of the fourth argument to the function.R- The type of the result of the function.
- All Superinterfaces:
Function4<A,B, C, D, R>
- 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 Function4 to allow the functional method
to throw checked exceptions. The default apply(Object, Object, Object, Object) method wraps any checked exceptions in a
RuntimeException, making it compatible with standard Function4 usage while still allowing
the implementation to throw checked exceptions via applyThrows(Object, Object, Object, Object).
Features:
- Functional interface - can be used with lambda expressions and method references
- Exception support - allows checked exceptions to be thrown via
applyThrows(Object, Object, Object, Object) - Compatible with Function4 - implements
Function4.apply(Object, Object, Object, Object)by wrapping exceptions - Dual interface - can be used as both Function4 and ThrowingFunction4
Use Cases:
- Four-argument transformations that may throw I/O exceptions
- Parsing operations that may throw validation exceptions
- Data conversion that may fail with checked exceptions
- Operations that need to propagate checked exceptions
Usage:
Exception Handling:
applyThrows(Object, Object, Object, Object)- Throws checked exceptions directlyapply(Object, Object, Object, Object)- Wraps checked exceptions inRuntimeException- Use
applyThrowswhen you need to handle specific checked exceptions - Use
applywhen you want standard Function4 behavior
See Also:
ThrowingFunction- Single-argument function that throws exceptionsThrowingFunction2- Two-argument function that throws exceptionsThrowingFunction3- Three-argument function that throws exceptionsThrowingFunction5- Five-argument function that throws exceptions- juneau-commons Basics
-
Method Summary
Modifier and TypeMethodDescriptiondefault <V> ThrowingFunction4<A,B, C, D, V> Returns a composed function that first applies this function to its input, and then applies theafterfunction to the result.default RApplies this function to the given arguments, wrapping any checked exceptions in aRuntimeException.applyThrows(A a, B b, C c, D d) Applies this function to the given arguments, potentially throwing a checked exception.
-
Method Details
-
apply
Applies this function to the given arguments, wrapping any checked exceptions in aRuntimeException.This is the default implementation that makes this interface compatible with
Function4. It callsapplyThrows(Object, Object, Object, Object)and wraps any checked exceptions.- Specified by:
applyin interfaceFunction4<A,B, C, D, R> - Parameters:
a- The first function argument.b- The second function argument.c- The third function argument.d- The fourth function argument.- Returns:
- The function result.
- Throws:
RuntimeException- ifapplyThrows(Object, Object, Object, Object)throws a checked exception.
-
andThen
Returns a composed function that first applies this function to its input, and then applies theafterfunction to the result.This method enables function composition, allowing you to chain multiple transformations together. The composed function will throw exceptions from this function, but the
afterfunction is a standardFunctionthat does not throw checked exceptions.- Specified by:
andThenin interfaceFunction4<A,B, C, D, R> - Type Parameters:
V- The type of output of theafterfunction, and of the composed function.- Parameters:
after- The function to apply after this function is applied. Must not benull .- Returns:
- A composed
ThrowingFunction4that first applies this function and then applies theafterfunction. - Throws:
NullPointerException- ifafterisnull .
-
applyThrows
Applies this function to 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
Function4.apply(Object, Object, Object, Object)method.Example:
ThrowingFunction4<String,Integer,Boolean,Double,Integer>
parser = (s ,base ,signed ,multiplier ) -> {try {int value = Integer.parseInt(s ,base );value =signed ?value : Math.abs(value );return (int )(value *multiplier ); }catch (NumberFormatExceptione ) {throw new ParseException("Invalid number: " +s +" in base " +base , 0); } };try {int value =parser .applyThrows("123" , 10,true , 2.0); }catch (ParseExceptione ) {// Handle checked exception }- Parameters:
a- The first function argument.b- The second function argument.c- The third function argument.d- The fourth function argument.- Returns:
- The function result.
- Throws:
Exception- If an error occurs during function execution.
-