ソースを参照

General clean-up and quality of life improvements (#181)

* Remove unused verbosity level DETAILS
* Move similarity metric calculation into the metric enum
* Encapsulate fields and fix visibility
* Use speaking member names
* Use constants to deduplicate common values
* Sort method by visibility and name
* Fix formatting and whitespace
* Add more comments
Timur Sağlam 5 年 前
親
コミット
5f9032f797

+ 1 - 1
jplag/src/main/java/jplag/CLI.java

@@ -6,13 +6,13 @@ import static jplag.CommandLineArgument.DEBUG;
 import static jplag.CommandLineArgument.EXCLUDE_FILE;
 import static jplag.CommandLineArgument.LANGUAGE;
 import static jplag.CommandLineArgument.MIN_TOKEN_MATCH;
+import static jplag.CommandLineArgument.RESULT_FOLDER;
 import static jplag.CommandLineArgument.ROOT_DIRECTORY;
 import static jplag.CommandLineArgument.SIMILARITY_THRESHOLD;
 import static jplag.CommandLineArgument.STORED_MATCHES;
 import static jplag.CommandLineArgument.SUBDIRECTORY;
 import static jplag.CommandLineArgument.SUFFIXES;
 import static jplag.CommandLineArgument.VERBOSITY;
-import static jplag.CommandLineArgument.RESULT_FOLDER;
 
 import java.io.File;
 import java.util.Random;

+ 1 - 1
jplag/src/main/java/jplag/CommandLineArgument.java

@@ -16,7 +16,7 @@ import net.sourceforge.argparse4j.inf.ArgumentParser;
 import net.sourceforge.argparse4j.inf.Namespace;
 
 /**
- * Command line arguments for the JPlag CLI. Each argument is defined through an enuemral.
+ * Command line arguments for the JPlag CLI. Each argument is defined through an enumeral.
  * @author Timur Saglam
  */
 public enum CommandLineArgument {

+ 6 - 6
jplag/src/main/java/jplag/GreedyStringTiling.java

@@ -5,8 +5,8 @@ import java.util.List;
 
 /**
  * This class implements the Greedy String Tiling algorithm as introduced by Michael Wise. However, it is very specific
- * to the classes {@link TokenList}, {@link Token}, and {@link Match}. While is class was
- * reworked, it still contains some quirks from the initial version.
+ * to the classes {@link TokenList}, {@link Token}, and {@link Match}. While is class was reworked, it still contains
+ * some quirks from the initial version.
  * @see <a href=
  * "https://www.researchgate.net/publication/262763983_String_Similarity_via_Greedy_String_Tiling_and_Running_Karp-Rabin_Matching">
  * String Similarity via Greedy String Tiling and Running Karp−Rabin Matching </a>
@@ -120,12 +120,12 @@ public class GreedyStringTiling implements TokenConstants {
     private final JPlagComparison compare(Submission firstSubmission, Submission secondSubmission, boolean withBaseCode) {
         // first and second refer to the list of tokens of the first and second submission:
         TokenList first = firstSubmission.tokenList;
-        TokenList second = secondSubmission.tokenList; 
+        TokenList second = secondSubmission.tokenList;
 
         // Initialize:
         JPlagComparison comparison = new JPlagComparison(firstSubmission, secondSubmission);
         int minimalTokenMatch = program.getOptions().getMinTokenMatch(); // minimal required token match
-        
+
         if (first.size() <= minimalTokenMatch || second.size() <= minimalTokenMatch) { // <= because of pivots!
             return comparison;
         }
@@ -181,8 +181,8 @@ public class GreedyStringTiling implements TokenConstants {
                 }
             }
             for (int i = matches.size() - 1; i >= 0; i--) {
-                int x = matches.get(i).getStartA();  // Beginning of/in sequence A
-                int y = matches.get(i).getStartB();  // Beginning of/in sequence B
+                int x = matches.get(i).getStartOfFirst();  // Beginning of/in sequence A
+                int y = matches.get(i).getStartOfSecond();  // Beginning of/in sequence B
                 comparison.addMatch(x, y, matches.get(i).getLength());
                 // in order that "Match" will be newly build (because reusing)
                 for (int j = matches.get(i).getLength(); j > 0; j--) {

+ 197 - 153
jplag/src/main/java/jplag/JPlagComparison.java

@@ -10,69 +10,124 @@ import java.util.List;
  */
 public class JPlagComparison implements Comparator<JPlagComparison> {
 
-    public Submission firstSubmission;
-    public Submission secondSubmission;
+    private static final int ROUNDING_FACTOR = 10;
 
-    public JPlagComparison baseCodeMatchesA = null;
-    public JPlagComparison baseCodeMatchesB = null;
+    private final Submission firstSubmission;
+    private final Submission secondSubmission;
 
-    public List<Match> matches = new ArrayList<>();
+    private JPlagComparison firstBaseCodeMatches = null;
+    private JPlagComparison secondBaseCodeMatches = null;
+
+    private final List<Match> matches;
 
     public JPlagComparison(Submission firstSubmission, Submission secondSubmission) {
         this.firstSubmission = firstSubmission;
         this.secondSubmission = secondSubmission;
+        matches = new ArrayList<>();
     }
 
-    public final void addMatch(int startA, int startB, int length) {
+    /**
+     * Add a match to the comparison (token indices and number of tokens), if it does not overlap with the existing matches.
+     * @see Match#Match(int, int, int)
+     */
+    public final void addMatch(int startOfFirst, int startOfSecond, int length) {
         for (Match match : matches) {
-            if (match.overlap(startA, startB, length)) {
+            if (match.overlap(startOfFirst, startOfSecond, length)) {
                 return;
             }
         }
-
-        matches.add(new Match(startA, startB, length));
+        matches.add(new Match(startOfFirst, startOfSecond, length));
     }
 
-    /*
-     * s==0 uses the start indexes of subA as key for the sorting algorithm. Otherwise the start indexes of subB are used.
+    /**
+     * The bigger a match (length) is relatively to the biggest match the redder is the color returned by this method.
      */
-    public final int[] sort_permutation(int s) {   // bubblesort!!!
-        int size = matches.size();
-        int[] perm = new int[size];
-        int i, j, tmp;
+    public String color(int length) {
+        int longestMatch = matches.stream().mapToInt(it -> it.getLength()).max().orElse(0);
+        int color = 255 * length / longestMatch;
+        String help = (color < 16 ? "0" : "") + Integer.toHexString(color);
+        return "#" + help + "0000";
+    }
 
-        // initialize permutation array
-        for (i = 0; i < size; i++) {
-            perm[i] = i;
+    @Override
+    public int compare(JPlagComparison comparison1, JPlagComparison comparison2) {
+        return Float.compare(comparison2.similarity(), comparison1.similarity()); // comparison2 first!
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if (!(other instanceof JPlagComparison)) {
+            return false;
+        }
+        return (compare(this, (JPlagComparison) other) == 0);
+    }
+
+    /**
+     * This method returns all the files which contributed to a match. Parameter: j == 0 1st submission, j != 0 2nd
+     * submission.
+     */
+    public final String[] files(int j) {
+        if (matches.size() == 0) {
+            return new String[] {};
         }
 
-        if (s == 0) {     // submission A
-            for (i = 1; i < size; i++) {
-                for (j = 0; j < (size - i); j++) {
-                    if (matches.get(perm[j]).getStartA() > matches.get(perm[j + 1]).getStartA()) {
-                        tmp = perm[j];
-                        perm[j] = perm[j + 1];
-                        perm[j + 1] = tmp;
-                    }
+        TokenList tokenList = (j == 0 ? firstSubmission : secondSubmission).tokenList;
+        int i, h, starti, starth, count = 1;
+
+        o1: for (i = 1; i < matches.size(); i++) {
+            starti = (j == 0 ? matches.get(i).getStartOfFirst() : matches.get(i).getStartOfSecond());
+            for (h = 0; h < i; h++) {
+                starth = (j == 0 ? matches.get(h).getStartOfFirst() : matches.get(h).getStartOfSecond());
+                if (tokenList.getToken(starti).file.equals(tokenList.getToken(starth).file)) {
+                    continue o1;
                 }
             }
-        } else {        // submission B
-            for (i = 1; i < size; i++) {
-                for (j = 0; j < (size - i); j++) {
-                    if (matches.get(perm[j]).getStartB() > matches.get(perm[j + 1]).getStartB()) {
-                        tmp = perm[j];
-                        perm[j] = perm[j + 1];
-                        perm[j + 1] = tmp;
-                    }
+            count++;
+        }
+
+        String[] res = new String[count];
+        res[0] = tokenList.getToken((j == 0 ? matches.get(0).getStartOfFirst() : matches.get(0).getStartOfSecond())).file;
+        count = 1;
+
+        o2: for (i = 1; i < matches.size(); i++) {
+            starti = (j == 0 ? matches.get(i).getStartOfFirst() : matches.get(i).getStartOfSecond());
+            for (h = 0; h < i; h++) {
+                starth = (j == 0 ? matches.get(h).getStartOfFirst() : matches.get(h).getStartOfSecond());
+                if (tokenList.getToken(starti).file.equals(tokenList.getToken(starth).file)) {
+                    continue o2;
                 }
             }
+            res[count++] = tokenList.getToken(starti).file;
         }
-        return perm;
+
+        /*
+         * sort by file name. (so that equally named files are displayed approximately side by side.)
+         */
+        Arrays.sort(res);
+
+        return res;
     }
 
-    /*
-     * A few methods to calculate some statistical data
+    /**
+     * @return the base code matches of the first submission.
      */
+    public JPlagComparison getFirstBaseCodeMatches() {
+        return firstBaseCodeMatches;
+    }
+
+    /**
+     * @return the first of the two submissions.
+     */
+    public Submission getFirstSubmission() {
+        return firstSubmission;
+    }
+
+    /**
+     * @return all matches between the two submissions.
+     */
+    public List<Match> getMatches() {
+        return matches;
+    }
 
     /**
      * Get the total number of matched tokens for this comparison.
@@ -87,174 +142,163 @@ public class JPlagComparison implements Comparator<JPlagComparison> {
         return numberOfMatchedTokens;
     }
 
-    private int biggestMatch() {
-        int maximalMatchLenght = 0;
+    /**
+     * @return the base code matches of the second submissions.
+     */
+    public JPlagComparison getSecondBaseCodeMatches() {
+        return secondBaseCodeMatches;
+    }
 
-        for (Match match : matches) {
-            if (match.getLength() > maximalMatchLenght) {
-                maximalMatchLenght = match.getLength();
-            }
-        }
+    /**
+     * @return the second of the two submissions.
+     */
+    public Submission getSecondSubmission() {
+        return secondSubmission;
+    }
 
-        return maximalMatchLenght;
+    /**
+     * @return Maximum similarity in percent of both submissions.
+     */
+    public final float maximalSimilarity() {
+        return Math.max(similarityOfFirst(), similarityOfSecond());
     }
 
-    public final float roundedPercent() {
-        float percent = percent();
-        return ((int) (percent * 10)) / (float) 10;
+    /**
+     * @return Minimum similarity in percent of both submissions.
+     */
+    public final float minimalSimilarity() {
+        return Math.min(similarityOfFirst(), similarityOfSecond());
     }
 
-    public final float percent() {
+    /**
+     * @return Similarity in percent (what percentage of tokens across both submissions are matched).
+     */
+    public final float similarity() {
         float sa, sb;
-        if (baseCodeMatchesB != null && baseCodeMatchesA != null) {
-            sa = firstSubmission.getNumberOfTokens() - firstSubmission.files.size() - baseCodeMatchesA.getNumberOfMatchedTokens();
-            sb = secondSubmission.getNumberOfTokens() - secondSubmission.files.size() - baseCodeMatchesB.getNumberOfMatchedTokens();
+        if (secondBaseCodeMatches != null && firstBaseCodeMatches != null) {
+            sa = firstSubmission.getNumberOfTokens() - firstSubmission.files.size() - firstBaseCodeMatches.getNumberOfMatchedTokens();
+            sb = secondSubmission.getNumberOfTokens() - secondSubmission.files.size() - secondBaseCodeMatches.getNumberOfMatchedTokens();
         } else {
             sa = firstSubmission.getNumberOfTokens() - firstSubmission.files.size();
             sb = secondSubmission.getNumberOfTokens() - secondSubmission.files.size();
         }
-        return (200 * (float) getNumberOfMatchedTokens()) / (sa + sb);
+        return (200 * getNumberOfMatchedTokens()) / (sa + sb);
     }
 
-    public final float percentA() {
+    /**
+     * @return Similarity in percent for the first submission (what percent of the first submission is similar to the
+     * second).
+     */
+    public final float similarityOfFirst() {
         int divisor;
-        if (baseCodeMatchesA != null) {
-            divisor = firstSubmission.getNumberOfTokens() - firstSubmission.files.size() - baseCodeMatchesA.getNumberOfMatchedTokens();
+        if (firstBaseCodeMatches != null) {
+            divisor = firstSubmission.getNumberOfTokens() - firstSubmission.files.size() - firstBaseCodeMatches.getNumberOfMatchedTokens();
         } else {
             divisor = firstSubmission.getNumberOfTokens() - firstSubmission.files.size();
         }
         return (divisor == 0 ? 0f : (getNumberOfMatchedTokens() * 100 / (float) divisor));
     }
 
-    public final float percentB() {
+    /**
+     * @return Similarity in percent for the second submission (what percent of the second submission is similar to the
+     * first).
+     */
+    public final float similarityOfSecond() {
         int divisor;
-        if (baseCodeMatchesB != null) {
-            divisor = secondSubmission.getNumberOfTokens() - secondSubmission.files.size() - baseCodeMatchesB.getNumberOfMatchedTokens();
+        if (secondBaseCodeMatches != null) {
+            divisor = secondSubmission.getNumberOfTokens() - secondSubmission.files.size() - secondBaseCodeMatches.getNumberOfMatchedTokens();
         } else {
             divisor = secondSubmission.getNumberOfTokens() - secondSubmission.files.size();
         }
         return (divisor == 0 ? 0f : (getNumberOfMatchedTokens() * 100 / (float) divisor));
     }
 
-    public final float percentMaxAB() {
-        float a = percentA();
-        float b = percentB();
-        if (a > b) {
-            return a;
-        } else {
-            return b;
-        }
-    }
-
-    public final float percentMinAB() {
-        float a = percentA();
-        float b = percentB();
-        if (a < b) {
-            return a;
-        } else {
-            return b;
-        }
+    /**
+     * @return Similarity in percent rounded down to the nearest tenth.
+     */
+    public final float roundedSimilarity() {
+        return ((int) (similarity() * ROUNDING_FACTOR)) / (float) ROUNDING_FACTOR;
     }
 
-    private final float percentBasecodeA() {
-        float sa = firstSubmission.getNumberOfTokens() - firstSubmission.files.size();
-        return baseCodeMatchesA.getNumberOfMatchedTokens() * 100 / sa;
+    /**
+     * @return Similarity of the first submission to the basecode in percent rounded down to the nearest tenth.
+     */
+    public final float basecodeSimilarityOfFirst() {
+        return ((int) (firstBasecodeSimilarity() * ROUNDING_FACTOR)) / (float) ROUNDING_FACTOR;
     }
 
-    private final float percentBasecodeB() {
-        float sb = secondSubmission.getNumberOfTokens() - secondSubmission.files.size();
-        return baseCodeMatchesB.getNumberOfMatchedTokens() * 100 / sb;
+    /**
+     * @return Similarity of the second submission to the basecode in percent rounded down to the nearest tenth.
+     */
+    public final float basecodeSimilarityOfSecond() {
+        return ((int) (secondBasecodeSimilarity() * ROUNDING_FACTOR)) / (float) ROUNDING_FACTOR;
     }
 
-    public final float roundedPercentBasecodeA() {
-        float percent = percentBasecodeA();
-        return ((int) (percent * 10)) / (float) 10;
+    /**
+     * Sets the base code matches of the second submissions.
+     */
+    public void setFirstBaseCodeMatches(JPlagComparison firstBaseCodeMatches) {
+        this.firstBaseCodeMatches = firstBaseCodeMatches;
     }
 
-    public final float roundedPercentBasecodeB() {
-        float percent = percentBasecodeB();
-        return ((int) (percent * 10)) / (float) 10;
+    /**
+     * Sets the base code matches of the second submissions.
+     */
+    public void setSecondBaseCodeMatches(JPlagComparison secondBaseCodeMatches) {
+        this.secondBaseCodeMatches = secondBaseCodeMatches;
     }
 
-    /**
-     * This method returns all the files which contributed to a match. Parameter: j == 0 submission A, j != 0 submission B.
+    /*
+     * s==0 uses the start indexes of 1st submission as key for the sorting algorithm. Otherwise the start indexes of 2nd
+     * submission are used.
      */
-    public final String[] files(int j) {
-        if (matches.size() == 0) {
-            return new String[] {};
-        }
+    public final int[] sort_permutation(int s) {   // bubblesort!!!
+        int size = matches.size();
+        int[] perm = new int[size];
+        int i, j, tmp;
 
-        TokenList tokenList = (j == 0 ? firstSubmission : secondSubmission).tokenList;
-        int i, h, starti, starth, count = 1;
+        // initialize permutation array
+        for (i = 0; i < size; i++) {
+            perm[i] = i;
+        }
 
-        o1: for (i = 1; i < matches.size(); i++) {
-            starti = (j == 0 ? matches.get(i).getStartA() : matches.get(i).getStartB());
-            for (h = 0; h < i; h++) {
-                starth = (j == 0 ? matches.get(h).getStartA() : matches.get(h).getStartB());
-                if (tokenList.getToken(starti).file.equals(tokenList.getToken(starth).file)) {
-                    continue o1;
+        if (s == 0) {     // First Submission
+            for (i = 1; i < size; i++) {
+                for (j = 0; j < (size - i); j++) {
+                    if (matches.get(perm[j]).getStartOfFirst() > matches.get(perm[j + 1]).getStartOfFirst()) {
+                        tmp = perm[j];
+                        perm[j] = perm[j + 1];
+                        perm[j + 1] = tmp;
+                    }
                 }
             }
-            count++;
-        }
-
-        String[] res = new String[count];
-        res[0] = tokenList.getToken((j == 0 ? matches.get(0).getStartA() : matches.get(0).getStartB())).file;
-        count = 1;
-
-        o2: for (i = 1; i < matches.size(); i++) {
-            starti = (j == 0 ? matches.get(i).getStartA() : matches.get(i).getStartB());
-            for (h = 0; h < i; h++) {
-                starth = (j == 0 ? matches.get(h).getStartA() : matches.get(h).getStartB());
-                if (tokenList.getToken(starti).file.equals(tokenList.getToken(starth).file)) {
-                    continue o2;
+        } else {        // Second submission
+            for (i = 1; i < size; i++) {
+                for (j = 0; j < (size - i); j++) {
+                    if (matches.get(perm[j]).getStartOfSecond() > matches.get(perm[j + 1]).getStartOfSecond()) {
+                        tmp = perm[j];
+                        perm[j] = perm[j + 1];
+                        perm[j + 1] = tmp;
+                    }
                 }
             }
-            res[count++] = tokenList.getToken(starti).file;
         }
-
-        /*
-         * sort by file name. (so that equally named files are displayed approximately side by side.)
-         */
-        Arrays.sort(res);
-
-        return res;
-    }
-
-    /**
-     * The bigger a match (length) is relatively to the biggest match the redder is the color returned by this method.
-     */
-    public String color(int length) {
-        int color = 255 * length / biggestMatch();
-        String help = (color < 16 ? "0" : "") + Integer.toHexString(color);
-        return "#" + help + "0000";
+        return perm;
     }
 
     @Override
-    public int compare(JPlagComparison o1, JPlagComparison o2) {
-        float p1 = o1.percent();
-        float p2 = o2.percent();
-        if (p1 == p2) {
-            return 0;
-        }
-        if (p1 > p2) {
-            return -1;
-        } else {
-            return 1;
-        }
+    public String toString() {
+        return firstSubmission.name + " <-> " + secondSubmission.name;
     }
 
-    @Override
-    public boolean equals(Object obj) {
-        if (!(obj instanceof JPlagComparison)) {
-            return false;
-        }
-        return (compare(this, (JPlagComparison) obj) == 0);
+    private final float firstBasecodeSimilarity() {
+        float sa = firstSubmission.getNumberOfTokens() - firstSubmission.files.size();
+        return firstBaseCodeMatches.getNumberOfMatchedTokens() * 100 / sa;
     }
 
-    @Override
-    public String toString() {
-        return firstSubmission.name + " <-> " + secondSubmission.name;
+    private final float secondBasecodeSimilarity() {
+        float sb = secondSubmission.getNumberOfTokens() - secondSubmission.files.size();
+        return secondBaseCodeMatches.getNumberOfMatchedTokens() * 100 / sb;
     }
 
 }

+ 26 - 24
jplag/src/main/java/jplag/JPlagResult.java

@@ -53,19 +53,16 @@ public class JPlagResult {
         this.numberOfSubmissions = numberOfSubmissions;
         this.options = options;
         similarityDistribution = calculateSimilarityDistribution(comparisons);
-        comparisons.sort((first, second) -> Float.compare(second.percent(), first.percent())); // Sort by percentage (descending).
+        comparisons.sort((first, second) -> Float.compare(second.similarity(), first.similarity())); // Sort by percentage (descending).
     }
 
     /**
-     * Note: Before, comparisons with a similarity below the given threshold were also included in the similarity matrix.
+     * Drops elements from the comparison list to free memory. Note, that this affects the similarity distribution and is
+     * only meant to be used if you don't need the information about comparisons with lower match percentage anymore.
+     * @param limit the number of comparisons to keep in the list
      */
-    private int[] calculateSimilarityDistribution(List<JPlagComparison> comparisons) {
-        int[] similarityDistribution = new int[10];
-
-        comparisons.stream().map(JPlagComparison::percent).map(percent -> percent / 10).map(Float::intValue).map(index -> index == 10 ? 9 : index)
-                .forEach(index -> similarityDistribution[index]++);
-
-        return similarityDistribution;
+    public void dropComparisons(int limit) {
+        this.comparisons = this.getComparisons(limit);
     }
 
     /**
@@ -76,11 +73,11 @@ public class JPlagResult {
     }
 
     /**
-     * @return a list of comparisons sorted by percentage (descending).
-     * the maximum number of comparisons is limited by the settings set in JPlagOptions
+     * @return a list of comparisons sorted by percentage (descending). the maximum number of comparisons is limited by the
+     * settings set in JPlagOptions
      */
     public List<JPlagComparison> getComparisons() {
-        if(this.options.getMaxNumberOfMatches() == -1) {
+        if (this.options.getMaxNumberOfMatches() == -1) {
             return this.getAllComparisons();
         } else {
             return this.getComparisons(this.options.getMaxNumberOfMatches());
@@ -97,27 +94,20 @@ public class JPlagResult {
     }
 
     /**
-     * Drops elements from the comparison list to free memory. Note, that this affects the similarity distribution
-     * and is only meant to be used if you don't need the information about comparisons with lower match percentage
-     * anymore.
-     * @param limit the number of comparisons to keep in the list
+     * @return the duration of the comparison in milliseconds.
      */
-    public void dropComparisons(int limit) {
-        this.comparisons = this.getComparisons(limit);
-    }
-
     public long getDuration() {
         return durationInMillis;
     }
 
-    public JPlagOptions getOptions() {
-        return options;
-    }
-
     public int getNumberOfSubmissions() {
         return numberOfSubmissions;
     }
 
+    public JPlagOptions getOptions() {
+        return options;
+    }
+
     public int[] getSimilarityDistribution() {
         return similarityDistribution;
     }
@@ -127,4 +117,16 @@ public class JPlagResult {
         return String.format("JPlagResult { comparisons: %d, duration: %d ms, language: %s, submissions: %d }", getComparisons().size(),
                 getDuration(), getOptions().getLanguageOption(), getNumberOfSubmissions());
     }
+
+    /**
+     * Note: Before, comparisons with a similarity below the given threshold were also included in the similarity matrix.
+     */
+    private int[] calculateSimilarityDistribution(List<JPlagComparison> comparisons) {
+        int[] similarityDistribution = new int[10];
+
+        comparisons.stream().map(JPlagComparison::similarity).map(percent -> percent / 10).map(Float::intValue).map(index -> index == 10 ? 9 : index)
+                .forEach(index -> similarityDistribution[index]++);
+
+        return similarityDistribution;
+    }
 }

+ 23 - 23
jplag/src/main/java/jplag/Match.java

@@ -1,42 +1,42 @@
 package jplag;
 
 /**
- * Represents two sections of two submissions A and B that are similar.
+ * Represents two sections of two submissions that are similar.
  */
 public class Match {
 
-    private final int startA;
-    private final int startB;
+    private final int startOfFirst;
+    private final int startOfSecond;
     private final int length;
 
     /**
      * Creates a match.
-     * @param startA is the starting index in the submission A.
-     * @param startB is the starting index in the submission B.
-     * @param length is the length of these similar sections.
+     * @param startOfSecond is the starting token index in the first submission.
+     * @param startOfSecond is the starting token index in the second submission.
+     * @param length is the length of these similar sections (number of tokens).
      */
-    public Match(int startA, int startB, int length) {
-        this.startA = startA;
-        this.startB = startB;
+    public Match(int startOfFirst, int startOfSecond, int length) {
+        this.startOfFirst = startOfFirst;
+        this.startOfSecond = startOfSecond;
         this.length = length;
     }
 
     /**
-     * @return the starting index in the submission A.
+     * @return the starting index in the first submission.
      */
-    public int getStartA() {
-        return startA;
+    public int getStartOfFirst() {
+        return startOfFirst;
     }
 
     /**
-     * @return the starting index in the submission B.
+     * @return the starting index in the second submission.
      */
-    public int getStartB() {
-        return startB;
+    public int getStartOfSecond() {
+        return startOfSecond;
     }
 
     /**
-     * @return the length of the similar sections.
+     * @return the length of the similar sections, meaning the number of tokens.
      */
     public int getLength() {
         return length;
@@ -46,21 +46,21 @@ public class Match {
      * Checks if two matches overlap.
      * @return true if they do.
      */
-    public final boolean overlap(int oStartA, int oStartB, int oLength) {
-        if (startA < oStartA) {
-            if ((oStartA - startA) < length) {
+    public final boolean overlap(int otherStartOfFirst, int otherStartOfSecond, int oLength) {
+        if (startOfFirst < otherStartOfFirst) {
+            if ((otherStartOfFirst - startOfFirst) < length) {
                 return true;
             }
         } else {
-            if ((startA - oStartA) < oLength) {
+            if ((startOfFirst - otherStartOfFirst) < oLength) {
                 return true;
             }
         }
 
-        if (startB < oStartB) {
-            return (oStartB - startB) < length;
+        if (startOfSecond < otherStartOfSecond) {
+            return (otherStartOfSecond - startOfSecond) < length;
         } else {
-            return (startB - oStartB) < oLength;
+            return (startOfSecond - otherStartOfSecond) < oLength;
         }
     }
 }

+ 2 - 3
jplag/src/main/java/jplag/Submission.java

@@ -204,7 +204,7 @@ public class Submission implements Comparable<Submission> {
             if (!file.isAbsolute()) {
                 file = new File(submissionFile, files[i]);
             }
-            
+
             try {
                 int size = (int) file.length();
                 char[] buffer = new char[size];
@@ -227,7 +227,7 @@ public class Submission implements Comparable<Submission> {
 
         return result;
     }
-    
+
     /**
      * Resets the base code flag for all tokens of this submission.
      */
@@ -237,7 +237,6 @@ public class Submission implements Comparable<Submission> {
         }
     }
 
-
     /*
      * This method is used to copy files that can not be parsed to a special folder: jplag/errors/java old_java scheme cpp
      * /001/(...files...) /002/(...files...)

+ 1 - 1
jplag/src/main/java/jplag/options/JPlagOptions.java

@@ -126,7 +126,7 @@ public class JPlagOptions {
     private boolean hasMinTokenMatch() {
         return this.minTokenMatch != null;
     }
-    
+
     public ComparisonMode getComparisonMode() {
         return comparisonMode;
     }

+ 2 - 6
jplag/src/main/java/jplag/options/LanguageOption.java

@@ -39,16 +39,12 @@ public enum LanguageOption {
     }
 
     public static LanguageOption fromDisplayName(String displayName) {
-        return Arrays.stream(LanguageOption.values())
-                .filter(languageOption -> languageOption.displayName.equals(displayName))
-                .findFirst()
+        return Arrays.stream(LanguageOption.values()).filter(languageOption -> languageOption.displayName.equals(displayName)).findFirst()
                 .orElse(getDefault());
     }
 
     public static Collection<String> getAllDisplayNames() {
-        return Arrays.stream(LanguageOption.values())
-                .map(languageOption -> languageOption.displayName)
-                .collect(toList());
+        return Arrays.stream(LanguageOption.values()).map(languageOption -> languageOption.displayName).collect(toList());
     }
 
     public static LanguageOption getDefault() {

+ 17 - 3
jplag/src/main/java/jplag/options/SimilarityMetric.java

@@ -1,7 +1,21 @@
 package jplag.options;
 
+import java.util.function.Function;
+
+import jplag.JPlagComparison;
+
 public enum SimilarityMetric {
-    AVG,
-    MIN,
-    MAX
+    AVG(it -> it.similarity()),
+    MIN(it -> it.minimalSimilarity()),
+    MAX(it -> it.maximalSimilarity());
+
+    private final Function<JPlagComparison, Float> similarityFunction;
+
+    private SimilarityMetric(Function<JPlagComparison, Float> determinePercentage) {
+        this.similarityFunction = determinePercentage;
+    }
+
+    public boolean isAboveThreshold(JPlagComparison comparison, float similarityThreshold) {
+        return similarityFunction.apply(comparison) >= similarityThreshold;
+    }
 }

+ 2 - 5
jplag/src/main/java/jplag/options/Verbosity.java

@@ -1,10 +1,9 @@
 package jplag.options;
 
-public enum Verbosity {
+public enum Verbosity { // TODO TS: These levels are not used consistently.
     PARSER,
     QUIET,
-    LONG,
-    DETAILS;
+    LONG;
 
     public static Verbosity fromOption(String optionName) {
         switch (optionName) {
@@ -14,8 +13,6 @@ public enum Verbosity {
             return QUIET;
         case "long":
             return LONG;
-        case "details":
-            return DETAILS;
         default:
             return QUIET;
         }

+ 61 - 60
jplag/src/main/java/jplag/reporting/Report.java

@@ -25,9 +25,9 @@ import jplag.Token;
 import jplag.TokenList;
 
 /**
- * This class writes all the HTML pages
+ * This class writes all the HTML pages.
  */
-public class Report {
+public class Report { // Mostly legacy code with some minor improvements.
 
     private static final String CSV_FILE = "matches_avg.csv";
     private static final String[] PICS = {"forward.gif", "back.gif"};
@@ -133,21 +133,21 @@ public class Report {
      */
     private void reportComparison(HTMLFile htmlFile, JPlagComparison comparison, int index) {
         Match match;
-        TokenList tokensA = comparison.firstSubmission.tokenList;
-        TokenList tokensB = comparison.secondSubmission.tokenList;
+        TokenList tokensA = comparison.getFirstSubmission().tokenList;
+        TokenList tokensB = comparison.getSecondSubmission().tokenList;
         // sort();
 
         htmlFile.println("<TABLE BORDER=\"1\" CELLSPACING=\"0\" BGCOLOR=\"#d0d0d0\">");
-        htmlFile.println("<TR><TH><TH>" + comparison.firstSubmission.name + " (" + comparison.percentA() + "%)<TH>" + comparison.secondSubmission.name
-                + " (" + comparison.percentB() + "%)<TH>" + msg.getString("AllMatches.Tokens"));
+        htmlFile.println("<TR><TH><TH>" + comparison.getFirstSubmission().name + " (" + comparison.similarityOfFirst() + "%)<TH>"
+                + comparison.getSecondSubmission().name + " (" + comparison.similarityOfSecond() + "%)<TH>" + msg.getString("AllMatches.Tokens"));
 
-        for (int i = 0; i < comparison.matches.size(); i++) {
-            match = comparison.matches.get(i);
+        for (int i = 0; i < comparison.getMatches().size(); i++) {
+            match = comparison.getMatches().get(i);
 
-            Token startA = tokensA.getToken(match.getStartA());
-            Token endA = tokensA.getToken(match.getStartA() + match.getLength() - 1);
-            Token startB = tokensB.getToken(match.getStartB());
-            Token endB = tokensB.getToken(match.getStartB() + match.getLength() - 1);
+            Token startA = tokensA.getToken(match.getStartOfFirst());
+            Token endA = tokensA.getToken(match.getStartOfFirst() + match.getLength() - 1);
+            Token startB = tokensB.getToken(match.getStartOfSecond());
+            Token endB = tokensB.getToken(match.getStartOfSecond() + match.getLength() - 1);
 
             String col = Color.getHexadecimalValue(i);
 
@@ -172,13 +172,14 @@ public class Report {
                 htmlFile.print("(" + startB.getLine() + "-" + endB.getLine());
             }
 
-            htmlFile.println(")</A><TD ALIGN=center>" + "<FONT COLOR=\"" + comparison.color(match.getLength()) + "\">" + match.getLength() + "</FONT>");
+            htmlFile.println(
+                    ")</A><TD ALIGN=center>" + "<FONT COLOR=\"" + comparison.color(match.getLength()) + "\">" + match.getLength() + "</FONT>");
         }
 
         if (result.getOptions().hasBaseCode()) {
             htmlFile.print(
-                    "<TR><TD BGCOLOR=\"#C0C0C0\"><TD>" + msg.getString("AllMatches.Basecode") + " " + comparison.roundedPercentBasecodeA() + "%");
-            htmlFile.println("<TD>" + msg.getString("AllMatches.Basecode") + " " + comparison.roundedPercentBasecodeB() + "%<TD>&nbsp;");
+                    "<TR><TD BGCOLOR=\"#C0C0C0\"><TD>" + msg.getString("AllMatches.Basecode") + " " + comparison.basecodeSimilarityOfFirst() + "%");
+            htmlFile.println("<TD>" + msg.getString("AllMatches.Basecode") + " " + comparison.basecodeSimilarityOfSecond() + "%<TD>&nbsp;");
         }
 
         htmlFile.println("</TABLE>");
@@ -259,10 +260,10 @@ public class Report {
      * makes use of the column and length information!
      */
     private int writeImprovedSubmission(HTMLFile f, int i, JPlagComparison comparison, int j) throws jplag.ExitException {
-        Submission sub = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission);
+        Submission sub = (j == 0 ? comparison.getFirstSubmission() : comparison.getSecondSubmission());
         String[] files = comparison.files(j);
         String[][] text = sub.readFiles(files);
-        TokenList tokens = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission).tokenList;
+        TokenList tokens = (j == 0 ? comparison.getFirstSubmission() : comparison.getSecondSubmission()).tokenList;
 
         // Markup list:
         Comparator<MarkupText> comp = (mo1, mo2) -> {
@@ -277,11 +278,11 @@ public class Report {
         };
         TreeMap<MarkupText, Object> markupList = new TreeMap<>(comp);
 
-        for (int x = 0; x < comparison.matches.size(); x++) {
-            Match onematch = comparison.matches.get(x);
+        for (int x = 0; x < comparison.getMatches().size(); x++) {
+            Match onematch = comparison.getMatches().get(x);
 
-            Token start = tokens.getToken(j == 0 ? onematch.getStartA() : onematch.getStartB());
-            Token end = tokens.getToken((j == 0 ? onematch.getStartA() : onematch.getStartB()) + onematch.getLength() - 1);
+            Token start = tokens.getToken(j == 0 ? onematch.getStartOfFirst() : onematch.getStartOfSecond());
+            Token end = tokens.getToken((j == 0 ? onematch.getStartOfFirst() : onematch.getStartOfSecond()) + onematch.getLength() - 1);
             for (int fileIndex = 0; fileIndex < files.length; fileIndex++) {
                 if (start.file.equals(files[fileIndex]) && text[fileIndex] != null) {
                     String tmp = "<FONT color=\"" + Color.getHexadecimalValue(x) + "\">" + (j == 1 ? "<div style=\"position:absolute;left:0\">" : "")
@@ -300,13 +301,13 @@ public class Report {
             }
         }
 
-        if (result.getOptions().hasBaseCode() && comparison.baseCodeMatchesA != null && comparison.baseCodeMatchesB != null) {
-            JPlagComparison baseCodeComparison = (j == 0 ? comparison.baseCodeMatchesA : comparison.baseCodeMatchesB);
+        if (result.getOptions().hasBaseCode() && comparison.getFirstBaseCodeMatches() != null && comparison.getSecondBaseCodeMatches() != null) {
+            JPlagComparison baseCodeComparison = (j == 0 ? comparison.getFirstBaseCodeMatches() : comparison.getSecondBaseCodeMatches());
 
-            for (int x = 0; x < baseCodeComparison.matches.size(); x++) {
-                Match onematch = baseCodeComparison.matches.get(x);
-                Token start = tokens.getToken(onematch.getStartA());
-                Token end = tokens.getToken(onematch.getStartA() + onematch.getLength() - 1);
+            for (int x = 0; x < baseCodeComparison.getMatches().size(); x++) {
+                Match onematch = baseCodeComparison.getMatches().get(x);
+                Token start = tokens.getToken(onematch.getStartOfFirst());
+                Token end = tokens.getToken(onematch.getStartOfFirst() + onematch.getLength() - 1);
 
                 for (int fileIndex = 0; fileIndex < files.length; fileIndex++) {
                     if (start.file.equals(files[fileIndex]) && text[fileIndex] != null) {
@@ -445,9 +446,8 @@ public class Report {
         if (result.getComparisons().size() > 0) {
             htmlFile.println("<TR BGCOLOR=#aaaaff VALIGN=top><TD>" + msg.getString("Report.Matches_displayed") + ":</TD>" + "<TD>");
 
-            htmlFile.println(result.getComparisons().size() + " of " + result.getAllComparisons().size()
-                    + " (" + msg.getString("Report.Treshold") + ": "
-                    + result.getOptions().getSimilarityThreshold() + "%)<br>");
+            htmlFile.println(result.getComparisons().size() + " of " + result.getAllComparisons().size() + " (" + msg.getString("Report.Treshold")
+                    + ": " + result.getOptions().getSimilarityThreshold() + "%)<br>");
 
             htmlFile.println("</TD></TR>");
         }
@@ -474,10 +474,10 @@ public class Report {
      * getIndex() method of the token. It is meant to be used with the Character front end
      */
     private void writeIndexedSubmission(HTMLFile f, int i, JPlagComparison comparison, int j) throws ExitException {
-        Submission sub = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission);
+        Submission sub = (j == 0 ? comparison.getFirstSubmission() : comparison.getSecondSubmission());
         String[] files = comparison.files(j);
         char[][] text = sub.readFilesChar(files);
-        TokenList tokens = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission).tokenList;
+        TokenList tokens = (j == 0 ? comparison.getFirstSubmission() : comparison.getSecondSubmission()).tokenList;
 
         // get index array with matches sorted in ascending order.
         int[] perm = comparison.sort_permutation(j);
@@ -502,10 +502,10 @@ public class Report {
 
             for (int charNr = 0; charNr < buffer.length; charNr++) {
                 if (onematch == null) {
-                    if (index < comparison.matches.size()) {
-                        onematch = comparison.matches.get(perm[index]);
-                        start = tokens.getToken(j == 0 ? onematch.getStartA() : onematch.getStartB());
-                        end = tokens.getToken((j == 0 ? onematch.getStartA() : onematch.getStartB()) + onematch.getLength() - 1);
+                    if (index < comparison.getMatches().size()) {
+                        onematch = comparison.getMatches().get(perm[index]);
+                        start = tokens.getToken(j == 0 ? onematch.getStartOfFirst() : onematch.getStartOfSecond());
+                        end = tokens.getToken((j == 0 ? onematch.getStartOfFirst() : onematch.getStartOfSecond()) + onematch.getLength() - 1);
                         index++;
                     } else {
                         start = end = null;
@@ -559,15 +559,16 @@ public class Report {
         htmlFile.println("<TABLE CELLPADDING=3 CELLSPACING=2>");
 
         for (JPlagComparison comparison : comparisons) {
-            String submissionNameA = comparison.firstSubmission.name;
-            String submissionNameB = comparison.secondSubmission.name;
+            String submissionNameA = comparison.getFirstSubmission().name;
+            String submissionNameB = comparison.getSecondSubmission().name;
 
-            htmlFile.print("<TR><TD BGCOLOR=" + color(comparison.percentA(), 128, 192, 128, 192, 255, 255) + ">" + submissionNameA
+            htmlFile.print("<TR><TD BGCOLOR=" + color(comparison.similarityOfFirst(), 128, 192, 128, 192, 255, 255) + ">" + submissionNameA
                     + "</TD><TD><nobr>-&gt;</nobr>");
 
-            htmlFile.print("</TD><TD BGCOLOR=" + color(comparison.percentB(), 128, 192, 128, 192, 255, 255) + " ALIGN=center><A HREF=\"match"
-                    + getComparisonIndex(comparison) + ".html\">" + submissionNameB + "</A><BR><FONT COLOR=\""
-                    + color(comparison.percent(), 0, 255, 0, 0, 0, 0) + "\">(" + (((int) (comparison.percent() * 10)) / (float) 10) + "%)</FONT>");
+            htmlFile.print("</TD><TD BGCOLOR=" + color(comparison.similarityOfSecond(), 128, 192, 128, 192, 255, 255)
+                    + " ALIGN=center><A HREF=\"match" + getComparisonIndex(comparison) + ".html\">" + submissionNameB + "</A><BR><FONT COLOR=\""
+                    + color(comparison.similarity(), 0, 255, 0, 0, 0, 0) + "\">(" + (((int) (comparison.similarity() * 10)) / (float) 10)
+                    + "%)</FONT>");
 
             htmlFile.println("</TD></TR>");
         }
@@ -580,7 +581,7 @@ public class Report {
         HTMLFile htmlFile = createHTMLFile("match" + i + ".html");
 
         writeHTMLHeader(htmlFile, TagParser.parse(msg.getString("Report.Matches_for_X1_AND_X2"),
-                new String[] {comparison.firstSubmission.name, comparison.secondSubmission.name}));
+                new String[] {comparison.getFirstSubmission().name, comparison.getSecondSubmission().name}));
 
         htmlFile.println("<body>");
         htmlFile.println("  <div style=\"align-items: center; display: flex; justify-content: space-around;\">");
@@ -588,10 +589,10 @@ public class Report {
         htmlFile.println("    <div>");
         htmlFile.println("      <h3 align=\"center\">");
         htmlFile.println(TagParser.parse(msg.getString("Report.Matches_for_X1_AND_X2"),
-                new String[] {comparison.firstSubmission.name, comparison.secondSubmission.name}));
+                new String[] {comparison.getFirstSubmission().name, comparison.getSecondSubmission().name}));
         htmlFile.println("      </h3>");
         htmlFile.println("      <h1 align=\"center\">");
-        htmlFile.println("        " + comparison.roundedPercent() + "%");
+        htmlFile.println("        " + comparison.roundedSimilarity() + "%");
         htmlFile.println("      </h1>");
         htmlFile.println("      <center>");
         htmlFile.println("        <a href=\"index.html\" target=\"_top\">");
@@ -653,13 +654,13 @@ public class Report {
             writer = new FileWriter(csvFile);
 
             for (JPlagComparison comparison : comparisons) {
-                String submissionNameA = comparison.firstSubmission.name;
-                String submissionNameB = comparison.secondSubmission.name;
+                String submissionNameA = comparison.getFirstSubmission().name;
+                String submissionNameB = comparison.getSecondSubmission().name;
 
                 writer.write(getComparisonIndex(comparison) + ";");
                 writer.write(submissionNameA + ";");
                 writer.write(submissionNameB + ";");
-                writer.write((((int) (comparison.percent() * 10)) / (float) 10) + ";");
+                writer.write((((int) (comparison.similarity() * 10)) / (float) 10) + ";");
                 writer.write("\n");
             }
 
@@ -678,20 +679,20 @@ public class Report {
      * i is the number of the match j == 0 if subA is considered, otherwise (j must then be 1) it is subB
      */
     private void writeNormalSubmission(HTMLFile f, int i, JPlagComparison comparison, int j) throws ExitException {
-        Submission sub = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission);
+        Submission sub = (j == 0 ? comparison.getFirstSubmission() : comparison.getSecondSubmission());
         String[] files = comparison.files(j);
 
         String[][] text = sub.readFiles(files);
 
-        TokenList tokens = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission).tokenList;
+        TokenList tokens = (j == 0 ? comparison.getFirstSubmission() : comparison.getSecondSubmission()).tokenList;
         Match currentMatch;
         String hilf;
         int h;
-        for (int x = 0; x < comparison.matches.size(); x++) {
-            currentMatch = comparison.matches.get(x);
+        for (int x = 0; x < comparison.getMatches().size(); x++) {
+            currentMatch = comparison.getMatches().get(x);
 
-            Token start = tokens.getToken(j == 0 ? currentMatch.getStartA() : currentMatch.getStartB());
-            Token ende = tokens.getToken((j == 0 ? currentMatch.getStartA() : currentMatch.getStartB()) + currentMatch.getLength() - 1);
+            Token start = tokens.getToken(j == 0 ? currentMatch.getStartOfFirst() : currentMatch.getStartOfSecond());
+            Token ende = tokens.getToken((j == 0 ? currentMatch.getStartOfFirst() : currentMatch.getStartOfSecond()) + currentMatch.getLength() - 1);
 
             for (int y = 0; y < files.length; y++) {
                 if (start.file.equals(files[y]) && text[y] != null) {
@@ -719,13 +720,13 @@ public class Report {
             }
         }
 
-        if (result.getOptions().hasBaseCode() && comparison.baseCodeMatchesA != null && comparison.baseCodeMatchesB != null) {
-            JPlagComparison baseCodeComparison = (j == 0 ? comparison.baseCodeMatchesA : comparison.baseCodeMatchesB);
+        if (result.getOptions().hasBaseCode() && comparison.getFirstBaseCodeMatches() != null && comparison.getSecondBaseCodeMatches() != null) {
+            JPlagComparison baseCodeComparison = (j == 0 ? comparison.getFirstBaseCodeMatches() : comparison.getSecondBaseCodeMatches());
 
-            for (int x = 0; x < baseCodeComparison.matches.size(); x++) {
-                currentMatch = baseCodeComparison.matches.get(x);
-                Token start = tokens.getToken(currentMatch.getStartA());
-                Token ende = tokens.getToken(currentMatch.getStartA() + currentMatch.getLength() - 1);
+            for (int x = 0; x < baseCodeComparison.getMatches().size(); x++) {
+                currentMatch = baseCodeComparison.getMatches().get(x);
+                Token start = tokens.getToken(currentMatch.getStartOfFirst());
+                Token ende = tokens.getToken(currentMatch.getStartOfFirst() + currentMatch.getLength() - 1);
 
                 for (int y = 0; y < files.length; y++) {
                     if (start.file.equals(files[y]) && text[y] != null) {

+ 1 - 2
jplag/src/main/java/jplag/reporting/TagParser.java

@@ -12,8 +12,7 @@ public class TagParser {
         String[] tokens = message.split("[{}]", -1);
         String result = tokens[0];
 
-        for (int i = 1; i < tokens.length; i += 2)    // Go to next tag position
-        {
+        for (int i = 1; i < tokens.length; i += 2) { // Go to next tag position
             try {
                 int ind = tokens[i].indexOf('_');
                 String num = (ind == -1) ? tokens[i] : tokens[i].substring(0, ind);

+ 4 - 21
jplag/src/main/java/jplag/strategy/AbstractComparisonStrategy.java

@@ -8,7 +8,6 @@ import jplag.GreedyStringTiling;
 import jplag.JPlagComparison;
 import jplag.Submission;
 import jplag.options.JPlagOptions;
-import jplag.options.SimilarityMetric;
 
 public abstract class AbstractComparisonStrategy implements ComparisonStrategy {
 
@@ -38,31 +37,15 @@ public abstract class AbstractComparisonStrategy implements ComparisonStrategy {
      */
     protected Optional<JPlagComparison> compareSubmissions(Submission first, Submission second, boolean withBaseCode) {
         JPlagComparison comparison = greedyStringTiling.compare(first, second);
-        System.out.println("Comparing " + first.name + "-" + second.name + ": " + comparison.percent());
+        System.out.println("Comparing " + first.name + "-" + second.name + ": " + comparison.similarity());
         if (withBaseCode) {
-            comparison.baseCodeMatchesA = baseCodeMatches.get(comparison.firstSubmission.name);
-            comparison.baseCodeMatchesB = baseCodeMatches.get(comparison.secondSubmission.name);
+            comparison.setFirstBaseCodeMatches(baseCodeMatches.get(comparison.getFirstSubmission().name));
+            comparison.setSecondBaseCodeMatches(baseCodeMatches.get(comparison.getSecondSubmission().name));
         }
-        if (isAboveSimilarityThreshold(comparison)) {
+        if (options.getSimilarityMetric().isAboveThreshold(comparison, options.getSimilarityThreshold())) {
             return Optional.of(comparison);
         }
         return Optional.empty();
     }
 
-    private 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;
-        }
-    }
-
 }

+ 3 - 3
jplag/src/main/java/jplag/strategy/NormalComparisonStrategy.java

@@ -15,19 +15,19 @@ public class NormalComparisonStrategy extends AbstractComparisonStrategy {
     public NormalComparisonStrategy(JPlagOptions options, GreedyStringTiling greedyStringTiling) {
         super(options, greedyStringTiling);
     }
-    
+
     @Override
     public JPlagResult compareSubmissions(Vector<Submission> submissions, Submission baseCodeSubmission) {
         boolean withBaseCode = baseCodeSubmission != null;
         if (withBaseCode) {
             compareSubmissionsToBaseCode(submissions, baseCodeSubmission);
         }
-        
+
         long timeBeforeStartInMillis = System.currentTimeMillis();
         int i, j, numberOfSubmissions = submissions.size();
         Submission first, second;
         List<JPlagComparison> comparisons = new ArrayList<>();
-        
+
         for (i = 0; i < (numberOfSubmissions - 1); i++) {
             first = submissions.elementAt(i);
             if (first.tokenList == null) {

+ 6 - 6
jplag/src/test/java/jplag/NewJavaFeaturesTest.java

@@ -1,9 +1,9 @@
 package jplag;
 
-import org.junit.Test;
-
 import static org.junit.Assert.assertEquals;
 
+import org.junit.Test;
+
 public class NewJavaFeaturesTest extends TestBase {
     private static final String EXCLUSION_FILE_NAME = "blacklist.txt";
     private static final String ROOT_DIRECTORY = "NewJavaFeatures";
@@ -16,12 +16,12 @@ public class NewJavaFeaturesTest extends TestBase {
         assertEquals(2, result.getNumberOfSubmissions());
         assertEquals(1, result.getComparisons().size());
         var comparison = result.getComparisons().get(0);
-        assertEquals(100, comparison.percent(), Double.MIN_NORMAL);
+        assertEquals(100, comparison.similarity(), Double.MIN_NORMAL);
         
         // Five matches that each start at the same position:
-        assertEquals(4, comparison.matches.size());
-        for (Match match : comparison.matches) {
-            assertEquals(match.getStartA(), match.getStartB());
+        assertEquals(4, comparison.getMatches().size());
+        for (Match match : comparison.getMatches()) {
+            assertEquals(match.getStartOfFirst(), match.getStartOfSecond());
         }
     }
 

+ 16 - 16
jplag/src/test/java/jplag/NormalComparisonTest.java

@@ -1,10 +1,10 @@
 package jplag;
 
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
 
 import java.util.Optional;
 
-import static org.junit.Assert.assertEquals;
+import org.junit.Test;
 
 public class NormalComparisonTest extends TestBase {
 
@@ -17,9 +17,9 @@ public class NormalComparisonTest extends TestBase {
 
         assertEquals(2, result.getNumberOfSubmissions());
         assertEquals(1, result.getComparisons().size());
-        assertEquals(1, result.getComparisons().get(0).matches.size());
+        assertEquals(1, result.getComparisons().get(0).getMatches().size());
         assertEquals(1, result.getSimilarityDistribution()[6]);
-        assertEquals(62.07f, result.getComparisons().get(0).percent(), 0.1f);
+        assertEquals(62.07f, result.getComparisons().get(0).similarity(), 0.1f);
     }
 
     /**
@@ -33,7 +33,7 @@ public class NormalComparisonTest extends TestBase {
         assertEquals(3, result.getComparisons().size());
 
         result.getAllComparisons().forEach(comparison -> {
-            assertEquals(0f, comparison.percent(), 0.1f);
+            assertEquals(0f, comparison.similarity(), 0.1f);
         });
     }
 
@@ -56,10 +56,10 @@ public class NormalComparisonTest extends TestBase {
         result.getAllComparisons()
                 .stream()
                 .filter(comparison ->
-                        comparison.secondSubmission.name.equals("E") ||
-                                comparison.firstSubmission.name.equals("E"))
+                        comparison.getSecondSubmission().name.equals("E") ||
+                                comparison.getFirstSubmission().name.equals("E"))
                 .forEach(comparison ->
-                        assertEquals(0f, comparison.percent(), 0.1f)
+                        assertEquals(0f, comparison.similarity(), 0.1f)
                 );
 
         // Hard coded assertions on selected comparisons
@@ -72,26 +72,26 @@ public class NormalComparisonTest extends TestBase {
 
         // More detailed assertions for the plagiarism in A-D
         var biggestMatch = getSelectedComparison(result, "A", "D");
-        assertEquals(96.4f, biggestMatch.get().percentMaxAB(), 0.1f);
-        assertEquals(65.3f, biggestMatch.get().percentMinAB(), 0.1f);
-        assertEquals(12, biggestMatch.get().matches.size());
+        assertEquals(96.4f, biggestMatch.get().maximalSimilarity(), 0.1f);
+        assertEquals(65.3f, biggestMatch.get().minimalSimilarity(), 0.1f);
+        assertEquals(12, biggestMatch.get().getMatches().size());
 
     }
 
     // TODO SH: Methods like this should be moved to the API and also should accept wildcards
     private float getSelectedPercent(JPlagResult result, String nameA, String nameB) {
         return getSelectedComparison(result, nameA, nameB)
-                .map(JPlagComparison::percent)
+                .map(JPlagComparison::similarity)
                 .orElse(-1f);
     }
 
     private Optional<JPlagComparison> getSelectedComparison(JPlagResult result, String nameA, String nameB) {
         return result.getAllComparisons().stream()
                 .filter(comparison ->
-                        comparison.firstSubmission.name.equals(nameA) &&
-                                comparison.secondSubmission.name.equals(nameB) ||
-                                comparison.firstSubmission.name.equals(nameB) &&
-                                        comparison.secondSubmission.name.equals(nameA))
+                        comparison.getFirstSubmission().name.equals(nameA) &&
+                                comparison.getSecondSubmission().name.equals(nameB) ||
+                                comparison.getFirstSubmission().name.equals(nameB) &&
+                                        comparison.getSecondSubmission().name.equals(nameA))
                 .findFirst();
     }
 }

+ 11 - 11
jplag/src/test/java/jplag/ParallelComparisonTest.java

@@ -24,9 +24,9 @@ public class ParallelComparisonTest extends TestBase {
 
         assertEquals(2, result.getNumberOfSubmissions());
         assertEquals(1, result.getComparisons().size());
-        assertEquals(1, result.getComparisons().get(0).matches.size());
+        assertEquals(1, result.getComparisons().get(0).getMatches().size());
         assertEquals(1, result.getSimilarityDistribution()[6]);
-        assertEquals(62.07f, result.getComparisons().get(0).percent(), 0.1f);
+        assertEquals(62.07f, result.getComparisons().get(0).similarity(), 0.1f);
     }
 
     /**
@@ -40,7 +40,7 @@ public class ParallelComparisonTest extends TestBase {
         assertEquals(3, result.getComparisons().size());
 
         result.getAllComparisons().forEach(comparison -> {
-            assertEquals(0f, comparison.percent(), 0.1f);
+            assertEquals(0f, comparison.similarity(), 0.1f);
         });
     }
 
@@ -58,8 +58,8 @@ public class ParallelComparisonTest extends TestBase {
 
         // All comparisons with E shall have no matches
         result.getAllComparisons().stream()
-                .filter(comparison -> comparison.secondSubmission.name.equals("E") || comparison.firstSubmission.name.equals("E"))
-                .forEach(comparison -> assertEquals(0f, comparison.percent(), 0.1f));
+                .filter(comparison -> comparison.getSecondSubmission().name.equals("E") || comparison.getFirstSubmission().name.equals("E"))
+                .forEach(comparison -> assertEquals(0f, comparison.similarity(), 0.1f));
 
         // Hard coded assertions on selected comparisons
         assertEquals(24.6f, getSelectedPercent(result, "A", "B"), 0.1f);
@@ -71,21 +71,21 @@ public class ParallelComparisonTest extends TestBase {
 
         // More detailed assertions for the plagiarism in A-D
         var biggestMatch = getSelectedComparison(result, "A", "D");
-        assertEquals(96.4f, biggestMatch.get().percentMaxAB(), 0.1f);
-        assertEquals(65.3f, biggestMatch.get().percentMinAB(), 0.1f);
-        assertEquals(12, biggestMatch.get().matches.size());
+        assertEquals(96.4f, biggestMatch.get().maximalSimilarity(), 0.1f);
+        assertEquals(65.3f, biggestMatch.get().minimalSimilarity(), 0.1f);
+        assertEquals(12, biggestMatch.get().getMatches().size());
 
     }
 
     // TODO SH: Methods like this should be moved to the API and also should accept wildcards
     private float getSelectedPercent(JPlagResult result, String nameA, String nameB) {
-        return getSelectedComparison(result, nameA, nameB).map(JPlagComparison::percent).orElse(-1f);
+        return getSelectedComparison(result, nameA, nameB).map(JPlagComparison::similarity).orElse(-1f);
     }
 
     private Optional<JPlagComparison> getSelectedComparison(JPlagResult result, String nameA, String nameB) {
         return result.getAllComparisons().stream()
-                .filter(comparison -> comparison.firstSubmission.name.equals(nameA) && comparison.secondSubmission.name.equals(nameB)
-                        || comparison.firstSubmission.name.equals(nameB) && comparison.secondSubmission.name.equals(nameA))
+                .filter(comparison -> comparison.getFirstSubmission().name.equals(nameA) && comparison.getSecondSubmission().name.equals(nameB)
+                        || comparison.getFirstSubmission().name.equals(nameB) && comparison.getSecondSubmission().name.equals(nameA))
                 .findFirst();
     }
 }

+ 2 - 2
jplag/src/test/java/jplag/VolumeTest.java

@@ -50,10 +50,10 @@ public class VolumeTest extends TestBase {
         System.out.println("Volume test size: " + csv.size());
 
         results.getAllComparisons().forEach(result -> {
-            var key = result.firstSubmission.name + result.secondSubmission.name;
+            var key = result.getFirstSubmission().name + result.getSecondSubmission().name;
 
             assertTrue(csv.containsKey(key));
-            assertEquals(csv.getOrDefault(key, -1f), result.percent(), 0.1f);
+            assertEquals(csv.getOrDefault(key, -1f), result.similarity(), 0.1f);
         });
 
     }