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