Replaced Tail Recursion while while/true loops. (#1019)

This commit is contained in:
Koen De Groote
2017-05-11 22:07:10 +12:00
committed by Rob Bygrave
parent 8cef603d1c
commit 951e517caf
8 changed files with 250 additions and 212 deletions
@@ -36,41 +36,43 @@ public final class DeployUpdateParser extends DeployParser {
}
private String convertSubword(int start, String currentWord, StringBuilder localBuffer) {
while (true) {
int dotPos = currentWord.indexOf('.', start);
if (start == 0 && dotPos == -1) {
return currentWord;
}
if (start == 0) {
localBuffer = new StringBuilder();
}
if (dotPos == -1) {
// no match...
localBuffer.append(currentWord.substring(start));
return localBuffer.toString();
}
int dotPos = currentWord.indexOf('.', start);
if (start == 0 && dotPos == -1) {
return currentWord;
}
if (start == 0) {
localBuffer = new StringBuilder();
}
if (dotPos == -1) {
// no match...
localBuffer.append(currentWord.substring(start));
return localBuffer.toString();
}
// append up to the dot
localBuffer.append(currentWord.substring(start, dotPos + 1));
// append up to the dot
localBuffer.append(currentWord.substring(start, dotPos + 1));
if (dotPos == currentWord.length() - 1) {
// ends with a "." ???
return localBuffer.toString();
}
if (dotPos == currentWord.length() - 1) {
// ends with a "." ???
return localBuffer.toString();
}
// get the remainder after the dot
start = dotPos + 1;
String remainder = currentWord.substring(start, currentWord.length());
// get the remainder after the dot
start = dotPos + 1;
String remainder = currentWord.substring(start, currentWord.length());
//String dbWord = deployMap.get(remainder.toLowerCase());
String dbWord = getDeployWord(remainder);
if (dbWord != null) {
// we have found a match for the remainder
localBuffer.append(dbWord);
return localBuffer.toString();
} else {
//
return convertSubword(start, currentWord, localBuffer);
//String dbWord = deployMap.get(remainder.toLowerCase());
String dbWord = getDeployWord(remainder);
if (dbWord != null) {
// we have found a match for the remainder
localBuffer.append(dbWord);
return localBuffer.toString();
} else {
//
}
}
}