BiFunctionBuilder.java

1
package pro.verron.officestamper.core.functions;
2
3
import org.jetbrains.annotations.Contract;
4
import pro.verron.officestamper.api.CustomFunction;
5
import pro.verron.officestamper.core.DocxStamperConfiguration;
6
7
import java.util.List;
8
import java.util.function.BiFunction;
9
import java.util.function.Function;
10
11
/**
12
 * A builder class for creating and registering bi-functional implementations with a given configuration.
13
 * This class is responsible for bridging a BiFunction implementation into a custom function that
14
 * can be utilized within the provided configuration context.
15
 *
16
 * @param <T> the type of the first input parameter for the BiFunction
17
 * @param <U> the type of the second input parameter for the BiFunction
18
 */
19
public class BiFunctionBuilder<T, U>
20
        implements CustomFunction.NeedsBiFunctionImpl<T, U> {
21
    private final DocxStamperConfiguration source;
22
    private final String name;
23
    private final Class<T> class0;
24
    private final Class<U> class1;
25
26
    /**
27
     * Constructs a new {@code BiFunctionBuilder} instance, which enables the creation and registration
28
     * of a bi-functional implementation with the specified source configuration.
29
     *
30
     * @param source the configuration instance where the custom function will be registered
31
     * @param name the name given to the bi-functional custom function to identify it
32
     * @param class0 the {@code Class} type that represents the type of the first input parameter
33
     * @param class1 the {@code Class} type that represents the type of the second input parameter
34
     */
35
    @Contract(pure = true)
36
    public BiFunctionBuilder(DocxStamperConfiguration source, String name, Class<T> class0, Class<U> class1) {
37
        this.source = source;
38
        this.name = name;
39
        this.class0 = class0;
40
        this.class1 = class1;
41
    }
42
43
    @Override public void withImplementation(BiFunction<T, U, ?> implementation) {
44
        Function<List<Object>, Object> function = args -> {
45
            var arg0 = class0.cast(args.getFirst());
46
            var arg1 = class1.cast(args.get(1));
47 1 1. lambda$withImplementation$0 : replaced return value with null for pro/verron/officestamper/core/functions/BiFunctionBuilder::lambda$withImplementation$0 → KILLED
            return implementation.apply(arg0, arg1);
48
        };
49
        var customFunction = new CustomFunction(name, List.of(class0, class1), function);
50 1 1. withImplementation : removed call to pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → KILLED
        source.addCustomFunction(customFunction);
51
    }
52
}

Mutations

47

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

50

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

Active mutators

Tests examined


Report generated by PIT 1.20.0