Browse Source

Simplify getting start of first/second match.

Alberth 5 years ago
parent
commit
9db841b735

+ 6 - 6
jplag/src/main/java/de/jplag/JPlagComparison.java

@@ -77,9 +77,9 @@ public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME T
         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());
+            starti = matches.get(i).getStart(j == 0);
             for (h = 0; h < i; h++) {
-                starth = (j == 0 ? matches.get(h).getStartOfFirst() : matches.get(h).getStartOfSecond());
+                starth = matches.get(h).getStart(j == 0);
                 if (tokenList.getToken(starti).file.equals(tokenList.getToken(starth).file)) {
                     continue o1;
                 }
@@ -88,13 +88,13 @@ public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME T
         }
 
         String[] res = new String[count];
-        res[0] = tokenList.getToken((j == 0 ? matches.get(0).getStartOfFirst() : matches.get(0).getStartOfSecond())).file;
+        res[0] = tokenList.getToken(matches.get(0).getStart(j == 0)).file;
         count = 1;
 
         o2: for (i = 1; i < matches.size(); i++) {
-            starti = (j == 0 ? matches.get(i).getStartOfFirst() : matches.get(i).getStartOfSecond());
+            starti = matches.get(i).getStart(j == 0);
             for (h = 0; h < i; h++) {
-                starth = (j == 0 ? matches.get(h).getStartOfFirst() : matches.get(h).getStartOfSecond());
+                starth = matches.get(h).getStart(j == 0);
                 if (tokenList.getToken(starti).file.equals(tokenList.getToken(starth).file)) {
                     continue o2;
                 }
@@ -267,7 +267,7 @@ public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME T
 
     private int selectStartof(Integer index, boolean useFirst) {
         Match match = matches.get(index);
-        return useFirst ? match.getStartOfFirst() : match.getStartOfSecond();
+        return match.getStart(useFirst);
     }
 
     @Override

+ 10 - 1
jplag/src/main/java/de/jplag/Match.java

@@ -11,7 +11,7 @@ public class Match {
 
     /**
      * Creates a match.
-     * @param startOfSecond is the starting token index in the first submission.
+     * @param startOfFirst 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).
      */
@@ -35,6 +35,15 @@ public class Match {
         return startOfSecond;
     }
 
+    /**
+     * @param getFirst Whether to return the starting token index of the first submission,
+     *      else the starting token index of the second submission is returned.
+     * @return Start index of the requested submission.
+     */
+    public int getStart(boolean getFirst) {
+        return getFirst ? startOfFirst : startOfSecond;
+    }
+
     /**
      * @return the length of the similar sections, meaning the number of tokens.
      */

+ 6 - 6
jplag/src/main/java/de/jplag/reporting/Report.java

@@ -285,8 +285,8 @@ public class Report { // Mostly legacy code with some minor improvements.
         for (int x = 0; x < comparison.getMatches().size(); x++) {
             Match onematch = comparison.getMatches().get(x);
 
-            Token start = tokens.getToken(j == 0 ? onematch.getStartOfFirst() : onematch.getStartOfSecond());
-            Token end = tokens.getToken((j == 0 ? onematch.getStartOfFirst() : onematch.getStartOfSecond()) + onematch.getLength() - 1);
+            Token start = tokens.getToken(onematch.getStart(j == 0));
+            Token end = tokens.getToken((onematch.getStart(j == 0)) + 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\">" : "")
@@ -509,8 +509,8 @@ public class Report { // Mostly legacy code with some minor improvements.
                 if (onematch == null) {
                     if (index < comparison.getMatches().size()) {
                         onematch = comparison.getMatches().get(perm.get(index));
-                        start = tokens.getToken(j == 0 ? onematch.getStartOfFirst() : onematch.getStartOfSecond());
-                        end = tokens.getToken((j == 0 ? onematch.getStartOfFirst() : onematch.getStartOfSecond()) + onematch.getLength() - 1);
+                        start = tokens.getToken(onematch.getStart(j == 0));
+                        end = tokens.getToken((onematch.getStart(j == 0)) + onematch.getLength() - 1);
                         index++;
                     } else {
                         start = end = null;
@@ -696,8 +696,8 @@ public class Report { // Mostly legacy code with some minor improvements.
         for (int x = 0; x < comparison.getMatches().size(); x++) {
             currentMatch = comparison.getMatches().get(x);
 
-            Token start = tokens.getToken(j == 0 ? currentMatch.getStartOfFirst() : currentMatch.getStartOfSecond());
-            Token ende = tokens.getToken((j == 0 ? currentMatch.getStartOfFirst() : currentMatch.getStartOfSecond()) + currentMatch.getLength() - 1);
+            Token start = tokens.getToken(currentMatch.getStart(j == 0));
+            Token ende = tokens.getToken((currentMatch.getStart(j == 0)) + currentMatch.getLength() - 1);
 
             for (int y = 0; y < files.length; y++) {
                 if (start.file.equals(files[y]) && text[y] != null) {