ExcelCollector.java

1
package pro.verron.officestamper.experimental;
2
3
import org.jspecify.annotations.Nullable;
4
5
import java.util.ArrayList;
6
import java.util.List;
7
8
/// The ExcelCollector class is used to collect objects of a specific type from an Excel file.
9
/// It extends the ExcelVisitor class and overrides the 'before' method to add the objects of the given type to a list.
10
///
11
/// @param <T> the type of objects to collect
12
public class ExcelCollector<T>
13
        extends ExcelVisitor {
14
15
    private final Class<T> type;
16
    private final List<T> list = new ArrayList<>();
17
18
    /// Constructs a new ExcelCollector object with the given type.
19
    ///
20
    /// @param type the class representing the type of objects to collect
21
    public ExcelCollector(Class<T> type) {
22
        this.type = type;
23
    }
24
25
    /// Collects objects of a specific type from an Excel file.
26
    ///
27
    /// @param <T>    the type of objects to collect
28
    /// @param object the Excel file or object to collect from
29
    /// @param type   the class representing the type of objects to collect
30
    /// @return a List containing the collected objects
31
    public static <T> List<T> collect(
32
            Object object,
33
            Class<T> type
34
    ) {
35
        var collector = new ExcelCollector<>(type);
36 1 1. collect : removed call to pro/verron/officestamper/experimental/ExcelCollector::visit → KILLED
        collector.visit(object);
37 1 1. collect : replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/ExcelCollector::collect → KILLED
        return collector.collect();
38
    }
39
40
    /// Returns a List containing the collected objects.
41
    ///
42
    /// @return a List containing the collected objects
43
    public List<T> collect() {
44 1 1. collect : replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/ExcelCollector::collect → KILLED
        return list;
45
    }
46
47
    /// This method is called before visiting an object in the ExcelCollector class.
48
    /// It checks if the object is an instance of the specified type and adds it to a list if it is.
49
    ///
50
    /// @param object the object being visited
51
    @Override
52
    protected void before(@Nullable Object object) {
53 1 1. before : negated conditional → KILLED
        if (type.isInstance(object))
54
            list.add(type.cast(object));
55
    }
56
}

Mutations

36

1.1
Location : collect
Killed by : pro.verron.officestamper.test.BasicExcelTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicExcelTest]/[method:testStamper()]
removed call to pro/verron/officestamper/experimental/ExcelCollector::visit → KILLED

37

1.1
Location : collect
Killed by : pro.verron.officestamper.test.BasicExcelTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicExcelTest]/[method:testStamper()]
replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/ExcelCollector::collect → KILLED

44

1.1
Location : collect
Killed by : pro.verron.officestamper.test.BasicExcelTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicExcelTest]/[method:testStamper()]
replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/ExcelCollector::collect → KILLED

53

1.1
Location : before
Killed by : pro.verron.officestamper.test.BasicExcelTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.BasicExcelTest]/[method:testStamper()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.25.5 support