BiFunctionBuilder.java

1
package pro.verron.officestamper.core.functions;
2
3
import pro.verron.officestamper.api.CustomFunction;
4
import pro.verron.officestamper.api.OfficeStamperConfiguration;
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
/// A builder class for creating and registering bifunctional implementations with a given configuration.
12
///
13
/// This class helps register a [BiFunction] as a [CustomFunction] for the given [OfficeStamperConfiguration]
14
///
15
/// @param <T> the type of the first input parameter for the BiFunction
16
/// @param <U> the type of the second input parameter for the BiFunction
17
public class BiFunctionBuilder<T, U>
18
        implements CustomFunction.NeedsBiFunctionImpl<T, U> {
19
    private final DocxStamperConfiguration source;
20
    private final String name;
21
    private final Class<T> class0;
22
    private final Class<U> class1;
23
24
    /// Constructs a new `BiFunctionBuilder` instance, which enables the creation and registration of a bifunctional
25
    /// implementation with the specified source configuration.
26
    ///
27
    /// @param source the configuration instance where the custom function will be registered
28
    /// @param name the name given to the bifunctional custom function to identify it.
29
    /// @param class0 the `Class` type that represents the type of the first input parameter.
30
    /// @param class1 the `Class` type that represents the type of the second input parameter.
31
32
    public BiFunctionBuilder(DocxStamperConfiguration source, String name, Class<T> class0, Class<U> class1) {
33
        this.source = source;
34
        this.name = name;
35
        this.class0 = class0;
36
        this.class1 = class1;
37
    }
38
39
    /// Registers a BiFunction implementation as a custom function within the current context.
40
    ///
41
    /// The provided implementation is converted into a generic custom function that accepts a list of arguments and
42
    /// produces a result. This method enables the addition of a bifunctional logic to the associated configuration,
43
    /// which can be invoked later with the defined parameter and behavior.
44
    ///
45
    /// @param implementation the BiFunction implementation to register, taking two input arguments types `T`
46
    ///         and `U`, and producing a result.
47
    @Override
48
    public OfficeStamperConfiguration withImplementation(BiFunction<T, U, ?> implementation) {
49
        Function<List<Object>, Object> function = args -> {
50
            var arg0 = class0.cast(args.getFirst());
51
            var arg1 = class1.cast(args.get(1));
52 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);
53
        };
54
        var customFunction = new CustomFunction(name, List.of(class0, class1), function);
55 1 1. withImplementation : removed call to pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → TIMED_OUT
        source.addCustomFunction(customFunction);
56 1 1. withImplementation : replaced return value with null for pro/verron/officestamper/core/functions/BiFunctionBuilder::withImplementation → KILLED
        return source;
57
    }
58
}

Mutations

52

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.utils.ContextFactory)]/[test-template-invocation:#1]
replaced return value with null for pro/verron/officestamper/core/functions/BiFunctionBuilder::lambda$withImplementation$0 → KILLED

55

1.1
Location : withImplementation
Killed by : none
removed call to pro/verron/officestamper/core/DocxStamperConfiguration::addCustomFunction → TIMED_OUT

56

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

Active mutators

Tests examined


Report generated by PIT 1.22.0