ExcelCollector.java

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

Mutations

35

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

36

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

43

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

52

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