Просмотр исходного кода

Fix the order of the comparisons in the report by ensuring the order when creating a result object.

Timur Sağlam 5 лет назад
Родитель
Сommit
2958d48e4e

+ 5 - 2
jplag/src/main/java/jplag/JPlagResult.java

@@ -52,8 +52,8 @@ public class JPlagResult {
         this.durationInMillis = durationInMillis;
         this.numberOfSubmissions = numberOfSubmissions;
         this.options = options;
-
-        this.similarityDistribution = calculateSimilarityDistribution(comparisons);
+        similarityDistribution = calculateSimilarityDistribution(comparisons);
+        comparisons.sort((first, second) -> Float.compare(second.percent(), first.percent())); // Sort by percentage (descending).
     }
 
     /**
@@ -68,6 +68,9 @@ public class JPlagResult {
         return similarityDistribution;
     }
 
+    /**
+     * @return a list of comparisons sorted by percentage (descending).
+     */
     public List<JPlagComparison> getComparisons() {
         return comparisons;
     }

+ 4 - 5
jplag/src/main/java/jplag/reporting/Report.java

@@ -29,6 +29,7 @@ import jplag.Token;
  */
 public class Report {
 
+    private static final String CSV_FILE = "matches_avg.csv";
     private final Map<JPlagComparison, Integer> comparisonToIndex = new HashMap<>();
     private int currentComparisonIndex = 0;
     private final Messages msg;
@@ -401,11 +402,9 @@ public class Report {
         writeIndexBegin(htmlFile, msg.getString("Report.Search_Results"));
         writeDistribution(htmlFile);
 
-        String csvFile = "matches_avg.csv";
+        writeLinksToComparisons(htmlFile, "<H4>" + msg.getString("Report.MatchesAvg"), CSV_FILE);
 
-        writeLinksToComparisons(htmlFile, "<H4>" + msg.getString("Report.MatchesAvg"), csvFile);
-
-        writeMatchesCSV(csvFile);
+        writeMatchesCSV(CSV_FILE);
 
         writeIndexEnd(htmlFile);
 
@@ -542,7 +541,7 @@ public class Report {
     }
 
     private void writeLinksToComparisons(HTMLFile htmlFile, String headerStr, String csvFile) {
-        List<JPlagComparison> comparisons = result.getComparisons();
+        List<JPlagComparison> comparisons = result.getComparisons(); // should be already sorted!
 
         htmlFile.println(headerStr + " (<a href=\"help-sim-" + "en" // Country tag
                 + ".html\"><small><font color=\"#000088\">" + msg.getString("Report.WhatIsThis") + "</font></small></a>):</H4>");