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

Fixed formatting and made minor changes to comments in the strategy package.

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

+ 33 - 39
jplag/src/main/java/jplag/strategy/AbstractComparisonStrategy.java

@@ -11,55 +11,49 @@ import jplag.options.SimilarityMetric;
 
 public abstract class AbstractComparisonStrategy implements ComparisonStrategy {
 
-  /**
-   * Hashtable that maps the name of a submissions to its matches with the provided base code.
-   *
-   * TODO: I think it's better to make each submission store its own matches with the base code.
-   */
-  protected Hashtable<String, JPlagBaseCodeComparison> baseCodeMatches = new Hashtable<>(30);
+    // TODO PB: I think it's better to make each submission store its own matches with the base code.
+    // Hashtable that maps the name of a submissions to its matches with the provided base code.
+    protected Hashtable<String, JPlagBaseCodeComparison> baseCodeMatches = new Hashtable<>(30);
 
-  protected GSTiling gSTiling;
+    protected GSTiling gSTiling;
 
-  protected JPlagOptions options;
+    protected JPlagOptions options;
 
-  public AbstractComparisonStrategy(JPlagOptions options, GSTiling gSTiling) {
-    this.gSTiling = gSTiling;
-    this.options = options;
-  }
+    public AbstractComparisonStrategy(JPlagOptions options, GSTiling gSTiling) {
+        this.gSTiling = gSTiling;
+        this.options = options;
+    }
 
-  protected void compareSubmissionsToBaseCode(
-      Vector<Submission> submissions,
-      Submission baseCodeSubmission
-  ) {
-    int numberOfSubmissions = submissions.size();
+    protected void compareSubmissionsToBaseCode(Vector<Submission> submissions, Submission baseCodeSubmission) {
+        int numberOfSubmissions = submissions.size();
 
-    JPlagBaseCodeComparison bcMatch;
-    Submission currentSubmission;
+        JPlagBaseCodeComparison bcMatch;
+        Submission currentSubmission;
 
-    for (int i = 0; i < (numberOfSubmissions); i++) {
-      currentSubmission = submissions.elementAt(i);
+        for (int i = 0; i < (numberOfSubmissions); i++) {
+            currentSubmission = submissions.elementAt(i);
 
-      bcMatch = this.gSTiling.compareWithBaseCode(currentSubmission, baseCodeSubmission);
-      baseCodeMatches.put(currentSubmission.name, bcMatch);
+            bcMatch = this.gSTiling.compareWithBaseCode(currentSubmission, baseCodeSubmission);
+            baseCodeMatches.put(currentSubmission.name, bcMatch);
 
-      this.gSTiling.resetBaseSubmission(baseCodeSubmission);
+            this.gSTiling.resetBaseSubmission(baseCodeSubmission);
+        }
     }
-  }
-
-  protected boolean isAboveSimilarityThreshold(JPlagComparison comparison) {
-    float similarityThreshold = this.options.getSimilarityThreshold();
-    SimilarityMetric similarityMetric = this.options.getSimilarityMetric();
 
-    switch (similarityMetric) {
-      case AVG:
-        return comparison.percent() >= similarityThreshold;
-      case MAX:
-        return comparison.percentMaxAB() >= similarityThreshold;
-      case MIN:
-        return comparison.percentMinAB() >= similarityThreshold;
-      default:
-        return true;
+    protected boolean isAboveSimilarityThreshold(JPlagComparison comparison) {
+        float similarityThreshold = this.options.getSimilarityThreshold();
+        SimilarityMetric similarityMetric = this.options.getSimilarityMetric();
+
+        switch (similarityMetric) {
+        case AVG:
+            return comparison.percent() >= similarityThreshold;
+        case MAX:
+            return comparison.percentMaxAB() >= similarityThreshold;
+        case MIN:
+            return comparison.percentMinAB() >= similarityThreshold;
+        default:
+            return true;
+        }
     }
-  }
 
 }

+ 1 - 1
jplag/src/main/java/jplag/strategy/ComparisonMode.java

@@ -8,4 +8,4 @@ public enum ComparisonMode {
   REVISION,
   SPECIAL,
   EXTERNAL
-}
+}

+ 10 - 2
jplag/src/main/java/jplag/strategy/ComparisonStrategy.java

@@ -4,8 +4,16 @@ import java.util.Vector;
 import jplag.JPlagResult;
 import jplag.Submission;
 
+/**
+ * Strategy for comparing a set of submissions.
+ */
 public interface ComparisonStrategy {
 
-  JPlagResult compareSubmissions(Vector<Submission> submissions, Submission baseCodeSubmission);
-
+    /**
+     * Compares submissions from a set of submissions while considering a given base code.
+     * @param submissions is the set of submissions.
+     * @param baseCodeSubmission is the base code on which each submission is based on.
+     * @return the comparison results.
+     */
+    JPlagResult compareSubmissions(Vector<Submission> submissions, Submission baseCodeSubmission);
 }

+ 290 - 306
jplag/src/main/java/jplag/strategy/ExternalComparisonStrategy.java

@@ -11,351 +11,335 @@ import jplag.Structure;
 import jplag.Submission;
 import jplag.clustering.Cluster;
 
+@SuppressWarnings("unused") // TODO TS: External comparison strategy currently not supported
 public class ExternalComparisonStrategy extends AbstractComparisonStrategy {
 
-  private final Runtime runtime = Runtime.getRuntime();
-
-  public ExternalComparisonStrategy(JPlagOptions options, GSTiling gSTiling) {
-    super(options, gSTiling);
-  }
-
-  /**
-   * This is the special external comparison routine
-   */
-  @Override
-  public JPlagResult compareSubmissions(
-      Vector<Submission> submissions,
-      Submission baseCodeSubmission
-  ) {
-    try {
-      int size = submissions.size();
-
-      // Result vector
-      SortedVector<JPlagComparison> avgmatches = new SortedVector<>(
-          new JPlagComparison.AvgComparator());
-      SortedVector<JPlagComparison> maxmatches = new SortedVector<>(
-          new JPlagComparison.MaxComparator());
-      int[] dist = new int[10];
-
-      // print("Comparing: " + size + " submissions\n", null);
-
-      long totalComparisons = (size * (size - 1)) / 2, count = 0, comparisons = 0;
-      int index;
-      JPlagComparison match;
-      Submission s1, s2;
-      long remain;
-      String totalTimeStr, remainTime;
-
-      // print("Checking memory size...\n", null);
-
-      // First try to load as many submissions as possible
-      index = fillMemory(submissions, 0, size);
-
-      long startTime;
-      long totalTime = 0;
-      int startA = 0;
-      int endA = index / 2;
-      int startB = endA + 1;
-      int endB = index;
-      int i, j;
-      // long progStart;
-
-      do {
-        // compare A to A
-        startTime = System.currentTimeMillis();
-        // print("Comparing block A (" + startA + "-" + endA + ") to block A\n", null);
-
-        for (i = startA; i <= endA; i++) {
-          s1 = submissions.elementAt(i);
-
-          if (s1.tokenList == null) {
-            count += (endA - i);
-            continue;
-          }
-
-          for (j = (i + 1); j <= endA; j++) {
-            s2 = submissions.elementAt(j);
-
-            if (s2.tokenList == null) {
-              count++;
-              continue;
-            }
+    private final Runtime runtime = Runtime.getRuntime();
 
-            match = this.gSTiling.compare(s1, s2);
-            registerMatch(match, avgmatches, maxmatches, null, i, j);
-            comparisons++;
-            count++;
-          }
-        }
+    public ExternalComparisonStrategy(JPlagOptions options, GSTiling gSTiling) {
+        super(options, gSTiling);
+    }
 
-        // print("\n", null);
-        totalTime += System.currentTimeMillis() - startTime;
+    /**
+     * This is the special external comparison routine
+     */
+    @Override
+    public JPlagResult compareSubmissions(Vector<Submission> submissions, Submission baseCodeSubmission) {
+        try {
+            int size = submissions.size();
+
+            // Result vector
+            SortedVector<JPlagComparison> avgmatches = new SortedVector<>(new JPlagComparison.AvgComparator());
+            SortedVector<JPlagComparison> maxmatches = new SortedVector<>(new JPlagComparison.MaxComparator());
+            int[] dist = new int[10];
+
+            // print("Comparing: " + size + " submissions\n", null);
+
+            long totalComparisons = (size * (size - 1)) / 2, count = 0, comparisons = 0;
+            int index;
+            JPlagComparison match;
+            Submission first, second;
+            long remain;
+            String totalTimeStr, remainTime;
+
+            // print("Checking memory size...\n", null);
+
+            // First try to load as many submissions as possible
+            index = fillMemory(submissions, 0, size);
+
+            long startTime;
+            long totalTime = 0;
+            int startA = 0;
+            int endA = index / 2;
+            int startB = endA + 1;
+            int endB = index;
+            int i, j;
+            // long progStart;
+
+            do {
+                // compare A to A
+                startTime = System.currentTimeMillis();
+                // print("Comparing block A (" + startA + "-" + endA + ") to block A\n", null);
+
+                for (i = startA; i <= endA; i++) {
+                    first = submissions.elementAt(i);
+
+                    if (first.tokenList == null) {
+                        count += (endA - i);
+                        continue;
+                    }
+
+                    for (j = (i + 1); j <= endA; j++) {
+                        second = submissions.elementAt(j);
+
+                        if (second.tokenList == null) {
+                            count++;
+                            continue;
+                        }
+
+                        match = this.gSTiling.compare(first, second);
+                        registerMatch(match, avgmatches, maxmatches, null, i, j);
+                        comparisons++;
+                        count++;
+                    }
+                }
+
+                // print("\n", null);
+                totalTime += System.currentTimeMillis() - startTime;
+
+                // Are we finished?
+                if (startA == startB) {
+                    break;
+                }
+
+                do {
+                    totalTimeStr = "" + ((totalTime / 3600000 > 0) ? (totalTime / 3600000) + " h " : "")
+                            + ((totalTime / 60000 > 0) ? ((totalTime / 60000) % 60) + " min " : "") + (totalTime / 1000 % 60) + " sec";
+
+                    if (comparisons != 0) {
+                        remain = totalTime * (totalComparisons - count) / comparisons;
+                    } else {
+                        remain = 0;
+                    }
+
+                    remainTime = "" + ((remain / 3600000 > 0) ? (remain / 3600000) + " h " : "")
+                            + ((remain / 60000 > 0) ? ((remain / 60000) % 60) + " min " : "") + (remain / 1000 % 60) + " sec";
+
+                    // print("Progress: " + (100 * count) / totalComparisons + "%\nTime used for comparisons: "
+                    // + totalTimeStr
+                    // + "\nRemaining time (estimate): " + remainTime + "\n", null);
+
+                    // compare A to B
+                    startTime = System.currentTimeMillis();
+                    // print("Comparing block A (" + startA + "-" + endA + ") to block B (" + startB + "-" + endB
+                    // + ")\n", null);
+
+                    for (i = startB; i <= endB; i++) {
+                        first = submissions.elementAt(i);
+
+                        if (first.tokenList == null) {
+                            count += (endA - startA + 1);
+                            continue;
+                        }
+
+                        for (j = startA; j <= endA; j++) {
+                            second = submissions.elementAt(j);
+
+                            if (second.tokenList == null) {
+                                count++;
+                                continue;
+                            }
+
+                            match = this.gSTiling.compare(first, second);
+                            registerMatch(match, avgmatches, maxmatches, null, i, j);
+                            comparisons++;
+                            count++;
+                        }
+
+                        first.tokenList = null; // remove B
+                    }
+
+                    // print("\n", null);
+                    totalTime += System.currentTimeMillis() - startTime;
+
+                    if (endB == size - 1) {
+                        totalTimeStr = "" + ((totalTime / 3600000 > 0) ? (totalTime / 3600000) + " h " : "")
+                                + ((totalTime / 60000 > 0) ? ((totalTime / 60000) % 60) + " min " : "") + (totalTime / 1000 % 60) + " sec";
+                        remain = totalTime * (totalComparisons - count) / comparisons;
+                        remainTime = "" + ((remain / 3600000 > 0) ? (remain / 3600000) + " h " : "")
+                                + ((remain / 60000 > 0) ? ((remain / 60000) % 60) + " min " : "") + (remain / 1000 % 60) + " sec";
+
+                        // print("Progress: " + (100 * count) / totalComparisons + "%\nTime used for comparisons: "
+                        // + totalTimeStr
+                        // + "\nRemaining time (estimate): " + remainTime + "\n", null);
+                        break;
+                    }
+
+                    runtime.runFinalization();
+                    runtime.gc();
+                    Thread.yield();
+
+                    // Try to find the next B
+                    // print("Finding next B\n", null);
+
+                    index = fillMemory(submissions, endB + 1, size);
+
+                    startB = endB + 1;
+                    endB = index;
+
+                } while (true);
+
+                // Remove A
+                for (i = startA; i <= endA; i++) {
+                    submissions.elementAt(i).tokenList = null;
+                }
+
+                runtime.runFinalization();
+                runtime.gc();
+                Thread.yield();
+
+                // print("Find next A.\n", null);
+
+                // First try to load as many submissions as possible
 
-        // Are we finished?
-        if (startA == startB) {
-          break;
-        }
+                index = fillMemory(submissions, endA + 1, size);
 
-        do {
-          totalTimeStr = "" + ((totalTime / 3600000 > 0) ? (totalTime / 3600000) + " h " : "")
-              + ((totalTime / 60000 > 0) ? ((totalTime / 60000) % 60) + " min " : "") + (
-              totalTime / 1000 % 60) + " sec";
-
-          if (comparisons != 0) {
-            remain = totalTime * (totalComparisons - count) / comparisons;
-          } else {
-            remain = 0;
-          }
-
-          remainTime = "" + ((remain / 3600000 > 0) ? (remain / 3600000) + " h " : "")
-              + ((remain / 60000 > 0) ? ((remain / 60000) % 60) + " min " : "") + (remain / 1000
-              % 60)
-              + " sec";
-
-//          print("Progress: " + (100 * count) / totalComparisons + "%\nTime used for comparisons: "
-//              + totalTimeStr
-//              + "\nRemaining time (estimate): " + remainTime + "\n", null);
-
-          // compare A to B
-          startTime = System.currentTimeMillis();
-//          print("Comparing block A (" + startA + "-" + endA + ") to block B (" + startB + "-" + endB
-//              + ")\n", null);
-
-          for (i = startB; i <= endB; i++) {
-            s1 = submissions.elementAt(i);
-
-            if (s1.tokenList == null) {
-              count += (endA - startA + 1);
-              continue;
-            }
+                if (index != size - 1) {
+                    startA = endA + 1;
+                    endA = startA + (index - startA + 1) / 2;
+                    startB = endA + 1;
+                    endB = index;
+                } else {
+                    startA = startB; // last block
+                    endA = endB = index;
+                }
+            } while (true);
 
-            for (j = startA; j <= endA; j++) {
-              s2 = submissions.elementAt(j);
+            totalTime += System.currentTimeMillis() - startTime;
+            totalTimeStr = "" + ((totalTime / 3600000 > 0) ? (totalTime / 3600000) + " h " : "")
+                    + ((totalTime / 60000 > 0) ? ((totalTime / 60000) % 60000) + " min " : "") + (totalTime / 1000 % 60) + " sec";
 
-              if (s2.tokenList == null) {
-                count++;
-                continue;
-              }
+            // print("Total comparison time: " + totalTimeStr + "\nComparisons: " + count + "/" + comparisons
+            // + "/" + totalComparisons + "\n",
+            // null);
 
-              match = this.gSTiling.compare(s1, s2);
-              registerMatch(match, avgmatches, maxmatches, null, i, j);
-              comparisons++;
-              count++;
+            // free remaining memory
+            for (i = startA; i <= endA; i++) {
+                submissions.elementAt(i).tokenList = null;
             }
 
-            s1.tokenList = null; // remove B
-          }
+            runtime.runFinalization();
+            runtime.gc();
+            Thread.yield();
 
-          // print("\n", null);
-          totalTime += System.currentTimeMillis() - startTime;
+            Cluster cluster = null;
 
-          if (endB == size - 1) {
-            totalTimeStr = "" + ((totalTime / 3600000 > 0) ? (totalTime / 3600000) + " h " : "")
-                + ((totalTime / 60000 > 0) ? ((totalTime / 60000) % 60) + " min " : "") + (
-                totalTime / 1000 % 60) + " sec";
-            remain = totalTime * (totalComparisons - count) / comparisons;
-            remainTime = "" + ((remain / 3600000 > 0) ? (remain / 3600000) + " h " : "")
-                + ((remain / 60000 > 0) ? ((remain / 60000) % 60) + " min " : "") + (remain / 1000
-                % 60) + " sec";
-
-//            print("Progress: " + (100 * count) / totalComparisons + "%\nTime used for comparisons: "
-//                + totalTimeStr
-//                + "\nRemaining time (estimate): " + remainTime + "\n", null);
-            break;
-          }
-
-          runtime.runFinalization();
-          runtime.gc();
-          Thread.yield();
+            // TODO TS: Cluster currently not supported
+            // if (options.getClusterType() == ClusterType.NONE) {
+            // cluster = this.clusters.calculateClustering(submissions);
+            // }
 
-          // Try to find the next B
-          // print("Finding next B\n", null);
+            // TODO TS: External comparison strategy currently not supported
+            // Deprecated:
+            // writeResults(dist, avgmatches, maxmatches, null, cluster);
 
-          index = fillMemory(submissions, endB + 1, size);
-
-          startB = endB + 1;
-          endB = index;
+            // TODO TS: External comparison strategy currently not supported
+            return new JPlagResult();
+        } catch (OutOfMemoryError e) {
+            e.printStackTrace();
+            return new JPlagResult();
+        }
+    }
 
-        } while (true);
+    private int fillMemory(Vector<Submission> submissions, int from, int size) {
+        Submission sub = null;
+        int index = from;
 
-        // Remove A
-        for (i = startA; i <= endA; i++) {
-          submissions.elementAt(i).tokenList = null;
+        runtime.runFinalization();
+        runtime.gc();
+        Thread.yield();
+        long freeBefore = runtime.freeMemory();
+        try {
+            for (; index < size; index++) {
+                sub = submissions.elementAt(index);
+                sub.tokenList = new Structure();
+                if (!sub.tokenList.load(new File("temp", sub.submissionFile.getName() + sub.name))) {
+                    sub.tokenList = null;
+                }
+            }
+        } catch (java.lang.OutOfMemoryError e) {
+            sub.tokenList = null;
+            // print("Memory overflow after loading " + (index - from + 1) + " submissions.\n", null);
+        }
+        if (index >= size) {
+            index = size - 1;
         }
 
+        if (freeBefore / runtime.freeMemory() <= 2) {
+            return index;
+        }
+        for (int i = (index - from) / 2; i > 0; i--) {
+            submissions.elementAt(index--).tokenList = null;
+        }
         runtime.runFinalization();
         runtime.gc();
         Thread.yield();
 
-        // print("Find next A.\n", null);
-
-        // First try to load as many submissions as possible
-
-        index = fillMemory(submissions, endA + 1, size);
-
-        if (index != size - 1) {
-          startA = endA + 1;
-          endA = startA + (index - startA + 1) / 2;
-          startB = endA + 1;
-          endB = index;
-        } else {
-          startA = startB; // last block
-          endA = endB = index;
+        // make sure we freed half of the "available" memory.
+        long free;
+        while (freeBefore / (free = runtime.freeMemory()) > 2) {
+            submissions.elementAt(index--).tokenList = null;
+            runtime.runFinalization();
+            runtime.gc();
+            Thread.yield();
         }
-      } while (true);
-
-      totalTime += System.currentTimeMillis() - startTime;
-      totalTimeStr = "" + ((totalTime / 3600000 > 0) ? (totalTime / 3600000) + " h " : "")
-          + ((totalTime / 60000 > 0) ? ((totalTime / 60000) % 60000) + " min " : "") + (
-          totalTime / 1000 % 60) + " sec";
 
-//      print("Total comparison time: " + totalTimeStr + "\nComparisons: " + count + "/" + comparisons
-//              + "/" + totalComparisons + "\n",
-//          null);
+        // print(free / 1024 / 1024 + "MByte freed. Current index: " + index + "\n", null);
 
-      // free remaining memory
-      for (i = startA; i <= endA; i++) {
-        submissions.elementAt(i).tokenList = null;
-      }
-
-      runtime.runFinalization();
-      runtime.gc();
-      Thread.yield();
-
-      Cluster cluster = null;
+        return index;
+    }
 
-      // TODO
-//      if (options.getClusterType() == ClusterType.NONE) {
-//        cluster = this.clusters.calculateClustering(submissions);
-//      }
+    private void registerMatch(JPlagComparison match, SortedVector<JPlagComparison> avgMatches, SortedVector<JPlagComparison> maxMatches,
+            SortedVector<JPlagComparison> minMatches, int a, int b) {
+        float avgPercent = match.percent();
+        float maxPercent = match.percentMaxAB();
+        float minPercent = match.percentMinAB();
 
-      // TODO: Replace writeResults(...)
-      // Deprecated:
-      // writeResults(dist, avgmatches, maxmatches, null, cluster);
+        if (!options.isStorePercent()) {
+            if ((avgMatches.size() < options.getStoreMatches() || avgPercent > avgMatches.lastElement().percent()) && avgPercent > 0) {
+                avgMatches.insert(match);
 
-      return new JPlagResult();
-    } catch (OutOfMemoryError e) {
-      e.printStackTrace();
-      return new JPlagResult();
-    }
-  }
-
-  private int fillMemory(Vector<Submission> submissions, int from, int size) {
-    Submission sub = null;
-    int index = from;
-
-    runtime.runFinalization();
-    runtime.gc();
-    Thread.yield();
-    long freeBefore = runtime.freeMemory();
-    try {
-      for (; index < size; index++) {
-        sub = submissions.elementAt(index);
-        sub.tokenList = new Structure();
-        if (!sub.tokenList.load(new File("temp", sub.submissionFile.getName() + sub.name))) {
-          sub.tokenList = null;
-        }
-      }
-    } catch (java.lang.OutOfMemoryError e) {
-      sub.tokenList = null;
-      // print("Memory overflow after loading " + (index - from + 1) + " submissions.\n", null);
-    }
-    if (index >= size) {
-      index = size - 1;
-    }
+                if (avgMatches.size() > options.getStoreMatches()) {
+                    avgMatches.removeElementAt(options.getStoreMatches());
+                }
+            }
 
-    if (freeBefore / runtime.freeMemory() <= 2) {
-      return index;
-    }
-    for (int i = (index - from) / 2; i > 0; i--) {
-      submissions.elementAt(index--).tokenList = null;
-    }
-    runtime.runFinalization();
-    runtime.gc();
-    Thread.yield();
-
-    // make sure we freed half of the "available" memory.
-    long free;
-    while (freeBefore / (free = runtime.freeMemory()) > 2) {
-      submissions.elementAt(index--).tokenList = null;
-      runtime.runFinalization();
-      runtime.gc();
-      Thread.yield();
-    }
+            if (maxMatches != null && (maxMatches.size() < options.getStoreMatches() || maxPercent > maxMatches.lastElement().percent())
+                    && maxPercent > 0) {
+                maxMatches.insert(match);
 
-    // print(free / 1024 / 1024 + "MByte freed. Current index: " + index + "\n", null);
-
-    return index;
-  }
-
-  private void registerMatch(
-      JPlagComparison match,
-      SortedVector<JPlagComparison> avgMatches,
-      SortedVector<JPlagComparison> maxMatches,
-      SortedVector<JPlagComparison> minMatches,
-      int a,
-      int b
-  ) {
-    float avgPercent = match.percent();
-    float maxPercent = match.percentMaxAB();
-    float minPercent = match.percentMinAB();
-
-    if (!options.isStorePercent()) {
-      if ((avgMatches.size() < options.getStoreMatches() || avgPercent > avgMatches.lastElement()
-          .percent()) && avgPercent > 0) {
-        avgMatches.insert(match);
-
-        if (avgMatches.size() > options.getStoreMatches()) {
-          avgMatches.removeElementAt(options.getStoreMatches());
-        }
-      }
+                if (maxMatches.size() > options.getStoreMatches()) {
+                    maxMatches.removeElementAt(options.getStoreMatches());
+                }
+            }
 
-      if (maxMatches != null && (maxMatches.size() < options.getStoreMatches()
-          || maxPercent > maxMatches.lastElement().percent()) && maxPercent > 0) {
-        maxMatches.insert(match);
+            if (minMatches != null && (minMatches.size() < options.getStoreMatches() || minPercent > minMatches.lastElement().percent())
+                    && minPercent > 0) {
+                minMatches.insert(match);
 
-        if (maxMatches.size() > options.getStoreMatches()) {
-          maxMatches.removeElementAt(options.getStoreMatches());
-        }
-      }
+                if (minMatches.size() > options.getStoreMatches()) {
+                    minMatches.removeElementAt(options.getStoreMatches());
+                }
+            }
+        } else { // store_percent
+            if (avgPercent > options.getStoreMatches()) {
+                avgMatches.insert(match);
 
-      if (minMatches != null && (minMatches.size() < options.getStoreMatches()
-          || minPercent > minMatches.lastElement().percent()) && minPercent > 0) {
-        minMatches.insert(match);
+                if (avgMatches.size() > JPlagOptions.MAX_RESULT_PAIRS) {
+                    avgMatches.removeElementAt(JPlagOptions.MAX_RESULT_PAIRS);
+                }
+            }
 
-        if (minMatches.size() > options.getStoreMatches()) {
-          minMatches.removeElementAt(options.getStoreMatches());
-        }
-      }
-    } else { // store_percent
-      if (avgPercent > options.getStoreMatches()) {
-        avgMatches.insert(match);
+            if (maxMatches != null && maxPercent > options.getStoreMatches()) {
+                maxMatches.insert(match);
 
-        if (avgMatches.size() > JPlagOptions.MAX_RESULT_PAIRS) {
-          avgMatches.removeElementAt(JPlagOptions.MAX_RESULT_PAIRS);
-        }
-      }
+                if (maxMatches.size() > JPlagOptions.MAX_RESULT_PAIRS) {
+                    maxMatches.removeElementAt(JPlagOptions.MAX_RESULT_PAIRS);
+                }
+            }
 
-      if (maxMatches != null && maxPercent > options.getStoreMatches()) {
-        maxMatches.insert(match);
+            if (minMatches != null && minPercent > options.getStoreMatches()) {
+                minMatches.insert(match);
 
-        if (maxMatches.size() > JPlagOptions.MAX_RESULT_PAIRS) {
-          maxMatches.removeElementAt(JPlagOptions.MAX_RESULT_PAIRS);
+                if (minMatches.size() > JPlagOptions.MAX_RESULT_PAIRS) {
+                    minMatches.removeElementAt(JPlagOptions.MAX_RESULT_PAIRS);
+                }
+            }
         }
-      }
-
-      if (minMatches != null && minPercent > options.getStoreMatches()) {
-        minMatches.insert(match);
 
-        if (minMatches.size() > JPlagOptions.MAX_RESULT_PAIRS) {
-          minMatches.removeElementAt(JPlagOptions.MAX_RESULT_PAIRS);
-        }
-      }
+        // TODO TS: Cluster currently not supported
+        // if (options.getClusterType() != ClusterType.NONE) {
+        // similarity.setSimilarity(a, b, avgPercent);
+        // }
     }
-
-    // TODO
-//    if (options.getClusterType() != ClusterType.NONE) {
-//      similarity.setSimilarity(a, b, avgPercent);
-//    }
-  }
 }

+ 42 - 45
jplag/src/main/java/jplag/strategy/NormalComparisonStrategy.java

@@ -11,65 +11,62 @@ import jplag.Submission;
 
 public class NormalComparisonStrategy extends AbstractComparisonStrategy {
 
-  public NormalComparisonStrategy(JPlagOptions options, GSTiling gSTiling) {
-    super(options, gSTiling);
-  }
-
-  @Override
-  public JPlagResult compareSubmissions(
-      Vector<Submission> submissions,
-      Submission baseCodeSubmission
-  ) {
-    if (baseCodeSubmission != null) {
-      compareSubmissionsToBaseCode(submissions, baseCodeSubmission);
+    public NormalComparisonStrategy(JPlagOptions options, GSTiling gSTiling) {
+        super(options, gSTiling);
     }
 
-    long timeBeforeStartInMillis = System.currentTimeMillis();
-    int i, j, numberOfSubmissions = submissions.size();
-    Submission s1, s2;
-    JPlagComparison comparison;
+    @Override
+    public JPlagResult compareSubmissions(Vector<Submission> submissions, Submission baseCodeSubmission) {
+        if (baseCodeSubmission != null) {
+            compareSubmissionsToBaseCode(submissions, baseCodeSubmission);
+        }
 
-    List<JPlagComparison> comparisons = new ArrayList<>();
+        long timeBeforeStartInMillis = System.currentTimeMillis();
+        int i, j, numberOfSubmissions = submissions.size();
+        Submission first, second;
+        JPlagComparison comparison;
 
-    for (i = 0; i < (numberOfSubmissions - 1); i++) {
-      s1 = submissions.elementAt(i);
+        List<JPlagComparison> comparisons = new ArrayList<>();
 
-      if (s1.tokenList == null) {
-        continue;
-      }
+        for (i = 0; i < (numberOfSubmissions - 1); i++) {
+            first = submissions.elementAt(i);
 
-      for (j = (i + 1); j < numberOfSubmissions; j++) {
-        s2 = submissions.elementAt(j);
+            if (first.tokenList == null) {
+                continue;
+            }
 
-        if (s2.tokenList == null) {
-          continue;
-        }
+            for (j = (i + 1); j < numberOfSubmissions; j++) {
+                second = submissions.elementAt(j);
 
-        comparison = this.gSTiling.compare(s1, s2);
+                if (second.tokenList == null) {
+                    continue;
+                }
 
-        System.out.println("Comparing " + s1.name + "-" + s2.name + ": " + comparison.percent());
+                comparison = this.gSTiling.compare(first, second);
 
-        if (baseCodeSubmission != null) {
-          comparison.bcMatchesA = baseCodeMatches.get(comparison.subA.name);
-          comparison.bcMatchesB = baseCodeMatches.get(comparison.subB.name);
-        }
+                System.out.println("Comparing " + first.name + "-" + second.name + ": " + comparison.percent());
+
+                if (baseCodeSubmission != null) {
+                    comparison.bcMatchesA = baseCodeMatches.get(comparison.subA.name);
+                    comparison.bcMatchesB = baseCodeMatches.get(comparison.subB.name);
+                }
 
-        if (isAboveSimilarityThreshold(comparison)) {
-          comparisons.add(comparison);
+                if (isAboveSimilarityThreshold(comparison)) {
+                    comparisons.add(comparison);
+                }
+            }
         }
-      }
-    }
 
-    long durationInMillis = System.currentTimeMillis() - timeBeforeStartInMillis;
+        long durationInMillis = System.currentTimeMillis() - timeBeforeStartInMillis;
 
-    // TODO:
-    // Cluster cluster = null;
-    //
-    // if (options.getClusterType() != ClusterType.NONE) {
-    //     cluster = this.clusters.calculateClustering(submissions);
-    // }
+        // TODO TS: Cluster currently not supported
+        // Cluster cluster = null;
+        //
+        // if (options.getClusterType() != ClusterType.NONE) {
+        // cluster = this.clusters.calculateClustering(submissions);
+        // }
 
-    return new JPlagResult(comparisons, durationInMillis, numberOfSubmissions, options);
-  }
+        return new JPlagResult(comparisons, durationInMillis, numberOfSubmissions, options);
+    }
 
 }

+ 47 - 51
jplag/src/main/java/jplag/strategy/RevisionComparisonStrategy.java

@@ -11,72 +11,68 @@ import jplag.Submission;
 
 public class RevisionComparisonStrategy extends AbstractComparisonStrategy {
 
-  public RevisionComparisonStrategy(JPlagOptions options, GSTiling gSTiling) {
-    super(options, gSTiling);
-  }
-
-  @Override
-  public JPlagResult compareSubmissions(
-      Vector<Submission> submissions,
-      Submission baseCodeSubmission
-  ) {
-    if (baseCodeSubmission != null) {
-      compareSubmissionsToBaseCode(submissions, baseCodeSubmission);
+    public RevisionComparisonStrategy(JPlagOptions options, GSTiling gSTiling) {
+        super(options, gSTiling);
     }
 
-    long timeBeforeStartInMillis = System.currentTimeMillis();
-    int numberOfSubmissions = submissions.size();
-    Submission s1, s2;
-    JPlagComparison comparison;
+    @Override
+    public JPlagResult compareSubmissions(Vector<Submission> submissions, Submission baseCodeSubmission) {
+        if (baseCodeSubmission != null) {
+            compareSubmissionsToBaseCode(submissions, baseCodeSubmission);
+        }
 
-    List<JPlagComparison> comparisons = new ArrayList<>();
+        long timeBeforeStartInMillis = System.currentTimeMillis();
+        int numberOfSubmissions = submissions.size();
+        Submission first, second;
+        JPlagComparison comparison;
 
-    s1loop:
-    for (int i = 0; i < numberOfSubmissions - 1; ) {
-      s1 = submissions.elementAt(i);
+        List<JPlagComparison> comparisons = new ArrayList<>();
 
-      if (s1.tokenList == null) {
-        continue;
-      }
+        s1loop: for (int i = 0; i < numberOfSubmissions - 1;) {
+            first = submissions.elementAt(i);
 
-      // Find next valid submission
-      int j = i;
+            if (first.tokenList == null) {
+                continue;
+            }
 
-      do {
-        j++;
+            // Find next valid submission
+            int j = i;
 
-        if (j >= numberOfSubmissions) {
-          break s1loop; // no more comparison pairs available
-        }
+            do {
+                j++;
 
-        s2 = submissions.elementAt(j);
-      } while (s2.tokenList == null);
+                if (j >= numberOfSubmissions) {
+                    break s1loop; // no more comparison pairs available
+                }
 
-      comparison = this.gSTiling.compare(s1, s2);
+                second = submissions.elementAt(j);
+            } while (second.tokenList == null);
 
-      System.out.println("Comparing " + s1.name + "-" + s2.name + ": " + comparison.percent());
+            comparison = this.gSTiling.compare(first, second);
 
-      if (baseCodeSubmission != null) {
-        comparison.bcMatchesA = baseCodeMatches.get(comparison.subA.name);
-        comparison.bcMatchesB = baseCodeMatches.get(comparison.subB.name);
-      }
+            System.out.println("Comparing " + first.name + "-" + second.name + ": " + comparison.percent());
 
-      if (isAboveSimilarityThreshold(comparison)) {
-        comparisons.add(comparison);
-      }
+            if (baseCodeSubmission != null) {
+                comparison.bcMatchesA = baseCodeMatches.get(comparison.subA.name);
+                comparison.bcMatchesB = baseCodeMatches.get(comparison.subB.name);
+            }
 
-      i = j;
-    }
+            if (isAboveSimilarityThreshold(comparison)) {
+                comparisons.add(comparison);
+            }
 
-    long durationInMillis = System.currentTimeMillis() - timeBeforeStartInMillis;
+            i = j;
+        }
+
+        long durationInMillis = System.currentTimeMillis() - timeBeforeStartInMillis;
 
-    // TODO:
-    // Cluster cluster = null;
-    //
-    // if (options.getClusterType() != ClusterType.NONE) {
-    //     cluster = this.clusters.calculateClustering(submissions);
-    // }
+        // TODO TS: Cluster currently not supported
+        // Cluster cluster = null;
+        //
+        // if (options.getClusterType() != ClusterType.NONE) {
+        // cluster = this.clusters.calculateClustering(submissions);
+        // }
 
-    return new JPlagResult(comparisons, durationInMillis, numberOfSubmissions, options);
-  }
+        return new JPlagResult(comparisons, durationInMillis, numberOfSubmissions, options);
+    }
 }

+ 73 - 78
jplag/src/main/java/jplag/strategy/SpecialComparisonStrategy.java

@@ -9,89 +9,84 @@ import jplag.JPlagResult;
 import jplag.SortedVector;
 import jplag.Submission;
 
+@SuppressWarnings("unused") // TODO TS: Special comparison strategy currently not supported
 public class SpecialComparisonStrategy extends AbstractComparisonStrategy {
 
-  public SpecialComparisonStrategy(JPlagOptions options, GSTiling gSTiling) {
-    super(options, gSTiling);
-  }
-
-  /*
-   * Now the special comparison
-   * TODO: Previously, this comparison created a `Report.java` (removed)
-   * TODO: Check whether this comparison is now any different than the others after the report has been removed
-   */
-  @Override
-  public JPlagResult compareSubmissions(
-      Vector<Submission> submissions,
-      Submission baseCodeSubmission
-  ) {
-    File root = new File(options.getRootDirName());
-
-    int size = submissions.size();
-    int matchIndex = 0;
-
-    // TODO
-//    print("Comparing: ", countValidSubmissions() + " submissions");
-//    print("\n(Writing results at the same time.)\n", null);
-
-    int totalcomps = size * size;
-    int i, j, anz = 0, count = 0;
-    JPlagComparison match;
-    Submission s1, s2;
-    long msec = System.currentTimeMillis();
-
-    for (i = 0; i < (size - 1); i++) {
-      // Result vector
-      SortedVector<JPlagComparison> matches = new SortedVector<>(
-          new JPlagComparison.AvgComparator());
-
-      s1 = submissions.elementAt(i);
-
-      if (s1.tokenList == null) {
-        count += (size - 1);
-        continue;
-      }
-
-      for (j = 0; j < size; j++) {
-        s2 = submissions.elementAt(j);
-
-        if ((i == j) || (s2.tokenList == null)) {
-          count++;
-          continue;
-        }
-
-        match = this.gSTiling.compare(s1, s2);
-        anz++;
-
-        float percent = match.percent();
+    public SpecialComparisonStrategy(JPlagOptions options, GSTiling gSTiling) {
+        super(options, gSTiling);
+    }
 
-        if ((matches.size() < options.getNumberOfSubmissionsToCompareTo() || matches.size() == 0 || match
-            .moreThan(matches.lastElement().percent()))
-            && match.moreThan(0)) {
-          matches.insert(match);
-          if (matches.size() > options.getNumberOfSubmissionsToCompareTo()) {
-            matches.removeElementAt(options.getNumberOfSubmissionsToCompareTo());
-          }
+    /*
+     * Now the special comparison TODO PB: Previously, this comparison created a `Report.java` (removed) 
+     * TODO PB: Check whether this comparison is now any different than the others after the report has been removed
+     */
+    @Override
+    public JPlagResult compareSubmissions(Vector<Submission> submissions, Submission baseCodeSubmission) {
+        File root = new File(options.getRootDirName());
+
+        int size = submissions.size();
+        int matchIndex = 0;
+
+        // TODO TS: Special comparison strategy currently not supported
+        // print("Comparing: ", countValidSubmissions() + " submissions");
+        // print("\n(Writing results at the same time.)\n", null);
+
+        int totalcomps = size * size;
+        int i, j, anz = 0, count = 0;
+        JPlagComparison match;
+        Submission first, second;
+        long msec = System.currentTimeMillis();
+
+        for (i = 0; i < (size - 1); i++) {
+            // Result vector
+            SortedVector<JPlagComparison> matches = new SortedVector<>(new JPlagComparison.AvgComparator());
+
+            first = submissions.elementAt(i);
+
+            if (first.tokenList == null) {
+                count += (size - 1);
+                continue;
+            }
+
+            for (j = 0; j < size; j++) {
+                second = submissions.elementAt(j);
+
+                if ((i == j) || (second.tokenList == null)) {
+                    count++;
+                    continue;
+                }
+
+                match = this.gSTiling.compare(first, second);
+                anz++;
+
+                float percent = match.percent();
+
+                if ((matches.size() < options.getNumberOfSubmissionsToCompareTo() || matches.size() == 0
+                        || match.moreThan(matches.lastElement().percent())) && match.moreThan(0)) {
+                    matches.insert(match);
+                    if (matches.size() > options.getNumberOfSubmissionsToCompareTo()) {
+                        matches.removeElementAt(options.getNumberOfSubmissionsToCompareTo());
+                    }
+                }
+
+                // TODO TS: Special comparison strategy currently not supported
+                // if (options.getClusterType() != ClusterType.NONE) {
+                // similarity.setSimilarity(i, j, percent);
+                // }
+
+                count++;
+            }
         }
 
-        // TODO
-//        if (options.getClusterType() != ClusterType.NONE) {
-//          similarity.setSimilarity(i, j, percent);
-//        }
+        long time = System.currentTimeMillis() - msec;
 
-        count++;
-      }
-    }
-
-    long time = System.currentTimeMillis() - msec;
+        // TODO TS: Special comparison strategy currently not supported
+        // print("\n", "Total time: " + ((time / 3600000 > 0) ? (time / 3600000) + " h " : "")
+        // + ((time / 60000 > 0) ? ((time / 60000) % 60000) + " min " : "") + (time / 1000 % 60)
+        // + " sec\n" + "Time per comparison: "
+        // + (time / anz) + " msec\n");
 
-    // TODO
-//    print("\n", "Total time: " + ((time / 3600000 > 0) ? (time / 3600000) + " h " : "")
-//        + ((time / 60000 > 0) ? ((time / 60000) % 60000) + " min " : "") + (time / 1000 % 60)
-//        + " sec\n" + "Time per comparison: "
-//        + (time / anz) + " msec\n");
-
-    // TODO
-    return new JPlagResult();
-  }
+        // TODO TS: Special comparison strategy currently not supported
+        return new JPlagResult();
+    }
 }