From 9ebf6f5a1ba1f0373f3b5ec4e19dea21384cd1b5 Mon Sep 17 00:00:00 2001 From: Niels Faurskov Date: Thu, 20 Apr 2023 17:55:59 +0200 Subject: [PATCH 1/4] File total tokens added to report output --- .../jplag/reporting/jsonfactory/ComparisonReportWriter.java | 5 ++++- .../java/de/jplag/reporting/reportobject/model/Match.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java index 7fda46f69..f95363360 100644 --- a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java +++ b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java @@ -103,9 +103,12 @@ private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Mat Token startOfSecond = tokensSecond.stream().min(lineComparator).orElseThrow(); Token endOfSecond = tokensSecond.stream().max(lineComparator).orElseThrow(); + List file1TotalTokens = tokensFirst.stream().filter(x -> x.getFile() != null && x.getFile().equals(startOfFirst.getFile())).toList(); + List file2TotalTokens = tokensSecond.stream().filter(x -> x.getFile() != null && x.getFile().equals(startOfSecond.getFile())).toList(); + return new Match(relativizedFilePath(startOfFirst.getFile(), comparison.firstSubmission()), relativizedFilePath(startOfSecond.getFile(), comparison.secondSubmission()), startOfFirst.getLine(), endOfFirst.getLine(), - startOfSecond.getLine(), endOfSecond.getLine(), match.length()); + startOfSecond.getLine(), endOfSecond.getLine(), match.length(), file1TotalTokens.size(), file2TotalTokens.size()); } private String relativizedFilePath(File file, Submission submission) { diff --git a/core/src/main/java/de/jplag/reporting/reportobject/model/Match.java b/core/src/main/java/de/jplag/reporting/reportobject/model/Match.java index 8af13af20..9066d058f 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/model/Match.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/model/Match.java @@ -4,5 +4,5 @@ public record Match(@JsonProperty("file1") String firstFileName, @JsonProperty("file2") String secondFileName, @JsonProperty("start1") int startInFirst, @JsonProperty("end1") int endInFirst, @JsonProperty("start2") int startInSecond, - @JsonProperty("end2") int endInSecond, @JsonProperty("tokens") int tokens) { + @JsonProperty("end2") int endInSecond, @JsonProperty("tokens") int tokens, @JsonProperty("file1Tokens") long file1Tokens, @JsonProperty("file2Tokens") long file2Tokens) { } From f2aae565c55a820137030aa4075b1cbad2ebdc2f Mon Sep 17 00:00:00 2001 From: Niels Faurskov Date: Fri, 21 Apr 2023 11:36:54 +0200 Subject: [PATCH 2/4] Renamed variables and ran mvn:spotless --- .../reporting/jsonfactory/ComparisonReportWriter.java | 7 ++++--- .../java/de/jplag/reporting/reportobject/model/Match.java | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java index f95363360..b5f729249 100644 --- a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java +++ b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java @@ -103,12 +103,13 @@ private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Mat Token startOfSecond = tokensSecond.stream().min(lineComparator).orElseThrow(); Token endOfSecond = tokensSecond.stream().max(lineComparator).orElseThrow(); - List file1TotalTokens = tokensFirst.stream().filter(x -> x.getFile() != null && x.getFile().equals(startOfFirst.getFile())).toList(); - List file2TotalTokens = tokensSecond.stream().filter(x -> x.getFile() != null && x.getFile().equals(startOfSecond.getFile())).toList(); + List firstTotalTokens = tokensFirst.stream().filter(x -> x.getFile() != null && x.getFile().equals(startOfFirst.getFile())).toList(); + List secondTotalTokens = tokensSecond.stream().filter(x -> x.getFile() != null && x.getFile().equals(startOfSecond.getFile())) + .toList(); return new Match(relativizedFilePath(startOfFirst.getFile(), comparison.firstSubmission()), relativizedFilePath(startOfSecond.getFile(), comparison.secondSubmission()), startOfFirst.getLine(), endOfFirst.getLine(), - startOfSecond.getLine(), endOfSecond.getLine(), match.length(), file1TotalTokens.size(), file2TotalTokens.size()); + startOfSecond.getLine(), endOfSecond.getLine(), match.length(), firstTotalTokens.size(), secondTotalTokens.size()); } private String relativizedFilePath(File file, Submission submission) { diff --git a/core/src/main/java/de/jplag/reporting/reportobject/model/Match.java b/core/src/main/java/de/jplag/reporting/reportobject/model/Match.java index 9066d058f..3f708dc1b 100644 --- a/core/src/main/java/de/jplag/reporting/reportobject/model/Match.java +++ b/core/src/main/java/de/jplag/reporting/reportobject/model/Match.java @@ -4,5 +4,6 @@ public record Match(@JsonProperty("file1") String firstFileName, @JsonProperty("file2") String secondFileName, @JsonProperty("start1") int startInFirst, @JsonProperty("end1") int endInFirst, @JsonProperty("start2") int startInSecond, - @JsonProperty("end2") int endInSecond, @JsonProperty("tokens") int tokens, @JsonProperty("file1Tokens") long file1Tokens, @JsonProperty("file2Tokens") long file2Tokens) { + @JsonProperty("end2") int endInSecond, @JsonProperty("tokens") int tokens, @JsonProperty("file1Tokens") long file1Tokens, + @JsonProperty("file2Tokens") long file2Tokens) { } From 462260176935a6dcb668260b868a95108fbd5806 Mon Sep 17 00:00:00 2001 From: Niels Faurskov Date: Mon, 1 May 2023 21:30:48 +0200 Subject: [PATCH 3/4] Switched to Objects.equals --- .../jplag/reporting/jsonfactory/ComparisonReportWriter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java index b5f729249..735dfb294 100644 --- a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java +++ b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java @@ -5,6 +5,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; @@ -103,9 +104,8 @@ private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Mat Token startOfSecond = tokensSecond.stream().min(lineComparator).orElseThrow(); Token endOfSecond = tokensSecond.stream().max(lineComparator).orElseThrow(); - List firstTotalTokens = tokensFirst.stream().filter(x -> x.getFile() != null && x.getFile().equals(startOfFirst.getFile())).toList(); - List secondTotalTokens = tokensSecond.stream().filter(x -> x.getFile() != null && x.getFile().equals(startOfSecond.getFile())) - .toList(); + List firstTotalTokens = tokensFirst.stream().filter(x -> Objects.equals(x.getFile(), startOfFirst.getFile())).toList(); + List secondTotalTokens = tokensSecond.stream().filter(x -> Objects.equals(x.getFile(), startOfSecond.getFile())).toList(); return new Match(relativizedFilePath(startOfFirst.getFile(), comparison.firstSubmission()), relativizedFilePath(startOfSecond.getFile(), comparison.secondSubmission()), startOfFirst.getLine(), endOfFirst.getLine(), From e060624ad6fadd27e1fe6b96d747bf10e896fb3c Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Wed, 10 May 2023 16:49:30 +0200 Subject: [PATCH 4/4] Fixed formatting for spotless. --- .../de/jplag/reporting/jsonfactory/ComparisonReportWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java index 2e1ac3840..5b3594979 100644 --- a/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java +++ b/core/src/main/java/de/jplag/reporting/jsonfactory/ComparisonReportWriter.java @@ -105,7 +105,7 @@ private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Mat List firstTotalTokens = tokensFirst.stream().filter(x -> Objects.equals(x.getFile(), startOfFirst.getFile())).toList(); List secondTotalTokens = tokensSecond.stream().filter(x -> Objects.equals(x.getFile(), startOfSecond.getFile())).toList(); - + return new Match(FilePathUtil.getRelativeSubmissionPath(startOfFirst.getFile(), comparison.firstSubmission(), submissionToIdFunction), FilePathUtil.getRelativeSubmissionPath(startOfSecond.getFile(), comparison.secondSubmission(), submissionToIdFunction), startOfFirst.getLine(), endOfFirst.getLine(), startOfSecond.getLine(), endOfSecond.getLine(), match.length(), firstTotalTokens.size(),