FunctionBuilder.java

1
package pro.verron.officestamper.core.functions;
2
3
import pro.verron.officestamper.api.CustomFunction;
4
import pro.verron.officestamper.core.DocxStamperConfiguration;
5
6
import java.util.List;
7
import java.util.function.Function;
8
9
/// A builder class for creating and registering custom functions in the context of a `DocxStamperConfiguration`.
10
/// The custom functions are defined by a name, a single input parameter type, and their implementation.
11
///
12
/// @param <T> the type of the input to the function
13
public class FunctionBuilder<T>
14
        implements CustomFunction.NeedsFunctionImpl<T> {
15
    private final DocxStamperConfiguration source;
16
    private final String name;
17
    private final Class<T> class0;
18
19
    /// Constructs a new `FunctionBuilder` to define and register a custom function in the provided
20
    /// `DocxStamperConfiguration`.
21
    ///
22
    /// @param source the `DocxStamperConfiguration` instance in which the custom function will be registered
23
    /// @param name   the name of the custom function to be defined
24
    /// @param class0 the `Class` object representing the type of the single input parameter for the custom function
25
    public FunctionBuilder(DocxStamperConfiguration source, String name, Class<T> class0) {
26
        this.source = source;
27
        this.name = name;
28
        this.class0 = class0;
29
    }
30
31
    /// Sets the implementation for the custom function being built.
32
    /// The implementation defines the behavior of the function for a specific input type and is wrapped in a
33
    /// `CustomFunction` instance that is added to the configuration.
34
    ///
35
    /// @param implementation a `Function` that takes an input of type `T` and produces a result
36
    @Override
37
    public void withImplementation(Function<T, ?> implementation) {
38
        Function<List<Object>, Object> objectFunction = args -> {
39
            var arg0 = class0.cast(args.getFirst());
40 1 1. lambda$withImplementation$0 : replaced return value with null for pro/verron/officestamper/core/functions/FunctionBuilder::lambda$withImplementation$0 → KILLED
            return implementation.apply(arg0);
41
        };
42
        var customFunction = new CustomFunction(name, List.of(class0), objectFunction);
43 1 1. withImplementation : removed call to pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → KILLED
        source.addCustomFunction(customFunction);
44
    }
45
}

Mutations

40

1.1
Location : lambda$withImplementation$0
Killed by : pro.verron.officestamper.test.CustomFunctionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.CustomFunctionTests]/[test-template:functions(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#1]
replaced return value with null for pro/verron/officestamper/core/functions/FunctionBuilder::lambda$withImplementation$0 → KILLED

43

1.1
Location : withImplementation
Killed by : pro.verron.officestamper.test.CustomFunctionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.CustomFunctionTests]/[test-template:functions(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#1]
removed call to pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → KILLED

Active mutators

Tests examined


Report generated by PIT 1.21.0