Skip to content

Commit

Permalink
Implemented suggestions from pr.
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoOfTwelve committed Nov 20, 2023
1 parent 0e726b7 commit 815cd35
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
15 changes: 7 additions & 8 deletions cli/src/main/java/de/jplag/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public static void main(String[] args) {
ReportObjectFactory reportObjectFactory = new ReportObjectFactory();
reportObjectFactory.createAndSaveReport(result, cli.getResultFolder());

cli.printCsv(result);
if (cli.options.csv.print) {
cli.printCsv(result);
}
}
} catch (ExitException exception) {
logger.error(exception.getMessage()); // do not pass exception here to keep log clean
Expand All @@ -91,13 +93,10 @@ public static void main(String[] args) {
}

private void printCsv(JPlagResult result) {
if (options.csv.print) {
try {
CsvComparisonOutput.writeCsvResults(result.getAllComparisons(), options.csv.anonymize, new File(getResultFolder()),
options.csv.fileName);
} catch (IOException e) {
logger.error("Could not write csv", e);
}
try {
CsvComparisonOutput.writeCsvResults(result.getAllComparisons(), options.csv.anonymize, new File(getResultFolder()), options.csv.fileName);
} catch (IOException e) {
logger.error("Could not write csv", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private CsvComparisonOutput() {
* @param fileName The base name for the file without ".csv"
*/
public static void writeCsvResults(List<JPlagComparison> comparisons, boolean anonymize, File directory, String fileName) throws IOException {
NameMapper mapper = new NameMapper.DirectMapper();
NameMapper mapper = new NameMapper.IdentityMapper();
directory.mkdirs();

if (anonymize) {
Expand All @@ -51,8 +51,8 @@ public static void writeCsvResults(List<JPlagComparison> comparisons, boolean an

if (anonymize) {
List<Map.Entry<String, String>> nameMap = mapper.getNameMap();
CsvDataMapper<Map.Entry<String, String>> namesMapMapper = new HardcodedCsvDataMapper<>(2, it -> new String[] {it.getKey(), it.getValue()},
new String[] {"realName", "id"});
CsvDataMapper<Map.Entry<String, String>> namesMapMapper = new HardcodedCsvDataMapper<>(2, it -> new String[] {it.getValue(), it.getKey()},
new String[] {"id", "realName"});
CsvPrinter<Map.Entry<String, String>> namesPrinter = new CsvPrinter<>(namesMapMapper);
namesPrinter.addRows(nameMap);
namesPrinter.printToFile(new File(directory, fileName + "-names.csv"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface NameMapper {
/**
* Simple implementation, that does not change the names.
*/
class DirectMapper implements NameMapper {
class IdentityMapper implements NameMapper {
@Override
public String map(String original) {
return original;
Expand Down

0 comments on commit 815cd35

Please sign in to comment.