Skip to content

Commit

Permalink
Fixed a rare case when getting color for mid part would crash if 1 st…
Browse files Browse the repository at this point in the history
…ring was substring of another
  • Loading branch information
Arcidev committed May 19, 2017
1 parent f9f42ae commit 4d88a97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Parser/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ excludes=
file.reference.gson-2.2.2.jar=libraries/gson-2.2.2.jar
file.reference.lombok.jar=libraries\\lombok.jar
includes=**
jar.compress=false
jar.compress=true
javac.classpath=\
${file.reference.gson-2.2.2.jar}:\
${file.reference.lombok.jar}
Expand Down
15 changes: 11 additions & 4 deletions Parser/src/parser/output/data/OutputTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private Pair<Integer, Integer> longestCommonPrefixes(List<OutputMessage> msgs) {
int left = longestCommonPrefix(strings);
int right = longestCommonPrefix(invertedStrings);

return new Pair(left, right);
return Pair.of(left, right);
}

private void prepare(StringBuilder sb, int parentIdentifier, List<OutputMessage> msgs, boolean generateIdentifier) {
Expand Down Expand Up @@ -258,8 +258,12 @@ private int longestCommonPrefix(String[] strs) {

int end = minStr.length();
for (String str : strs) {
int j;
for (j = 0; end != 0 && j < end + 1; j += 3) {
if (str.equals(minStr)) {
continue;
}

int j = 0;
for (; end != 0 && j < end + 1; j += 3) {
if (minStr.charAt(j) != str.charAt(j) || minStr.charAt(j + 1) != str.charAt(j + 1)) {
break;
}
Expand Down Expand Up @@ -298,8 +302,11 @@ private String getColorForMidStream(List<OutputMessage> msgs, int leftIndex, int
}

String msg1 = msgs.get(i).message;
msg1 = msg1.length() > leftIndex + rightIndex + 1 ? msg1.substring(leftIndex, msg1.length() - rightIndex) : "";
String msg2 = msgs.get(j).message;
double currentRank = SimilarityTool.compareStrings(msg1.substring(leftIndex, msg1.length() - rightIndex), msg2.substring(leftIndex, msg2.length() - rightIndex));
msg2 = msg2.length() > leftIndex + rightIndex + 1 ? msg2.substring(leftIndex, msg2.length() - rightIndex) : "";

double currentRank = SimilarityTool.compareStrings(msg1, msg2);
int msgCount = msgs.get(i).getCount() * msgs.get(j).getCount();

similarityRank += currentRank * msgCount;
Expand Down

0 comments on commit 4d88a97

Please sign in to comment.