Explorar o código

Overhauled the GST algorithm and the Structure class. Remove complicated token access based on arrays. Remove re-implementations of array list.

Timur Sağlam %!s(int64=5) %!d(string=hai) anos
pai
achega
42b8c2101a

+ 33 - 29
jplag.frontend-utils/src/main/java/jplag/Structure.java

@@ -1,44 +1,48 @@
 package jplag;
 package jplag;
 
 
+import java.util.ArrayList;
+import java.util.List;
+
 /** The tokenlist */ // TODO PB: The name 'Structure' is very generic and should be changed to something more descriptive.
 /** The tokenlist */ // TODO PB: The name 'Structure' is very generic and should be changed to something more descriptive.
-public class Structure implements TokenConstants { // TODO TS: How about TokenList?
-    public Token[] tokens = new Token[0]; // TODO TS: An array list would allow us to remove the code in ensureCapacity()
+public class Structure implements TokenConstants { // TODO TS: How about renaming it to TokenList?
+    private final List<Token> tokens;
     Table table = null;
     Table table = null;
     int hash_length = -1;
     int hash_length = -1;
 
 
-    private int numberOfTokens;
-
     public Structure() {
     public Structure() {
-        tokens = new Token[400];
-        numberOfTokens = 0;
+        tokens = new ArrayList<>();
     }
     }
 
 
     public final int size() {
     public final int size() {
-        return numberOfTokens;
+        return tokens.size();
     }
     }
 
 
-   private final void ensureCapacity(int minCapacity) {
-        int oldCapacity = tokens.length;
-        if (minCapacity > oldCapacity) {
-            Token[] oldTokens = tokens;
-            int newCapacity = (2 * oldCapacity);
-            if (newCapacity < minCapacity) {
-                newCapacity = minCapacity;
+    public final void addToken(Token token) {
+        if (tokens.size() > 0) {
+            Token lastToken = tokens.get(tokens.size() - 1);
+            if (lastToken.file.equals(token.file)) {
+                token.file = lastToken.file; // To save memory ...
+            }
+            if (token.getLine() < lastToken.getLine() && (token.file.equals(lastToken.file))) {
+                token.setLine(lastToken.getLine()); // just to make sure
             }
             }
-            tokens = new Token[newCapacity];
-            System.arraycopy(oldTokens, 0, tokens, 0, numberOfTokens);
         }
         }
+        tokens.add(token);
     }
     }
 
 
-    public final void addToken(Token token) {
-        ensureCapacity(numberOfTokens + 1);
-        if (numberOfTokens > 0 && tokens[numberOfTokens - 1].file.equals(token.file))
-            token.file = tokens[numberOfTokens - 1].file; // To save memory ...
-        if ((numberOfTokens > 0) && (token.getLine() < tokens[numberOfTokens - 1].getLine()) && (token.file.equals(tokens[numberOfTokens - 1].file)))
-            token.setLine(tokens[numberOfTokens - 1].getLine());
-        // just to make sure
-
-        tokens[numberOfTokens++] = token;
+    public Iterable<Token> allTokens() {
+        return new ArrayList<>(tokens);
+    }
+
+    public Token getToken(int index) {
+        if (index < 0 || index >= tokens.size()) {
+            throw new IllegalArgumentException("Cannot access token with index " + index + ", there are only " + tokens.size() + " tokens!");
+        }
+        return tokens.get(index);
+    }
+
+    public Token[] getTokenArray() { // TODO TS: I added this to support the legacy code using arrays, however we should get rid of this.
+        return tokens.toArray(new Token[0]);
     }
     }
 
 
     @Override
     @Override
@@ -46,16 +50,16 @@ public class Structure implements TokenConstants { // TODO TS: How about TokenLi
         StringBuffer buffer = new StringBuffer();
         StringBuffer buffer = new StringBuffer();
 
 
         try {
         try {
-            for (int i = 0; i < numberOfTokens; i++) {
+            for (int i = 0; i < tokens.size(); i++) {
                 buffer.append(i);
                 buffer.append(i);
                 buffer.append("\t");
                 buffer.append("\t");
-                buffer.append(tokens[i].toString());
-                if (i < numberOfTokens - 1) {
+                buffer.append(tokens.get(i).toString());
+                if (i < tokens.size() - 1) {
                     buffer.append("\n");
                     buffer.append("\n");
                 }
                 }
             }
             }
         } catch (OutOfMemoryError e) {
         } catch (OutOfMemoryError e) {
-            return "Tokenlist to large for output: " + (numberOfTokens) + " Tokens";
+            return "Tokenlist to large for output: " + tokens.size() + " Tokens";
         }
         }
         return buffer.toString();
         return buffer.toString();
     }
     }

+ 1 - 1
jplag.frontend-utils/src/main/java/jplag/Table.java

@@ -11,7 +11,7 @@ import java.util.Map;
  * <code>(key % prime)</code> are mapped to the same values. Specifically, <code>prime</code> is the next prime number
  * <code>(key % prime)</code> are mapped to the same values. Specifically, <code>prime</code> is the next prime number
  * that is larger or equal to the specified size (see {@link Table#Table(int)}).
  * that is larger or equal to the specified size (see {@link Table#Table(int)}).
  */
  */
-public class Table { // TODO TS: I think this might map token hashes to token indices for the token array in the structure class
+public class Table { // TODO TS: I think this might map token hashes to token indices for the token array in the structure class (rename?)
     private final Map<Integer, ArrayList<Integer>> mappedEntries;
     private final Map<Integer, ArrayList<Integer>> mappedEntries;
     private final int primeNumber;
     private final int primeNumber;
 
 

+ 4 - 4
jplag.frontend.java-1.7/src/test/java/jplag/java17/ParserTest.java

@@ -271,11 +271,11 @@ public class ParserTest {
 	private String buildTokenString(jplag.Structure oldStruct, boolean withDetails) {
 	private String buildTokenString(jplag.Structure oldStruct, boolean withDetails) {
 		StringBuilder sb = new StringBuilder();
 		StringBuilder sb = new StringBuilder();
 		for (int i = 0; i < oldStruct.size(); i++) {
 		for (int i = 0; i < oldStruct.size(); i++) {
-			sb.append(jplag.java17.JavaToken.type2string(oldStruct.tokens[i].type));
+			sb.append(jplag.java17.JavaToken.type2string(oldStruct.getToken(i).type));
 			if (withDetails) {
 			if (withDetails) {
-				sb.append(" L:" + oldStruct.tokens[i].getLine()  
-				+ " C:" + oldStruct.tokens[i].getLine()
-				+ " l:" + oldStruct.tokens[i].getLine());
+				sb.append(" L:" + oldStruct.getToken(i).getLine()  
+				+ " C:" + oldStruct.getToken(i).getLine()
+				+ " l:" + oldStruct.getToken(i).getLine());
 			}
 			}
 			sb.append("\n");
 			sb.append("\n");
 		}
 		}

+ 93 - 110
jplag/src/main/java/jplag/GreedyStringTiling.java

@@ -21,11 +21,11 @@ public class GreedyStringTiling implements TokenConstants {
     /**
     /**
      * Creating hashes in linear time. The hash-code will be written in every Token for the next <hash_length> token
      * Creating hashes in linear time. The hash-code will be written in every Token for the next <hash_length> token
      * (includes the Token itself).
      * (includes the Token itself).
-     * @param structure contains the tokens.
+     * @param tokenList contains the tokens.
      * @param hashLength is the hash length (condition: 1 < hashLength < 26)
      * @param hashLength is the hash length (condition: 1 < hashLength < 26)
      * @param makeTable determines if a simple hash table is created in the structure.
      * @param makeTable determines if a simple hash table is created in the structure.
      */
      */
-    public void createHashes(Structure structure, int hashLength, boolean makeTable) {
+    public void createHashes(Structure tokenList, int hashLength, boolean makeTable) {
         // Here the upper boundary of the hash length is set.
         // Here the upper boundary of the hash length is set.
         // It is determined by the number of bits of the 'int' data type and the number of tokens.
         // It is determined by the number of bits of the 'int' data type and the number of tokens.
         if (hashLength < 1) {
         if (hashLength < 1) {
@@ -33,21 +33,21 @@ public class GreedyStringTiling implements TokenConstants {
         }
         }
         hashLength = (hashLength < 26 ? hashLength : 25);
         hashLength = (hashLength < 26 ? hashLength : 25);
 
 
-        if (structure.size() < hashLength) {
+        if (tokenList.size() < hashLength) {
             return;
             return;
         }
         }
 
 
         int modulo = ((1 << 6) - 1);   // Modulo 64!
         int modulo = ((1 << 6) - 1);   // Modulo 64!
 
 
-        int loops = structure.size() - hashLength;
-        structure.table = (makeTable ? new Table(3 * loops) : null);
+        int loops = tokenList.size() - hashLength;
+        tokenList.table = (makeTable ? new Table(3 * loops) : null);
         int hash = 0;
         int hash = 0;
         int i;
         int i;
         int hashedLength = 0;
         int hashedLength = 0;
         for (i = 0; i < hashLength; i++) {
         for (i = 0; i < hashLength; i++) {
-            hash = (2 * hash) + (structure.tokens[i].type & modulo);
+            hash = (2 * hash) + (tokenList.getToken(i).type & modulo);
             hashedLength++;
             hashedLength++;
-            if (structure.tokens[i].marked) {
+            if (tokenList.getToken(i).marked) {
                 hashedLength = 0;
                 hashedLength = 0;
             }
             }
         }
         }
@@ -56,14 +56,14 @@ public class GreedyStringTiling implements TokenConstants {
         if (makeTable) {
         if (makeTable) {
             for (i = 0; i < loops; i++) {
             for (i = 0; i < loops; i++) {
                 if (hashedLength >= hashLength) {
                 if (hashedLength >= hashLength) {
-                    structure.tokens[i].hash = hash;
-                    structure.table.add(hash, i);   // add into hashtable
+                    tokenList.getToken(i).hash = hash;
+                    tokenList.table.add(hash, i);   // add into hashtable
                 } else {
                 } else {
-                    structure.tokens[i].hash = -1;
+                    tokenList.getToken(i).hash = -1;
                 }
                 }
-                hash -= factor * (structure.tokens[i].type & modulo);
-                hash = (2 * hash) + (structure.tokens[i + hashLength].type & modulo);
-                if (structure.tokens[i + hashLength].marked) {
+                hash -= factor * (tokenList.getToken(i).type & modulo);
+                hash = (2 * hash) + (tokenList.getToken(i + hashLength).type & modulo);
+                if (tokenList.getToken(i + hashLength).marked) {
                     hashedLength = 0;
                     hashedLength = 0;
                 } else {
                 } else {
                     hashedLength++;
                     hashedLength++;
@@ -71,110 +71,97 @@ public class GreedyStringTiling implements TokenConstants {
             }
             }
         } else {
         } else {
             for (i = 0; i < loops; i++) {
             for (i = 0; i < loops; i++) {
-                structure.tokens[i].hash = (hashedLength >= hashLength) ? hash : -1;
-                hash -= factor * (structure.tokens[i].type & modulo);
-                hash = (2 * hash) + (structure.tokens[i + hashLength].type & modulo);
-                if (structure.tokens[i + hashLength].marked) {
+                tokenList.getToken(i).hash = (hashedLength >= hashLength) ? hash : -1;
+                hash -= factor * (tokenList.getToken(i).type & modulo);
+                hash = (2 * hash) + (tokenList.getToken(i + hashLength).type & modulo);
+                if (tokenList.getToken(i + hashLength).marked) {
                     hashedLength = 0;
                     hashedLength = 0;
                 } else {
                 } else {
                     hashedLength++;
                     hashedLength++;
                 }
                 }
             }
             }
         }
         }
-        structure.hash_length = hashLength;
+        tokenList.hash_length = hashLength;
     }
     }
 
 
-    public final JPlagComparison compare(Submission first, Submission second) {
+    public final JPlagComparison compare(Submission firstSubmission, Submission secondSubmission) {
         Submission smallerSubmission, largerSubmission;
         Submission smallerSubmission, largerSubmission;
-        if (first.tokenList.size() > second.tokenList.size()) {
-            smallerSubmission = second;
-            largerSubmission = first;
+        if (firstSubmission.tokenList.size() > secondSubmission.tokenList.size()) {
+            smallerSubmission = secondSubmission;
+            largerSubmission = firstSubmission;
         } else {
         } else {
-            smallerSubmission = first;
-            largerSubmission = second;
+            smallerSubmission = firstSubmission;
+            largerSubmission = secondSubmission;
         }
         }
         // if hashtable exists in first but not in second structure: flip around!
         // if hashtable exists in first but not in second structure: flip around!
         if (largerSubmission.tokenList.table == null && smallerSubmission.tokenList.table != null) {
         if (largerSubmission.tokenList.table == null && smallerSubmission.tokenList.table != null) {
-            Submission tmp = smallerSubmission;
+            Submission swap = smallerSubmission;
             smallerSubmission = largerSubmission;
             smallerSubmission = largerSubmission;
-            largerSubmission = tmp;
+            largerSubmission = swap;
         }
         }
 
 
         return compare(smallerSubmission, largerSubmission, this.program.getOptions().getMinTokenMatch());
         return compare(smallerSubmission, largerSubmission, this.program.getOptions().getMinTokenMatch());
     }
     }
- 
+
     /**
     /**
      * first parameter should contain the smaller sequence!!!
      * first parameter should contain the smaller sequence!!!
      */
      */
-    private final JPlagComparison compare(Submission submissionA, Submission submissionB, int minimalTokenMatch) {
-        Structure structA = submissionA.tokenList;
-        Structure structB = submissionB.tokenList;
+    private final JPlagComparison compare(Submission firstSubmission, Submission secondSubmission, int minimalTokenMatch) {
+        Structure first = firstSubmission.tokenList;
+        Structure second = secondSubmission.tokenList;
 
 
         // FILE_END used as pivot
         // FILE_END used as pivot
 
 
-        // init
-        Token[] A = structA.tokens;
-        Token[] B = structB.tokens;
-        int lengthA = structA.size() - 1;  // minus pivots!
-        int lengthB = structB.size() - 1;  // minus pivots!
-        JPlagComparison comparison = new JPlagComparison(submissionA, submissionB);
+        // Initialize:
+        JPlagComparison comparison = new JPlagComparison(firstSubmission, secondSubmission);
 
 
-        if (lengthA < minimalTokenMatch || lengthB < minimalTokenMatch) {
+        if (first.size() <= minimalTokenMatch || second.size() <= minimalTokenMatch) { // <= because of pivots!
             return comparison;
             return comparison;
         }
         }
 
 
-        // Initialize
-        if (!program.getOptions().hasBaseCode()) {
-            for (int i = 0; i <= lengthA; i++) {
-                A[i].marked = A[i].type == FILE_END || A[i].type == SEPARATOR_TOKEN;
-            }
-
-            for (int i = 0; i <= lengthB; i++) {
-                B[i].marked = B[i].type == FILE_END || B[i].type == SEPARATOR_TOKEN;
-            }
-        } else {
-            for (int i = 0; i <= lengthA; i++) {
-                A[i].marked = A[i].type == FILE_END || A[i].type == SEPARATOR_TOKEN || A[i].basecode;
-            }
-
-            for (int i = 0; i <= lengthB; i++) {
-                B[i].marked = B[i].type == FILE_END || B[i].type == SEPARATOR_TOKEN || B[i].basecode;
-            }
+        // Mark tokens:
+        for (Token token : first.allTokens()) {
+            token.marked = token.type == FILE_END || token.type == SEPARATOR_TOKEN || (token.basecode && program.getOptions().hasBaseCode());
+        }
+        for (Token token : second.allTokens()) {
+            token.marked = token.type == FILE_END || token.type == SEPARATOR_TOKEN || (token.basecode && program.getOptions().hasBaseCode());
         }
         }
 
 
-        // start:
-        if (structA.hash_length != minimalTokenMatch) {
-            createHashes(structA, minimalTokenMatch, false);
+        // create hashes:
+        if (first.hash_length != minimalTokenMatch) {
+            createHashes(first, minimalTokenMatch, false);
         }
         }
-        if (structB.hash_length != minimalTokenMatch || structB.table == null) {
-            createHashes(structB, minimalTokenMatch, true);
+        if (second.hash_length != minimalTokenMatch || second.table == null) {
+            createHashes(second, minimalTokenMatch, true);
         }
         }
 
 
+        // start
         int maxmatch;
         int maxmatch;
-        List<Integer> elementsB;
-
         do {
         do {
             maxmatch = minimalTokenMatch;
             maxmatch = minimalTokenMatch;
             matches.clear();
             matches.clear();
-            for (int x = 0; x <= lengthA - maxmatch; x++) {
-                if (A[x].marked || A[x].hash == -1 || (elementsB = structB.table.get(A[x].hash)) == null) {
+            for (int x = 0; x < first.size() - maxmatch; x++) {
+                List<Integer> elementsOfSecond = second.table.get(first.getToken(x).hash);
+                if (first.getToken(x).marked || first.getToken(x).hash == -1 || elementsOfSecond == null) {
                     continue;
                     continue;
                 }
                 }
-                inner: for (Integer y : elementsB) {
-                    if (B[y].marked || maxmatch > lengthB - y) {
+                inner: for (Integer y : elementsOfSecond) {
+                    if (second.getToken(y).marked || maxmatch >= second.size() - y) { // <= because of pivots!
                         continue;
                         continue;
                     }
                     }
 
 
                     int j, hx, hy;
                     int j, hx, hy;
                     for (j = maxmatch - 1; j >= 0; j--) { // begins comparison from behind
                     for (j = maxmatch - 1; j >= 0; j--) { // begins comparison from behind
-                        if (A[hx = x + j].type != B[hy = y + j].type || A[hx].marked || B[hy].marked) {
+                        if (first.getToken(hx = x + j).type != second.getToken(hy = y + j).type || first.getToken(hx).marked
+                                || second.getToken(hy).marked) {
                             continue inner;
                             continue inner;
                         }
                         }
                     }
                     }
 
 
                     // expand match
                     // expand match
                     j = maxmatch;
                     j = maxmatch;
-                    while (A[hx = x + j].type == B[hy = y + j].type && !A[hx].marked && !B[hy].marked) {
+                    while (first.getToken(hx = x + j).type == second.getToken(hy = y + j).type && !first.getToken(hx).marked
+                            && !second.getToken(hy).marked) {
                         j++;
                         j++;
                     }
                     }
 
 
@@ -191,7 +178,7 @@ public class GreedyStringTiling implements TokenConstants {
                 comparison.addMatch(x, y, matches.matches[i].length);
                 comparison.addMatch(x, y, matches.matches[i].length);
                 // in order that "Match" will be newly build (because reusing)
                 // in order that "Match" will be newly build (because reusing)
                 for (int j = matches.matches[i].length; j > 0; j--) {
                 for (int j = matches.matches[i].length; j > 0; j--) {
-                    A[x++].marked = B[y++].marked = true;   // mark all Token!
+                    first.getToken(x++).marked = second.getToken(y++).marked = true; // mark all Token!
                 }
                 }
             }
             }
 
 
@@ -200,83 +187,80 @@ public class GreedyStringTiling implements TokenConstants {
         return comparison;
         return comparison;
     }
     }
 
 
-    public final JPlagBaseCodeComparison compareWithBaseCode(Submission first, Submission second) {
+    public final JPlagBaseCodeComparison compareWithBaseCode(Submission firstSubmission, Submission secondSubmission) {
         Submission smallerSubmission, largerSubmission;
         Submission smallerSubmission, largerSubmission;
-        if (first.tokenList.size() > second.tokenList.size()) {
-            smallerSubmission = second;
-            largerSubmission = first;
+        if (firstSubmission.tokenList.size() > secondSubmission.tokenList.size()) {
+            smallerSubmission = secondSubmission;
+            largerSubmission = firstSubmission;
         } else {
         } else {
-            smallerSubmission = second;
-            largerSubmission = first;
+            smallerSubmission = firstSubmission;
+            largerSubmission = secondSubmission;
         }
         }
         // if hashtable exists in first but not in second structure: flip around!
         // if hashtable exists in first but not in second structure: flip around!
         if (largerSubmission.tokenList.table == null && smallerSubmission.tokenList.table != null) {
         if (largerSubmission.tokenList.table == null && smallerSubmission.tokenList.table != null) {
-            Submission tmp = smallerSubmission;
+            Submission swap = smallerSubmission;
             smallerSubmission = largerSubmission;
             smallerSubmission = largerSubmission;
-            largerSubmission = tmp;
+            largerSubmission = swap;
         }
         }
 
 
         return compareWithBaseCode(smallerSubmission, largerSubmission, this.program.getOptions().getMinTokenMatch());
         return compareWithBaseCode(smallerSubmission, largerSubmission, this.program.getOptions().getMinTokenMatch());
     }
     }
 
 
-    private JPlagBaseCodeComparison compareWithBaseCode(Submission subA, Submission subB, int minimalTokenMatch) {
-        Structure structA = subA.tokenList;
-        Structure structB = subB.tokenList;
+    private JPlagBaseCodeComparison compareWithBaseCode(Submission firstSubmission, Submission secondSubmission, int minimalTokenMatch) {
+        Structure first = firstSubmission.tokenList;
+        Structure second = secondSubmission.tokenList;
 
 
         // FILE_END used as pivot
         // FILE_END used as pivot
 
 
-        // init
-        Token[] A = structA.tokens;
-        Token[] B = structB.tokens;
-        int lengthA = structA.size() - 1;  // minus pivots!
-        int lengthB = structB.size() - 1;  // minus pivots!
-        JPlagBaseCodeComparison baseCodeComparison = new JPlagBaseCodeComparison(subA, subB);
+        // Initialize:
+        JPlagBaseCodeComparison baseCodeComparison = new JPlagBaseCodeComparison(firstSubmission, secondSubmission);
 
 
-        if (lengthA < minimalTokenMatch || lengthB < minimalTokenMatch) {
+        if (first.size() - 1 < minimalTokenMatch || second.size() - 1 < minimalTokenMatch) { // -1 for pivot
             return baseCodeComparison;
             return baseCodeComparison;
         }
         }
 
 
-        // Initialize
-        for (int i = 0; i <= lengthA; i++) {
-            A[i].marked = A[i].type == FILE_END || A[i].type == SEPARATOR_TOKEN;
+        // Mark tokens:
+        for (Token token : first.allTokens()) {
+            token.marked = token.type == FILE_END || token.type == SEPARATOR_TOKEN;
         }
         }
-
-        for (int i = 0; i <= lengthB; i++) {
-            B[i].marked = B[i].type == FILE_END || B[i].type == SEPARATOR_TOKEN;
+        for (Token token : second.allTokens()) {
+            token.marked = token.type == FILE_END || token.type == SEPARATOR_TOKEN;
         }
         }
 
 
-        // start:
-        if (structA.hash_length != minimalTokenMatch) {
-            createHashes(structA, minimalTokenMatch, true);
+        // create hashes:
+        if (first.hash_length != minimalTokenMatch) {
+            createHashes(first, minimalTokenMatch, true);
         }
         }
-        if (structB.hash_length != minimalTokenMatch || structB.table == null) {
-            createHashes(structB, minimalTokenMatch, true);
+        if (second.hash_length != minimalTokenMatch || second.table == null) {
+            createHashes(second, minimalTokenMatch, true);
         }
         }
 
 
+        // start:
         int maxmatch;
         int maxmatch;
-        List<Integer> elementsB;
-
         do {
         do {
             maxmatch = minimalTokenMatch;
             maxmatch = minimalTokenMatch;
             matches.clear();
             matches.clear();
-            for (int x = 0; x <= lengthA - maxmatch; x++) {
-                if (A[x].marked || A[x].hash == -1 || (elementsB = structB.table.get(A[x].hash)) == null) {
+            for (int x = 0; x < first.size() - maxmatch; x++) { // -1 for pivot
+                List<Integer> elementsOfSecond = second.table.get(first.getToken(x).hash);
+                if (first.getToken(x).marked || first.getToken(x).hash == -1 || elementsOfSecond == null) {
                     continue;
                     continue;
                 }
                 }
-                inner: for (Integer y : elementsB) {
-                    if (B[y].marked || maxmatch > lengthB - y) {
+                inner: for (Integer y : elementsOfSecond) {
+                    if (second.getToken(y).marked || maxmatch > second.size() - 1 - y) { // -1 for pivot
                         continue;
                         continue;
                     }
                     }
 
 
                     int j, hx, hy;
                     int j, hx, hy;
                     for (j = maxmatch - 1; j >= 0; j--) { // begins comparison from behind
                     for (j = maxmatch - 1; j >= 0; j--) { // begins comparison from behind
-                        if (A[hx = x + j].type != B[hy = y + j].type || A[hx].marked || B[hy].marked) {
+                        if (first.getToken(hx = x + j).type != second.getToken(hy = y + j).type || first.getToken(hx).marked
+                                || second.getToken(hy).marked) {
                             continue inner;
                             continue inner;
                         }
                         }
                     }
                     }
                     // expand match
                     // expand match
                     j = maxmatch;
                     j = maxmatch;
-                    while (A[hx = x + j].type == B[hy = y + j].type && !A[hx].marked && !B[hy].marked) {
+                    while (first.getToken(hx = x + j).type == second.getToken(hy = y + j).type && !first.getToken(hx).marked
+                            && !second.getToken(hy).marked) {
                         j++;
                         j++;
                     }
                     }
 
 
@@ -293,8 +277,8 @@ public class GreedyStringTiling implements TokenConstants {
                 baseCodeComparison.addMatch(x, y, matches.matches[i].length);
                 baseCodeComparison.addMatch(x, y, matches.matches[i].length);
                 // in order that "Match" will be newly build (because reusing)
                 // in order that "Match" will be newly build (because reusing)
                 for (int j = matches.matches[i].length; j > 0; j--) {
                 for (int j = matches.matches[i].length; j > 0; j--) {
-                    A[x].marked = B[y].marked = true;   // mark all Token!
-                    A[x].basecode = B[y].basecode = true;
+                    first.getToken(x).marked = second.getToken(y).marked = true;   // mark all Token!
+                    first.getToken(x).basecode = second.getToken(y).basecode = true;
                     x++;
                     x++;
                     y++;
                     y++;
                 }
                 }
@@ -305,9 +289,8 @@ public class GreedyStringTiling implements TokenConstants {
     }
     }
 
 
     public void resetBaseSubmission(Submission submission) {
     public void resetBaseSubmission(Submission submission) {
-        Token[] tokens = submission.tokenList.tokens;
-        for (int i = 0; i < submission.tokenList.size() - 1; i++) {
-            tokens[i].basecode = false;
+        for (Token token : submission.tokenList.allTokens()) {
+            token.basecode = false;
         }
         }
     }
     }
 }
 }

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

@@ -184,7 +184,7 @@ public class JPlagComparison implements Comparator<JPlagComparison> {
             return new String[] {};
             return new String[] {};
         }
         }
 
 
-        Token[] tokens = (j == 0 ? firstSubmission : secondSubmission).tokenList.tokens;
+        Token[] tokens = (j == 0 ? firstSubmission : secondSubmission).tokenList.getTokenArray();
         int i, h, starti, starth, count = 1;
         int i, h, starti, starth, count = 1;
 
 
         o1: for (i = 1; i < matches.size(); i++) {
         o1: for (i = 1; i < matches.size(); i++) {

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

@@ -389,8 +389,8 @@ public class Report {
      */
      */
     private void reportComparison(HTMLFile htmlFile, JPlagComparison comparison, int index) {
     private void reportComparison(HTMLFile htmlFile, JPlagComparison comparison, int index) {
         Match match;
         Match match;
-        Token[] tokensA = comparison.firstSubmission.tokenList.tokens;
-        Token[] tokensB = comparison.secondSubmission.tokenList.tokens;
+        Token[] tokensA = comparison.firstSubmission.tokenList.getTokenArray();
+        Token[] tokensB = comparison.secondSubmission.tokenList.getTokenArray();
         // sort();
         // sort();
 
 
         htmlFile.println("<TABLE BORDER=\"1\" CELLSPACING=\"0\" BGCOLOR=\"#d0d0d0\">");
         htmlFile.println("<TABLE BORDER=\"1\" CELLSPACING=\"0\" BGCOLOR=\"#d0d0d0\">");
@@ -452,7 +452,7 @@ public class Report {
 
 
         String[][] text = sub.readFiles(files);
         String[][] text = sub.readFiles(files);
 
 
-        Token[] tokens = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission).tokenList.tokens;
+        Token[] tokens = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission).tokenList.getTokenArray();
         Match currentMatch;
         Match currentMatch;
         String hilf;
         String hilf;
         int h;
         int h;
@@ -556,7 +556,7 @@ public class Report {
         Submission sub = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission);
         Submission sub = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission);
         String[] files = comparison.files(j);
         String[] files = comparison.files(j);
         char[][] text = sub.readFilesChar(files);
         char[][] text = sub.readFilesChar(files);
-        Token[] tokens = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission).tokenList.tokens;
+        Token[] tokens = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission).tokenList.getTokenArray();
 
 
         // get index array with matches sorted in ascending order.
         // get index array with matches sorted in ascending order.
         int[] perm = comparison.sort_permutation(j);
         int[] perm = comparison.sort_permutation(j);
@@ -629,7 +629,7 @@ public class Report {
         Submission sub = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission);
         Submission sub = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission);
         String[] files = comparison.files(j);
         String[] files = comparison.files(j);
         String[][] text = sub.readFiles(files);
         String[][] text = sub.readFiles(files);
-        Token[] tokens = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission).tokenList.tokens;
+        Token[] tokens = (j == 0 ? comparison.firstSubmission : comparison.secondSubmission).tokenList.getTokenArray();
 
 
         // Markup list:
         // Markup list:
         Comparator<MarkupText> comp = (mo1, mo2) -> {
         Comparator<MarkupText> comp = (mo1, mo2) -> {