ExcelCollector.java

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

Mutations

41

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

42

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

51

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

62

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