Nesta Bentum 4 лет назад
Родитель
Сommit
7315125035

+ 3 - 3
jplag/src/main/java/de/jplag/JPlagResult.java

@@ -140,10 +140,10 @@ public class JPlagResult {
         for (JPlagComparison comparison : comparisons) {
             float similarity = similarityExtractor.apply(comparison); // extract similarity in percent: 0f <= similarity <= 100f
             int index = (int) (similarity / similarityDistributionBucketSize); // divide similarity by bucket size to find index of correct bucket.
-            if (index == SIMILARITY_DISTRIBUTION_SIZE)
-                index--; // index is out of bounds when similarity is 100%. decrease by one to count towards the highest value bucket
+            index = Math.min(index, SIMILARITY_DISTRIBUTION_SIZE - 1);// index is out of bounds when similarity is 100%. decrease by one to count
+                                                                      // towards the highest value bucket
             similarityDistribution[SIMILARITY_DISTRIBUTION_SIZE - 1 - index]++; // count comparison towards its determined bucket. bucket order is
-                                                                                // reversed, so that the highest value bucket has the lowest index
+            // reversed, so that the highest value bucket has the lowest index
         }
         return similarityDistribution;
     }

+ 2 - 4
jplag/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java

@@ -47,10 +47,8 @@ public class ReportObjectFactory {
 
     private static File createDirectory(String path, String name) {
         File directory = new File(path.concat("/").concat(name));
-        if (!directory.exists()) {
-            if (!directory.mkdirs()) {
-                logger.error("Failed to create dir.");
-            }
+        if (!directory.exists() && !directory.mkdirs()) {
+            logger.error("Failed to create dir.");
         }
         return directory;
     }

+ 7 - 9
jplag/src/main/java/de/jplag/reporting/reportobject/mapper/ComparisonReportMapper.java

@@ -1,7 +1,6 @@
 package de.jplag.reporting.reportobject.mapper;
 
 import java.util.List;
-import java.util.stream.Collectors;
 
 import de.jplag.*;
 import de.jplag.reporting.jsonfactory.FileWriter;
@@ -34,23 +33,22 @@ public class ComparisonReportMapper {
 
     private List<Match> convertMatchesToReportMatches(JPlagResult result, JPlagComparison comparison) {
         return comparison.getMatches().stream()
-                .map(match -> convertMatchToReportMatch(comparison, match, result.getOptions().getLanguage().usesIndex()))
-                .collect(Collectors.toList());
+                .map(match -> convertMatchToReportMatch(comparison, match, result.getOptions().getLanguage().supportsColumns())).toList();
     }
 
-    private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Match match, Boolean usesIndex) {
+    private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Match match, boolean usesIndex) {
         TokenList tokensFirst = comparison.getFirstSubmission().getTokenList();
         TokenList tokensSecond = comparison.getSecondSubmission().getTokenList();
-        Token startTokenFirst = tokensFirst.getToken(match.getStartOfFirst());
-        Token endTokenFirst = tokensFirst.getToken(match.getStartOfFirst() + match.getLength() - 1);
-        Token startTokenSecond = tokensSecond.getToken(match.getStartOfSecond());
-        Token endTokenSecond = tokensSecond.getToken(match.getStartOfSecond() + match.getLength() - 1);
+        Token startTokenFirst = tokensFirst.getToken(match.startOfFirst());
+        Token endTokenFirst = tokensFirst.getToken(match.startOfFirst() + match.length() - 1);
+        Token startTokenSecond = tokensSecond.getToken(match.startOfSecond());
+        Token endTokenSecond = tokensSecond.getToken(match.startOfSecond() + match.length() - 1);
 
         int startFirst = usesIndex ? startTokenFirst.getIndex() : startTokenFirst.getLine();
         int endFirst = usesIndex ? endTokenFirst.getIndex() : endTokenFirst.getLine();
         int startSecond = usesIndex ? startTokenSecond.getIndex() : startTokenSecond.getLine();
         int endSecond = usesIndex ? endTokenSecond.getIndex() : endTokenSecond.getLine();
-        int tokens = match.getLength();
+        int tokens = match.length();
 
         return new Match(startTokenFirst.getFile(), startTokenSecond.getFile(), startFirst, endFirst, startSecond, endSecond, tokens);
     }

+ 1 - 1
jplag/src/main/java/de/jplag/reporting/reportobject/mapper/MetricMapper.java

@@ -40,7 +40,7 @@ public class MetricMapper {
         return comparisons.stream().sorted(Comparator.comparing(similarityExtractor).reversed())
                 .map(comparison -> new TopComparison(comparison.getFirstSubmission().getName(), comparison.getSecondSubmission().getName(),
                         similarityExtractor.apply(comparison)))
-                .collect(Collectors.toList());
+                .toList();
     }
 
     private static List<TopComparison> getTopComparisons(List<JPlagComparison> comparisons) {