1 | package pro.verron.officestamper.core.functions; | |
2 | ||
3 | import pro.verron.officestamper.api.CustomFunction; | |
4 | import pro.verron.officestamper.core.DocxStamperConfiguration; | |
5 | import pro.verron.officestamper.utils.TriFunction; | |
6 | ||
7 | import java.util.List; | |
8 | import java.util.function.Function; | |
9 | ||
10 | /** | |
11 | * A builder class for defining and registering custom TriFunction implementations. | |
12 | * | |
13 | * This class is responsible for constructing a TriFunction implementation | |
14 | * with three input types and registering it within a provided {@code DocxStamperConfiguration}. | |
15 | * The TriFunction allows execution of a specific behavior based on the three input arguments | |
16 | * and provides a result. | |
17 | * | |
18 | * @param <T> the type of the first input to the TriFunction | |
19 | * @param <U> the type of the second input to the TriFunction | |
20 | * @param <V> the type of the third input to the TriFunction | |
21 | */ | |
22 | public class TriFunctionBuilder<T, U, V> | |
23 | implements CustomFunction.NeedsTriFunctionImpl<T, U, V> { | |
24 | private final DocxStamperConfiguration source; | |
25 | private final String name; | |
26 | private final Class<T> class0; | |
27 | private final Class<U> class1; | |
28 | private final Class<V> class2; | |
29 | ||
30 | /** | |
31 | * Constructs a new instance of TriFunctionBuilder. | |
32 | * | |
33 | * This constructor initializes the TriFunctionBuilder with the given configuration, name, and | |
34 | * input types. It prepares the builder to define and register a custom TriFunction. | |
35 | * | |
36 | * @param source the DocxStamperConfiguration to which the custom TriFunction will be registered | |
37 | * @param name the name of the custom TriFunction being defined | |
38 | * @param class0 the class of the first input type of the TriFunction | |
39 | * @param class1 the class of the second input type of the TriFunction | |
40 | * @param class2 the class of the third input type of the TriFunction | |
41 | */ | |
42 | public TriFunctionBuilder( | |
43 | DocxStamperConfiguration source, String name, Class<T> class0, Class<U> class1, Class<V> class2 | |
44 | ) { | |
45 | this.source = source; | |
46 | this.name = name; | |
47 | this.class0 = class0; | |
48 | this.class1 = class1; | |
49 | this.class2 = class2; | |
50 | } | |
51 | ||
52 | /** | |
53 | * Registers a custom implementation of a {@code TriFunction} that operates on three | |
54 | * input arguments of types {@code T}, {@code U}, and {@code V}, and produces a result. | |
55 | * The provided implementation is encapsulated as a {@code CustomFunction} and added | |
56 | * to the underlying configuration for later use. | |
57 | * | |
58 | * @param implementation the {@code TriFunction} implementation to register. This function | |
59 | * takes three input arguments of types {@code T}, {@code U}, | |
60 | * and {@code V} and produces a result. | |
61 | */ | |
62 | @Override public void withImplementation(TriFunction<T, U, V, ?> implementation) { | |
63 | Function<List<Object>, Object> function = args -> { | |
64 | var arg0 = class0.cast(args.getFirst()); | |
65 | var arg1 = class1.cast(args.get(1)); | |
66 | var arg2 = class2.cast(args.get(2)); | |
67 |
1
1. lambda$withImplementation$0 : replaced return value with null for pro/verron/officestamper/core/functions/TriFunctionBuilder::lambda$withImplementation$0 → KILLED |
return implementation.apply(arg0, arg1, arg2); |
68 | }; | |
69 | var customFunction = new CustomFunction(name, List.of(class0, class1, class2), function); | |
70 |
1
1. withImplementation : removed call to pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → KILLED |
source.addCustomFunction(customFunction); |
71 | } | |
72 | } | |
Mutations | ||
67 |
1.1 |
|
70 |
1.1 |