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

Mutations

44

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

47

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.20.0