| 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 | /// | |
| 31 | /// @return a List containing the collected objects | |
| 32 | public static <T> List<T> collect( | |
| 33 | Object object, | |
| 34 | Class<T> type | |
| 35 | ) { | |
| 36 | var collector = new ExcelCollector<>(type); | |
| 37 |
1
1. collect : removed call to pro/verron/officestamper/experimental/ExcelCollector::visit → KILLED |
collector.visit(object); |
| 38 |
1
1. collect : replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/ExcelCollector::collect → KILLED |
return collector.collect(); |
| 39 | } | |
| 40 | ||
| 41 | /// Returns a List containing the collected objects. | |
| 42 | /// | |
| 43 | /// @return a List containing the collected objects | |
| 44 | public List<T> collect() { | |
| 45 |
1
1. collect : replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/ExcelCollector::collect → KILLED |
return list; |
| 46 | } | |
| 47 | ||
| 48 | /// This method is called before visiting an object in the ExcelCollector class. | |
| 49 | /// It checks if the object is an instance of the specified type and adds it to a list if it is. | |
| 50 | /// | |
| 51 | /// @param object the object being visited | |
| 52 | @Override | |
| 53 | protected void before(@Nullable Object object) { | |
| 54 |
1
1. before : negated conditional → KILLED |
if (type.isInstance(object)) |
| 55 | list.add(type.cast(object)); | |
| 56 | } | |
| 57 | } | |
Mutations | ||
| 37 |
1.1 |
|
| 38 |
1.1 |
|
| 45 |
1.1 |
|
| 54 |
1.1 |