| 1 | package com.takenoko.stats; | |
| 2 | ||
| 3 | import com.opencsv.CSVReader; | |
| 4 | import com.opencsv.CSVWriter; | |
| 5 | import java.io.File; | |
| 6 | import java.io.FileReader; | |
| 7 | import java.io.FileWriter; | |
| 8 | import java.nio.file.Paths; | |
| 9 | import java.util.*; | |
| 10 | ||
| 11 | public abstract class CSVExporter { | |
| 12 | File csvPath; | |
| 13 | ||
| 14 | @SuppressWarnings("java:S112") | |
| 15 | protected CSVExporter(String filePath) { | |
| 16 | csvPath = Paths.get(filePath).toFile(); | |
| 17 | ||
| 18 | // Create the folder if it doesn't exist | |
| 19 |
2
1. <init> : negated conditional → NO_COVERAGE 2. <init> : negated conditional → KILLED |
if (!csvPath.getParentFile().exists() && !csvPath.getParentFile().mkdirs()) { |
| 20 | throw new RuntimeException("Could not create directory for CSV file"); | |
| 21 | } | |
| 22 | ||
| 23 | // Try and read latest CSV file | |
| 24 |
3
1. <init> : negated conditional → SURVIVED 2. <init> : negated conditional → NO_COVERAGE 3. <init> : negated conditional → NO_COVERAGE |
if (csvPath.exists() && csvPath.isFile() && csvPath.canRead()) { |
| 25 | // Load data | |
| 26 | try (CSVReader reader = new CSVReader(new FileReader(csvPath.toPath().toFile()))) { | |
| 27 |
1
1. <init> : removed call to com/takenoko/stats/CSVExporter::readData → NO_COVERAGE |
readData(reader.readAll()); |
| 28 | } catch (Exception e) { | |
| 29 |
1
1. <init> : removed call to java/lang/Exception::printStackTrace → NO_COVERAGE |
e.printStackTrace(); |
| 30 | } | |
| 31 | } | |
| 32 | } | |
| 33 | ||
| 34 | public void writeCSV() { | |
| 35 | // Format data into CSV friendly format | |
| 36 | List<String[]> contents = writeData(); | |
| 37 | ||
| 38 | // Write to CSV file | |
| 39 | try (CSVWriter writer = new CSVWriter(new FileWriter(this.csvPath.toPath().toFile()))) { | |
| 40 |
1
1. writeCSV : removed call to com/opencsv/CSVWriter::writeAll → NO_COVERAGE |
writer.writeAll(contents); |
| 41 | } catch (Exception e) { | |
| 42 |
1
1. writeCSV : removed call to java/lang/Exception::printStackTrace → NO_COVERAGE |
e.printStackTrace(); |
| 43 | } | |
| 44 | } | |
| 45 | ||
| 46 | protected abstract void readData(List<String[]> data); | |
| 47 | ||
| 48 | protected abstract List<String[]> writeData(); | |
| 49 | } | |
Mutations | ||
| 19 |
1.1 2.2 |
|
| 24 |
1.1 2.2 3.3 |
|
| 27 |
1.1 |
|
| 29 |
1.1 |
|
| 40 |
1.1 |
|
| 42 |
1.1 |