void (String hostText, String newText, String[] result, int i, int j) { synchronized (myLock) { String rangeText1 = getRangeText(hostText, i); if (i == j) { result[i] = rangeText1.equals(newText) ? null : newText; return; } if (StringUtil.startsWith(newText, rangeText1)) { result[i] = null; //no change calculateMinEditSequence(hostText, newText.substring(rangeText1.length()), result, i+1, j); return; } String rangeText2 = getRangeText(hostText, j); if (StringUtil.endsWith(newText, rangeText2)) { result[j] = null; //no change calculateMinEditSequence(hostText, newText.substring(0, newText.length() - rangeText2.length()), result, i, j-1); return; } if (i+1 == j) { String suffix = myShreds.get(i).getSuffix(); String prefix = myShreds.get(j).getPrefix(); String separator = suffix + prefix; if (!separator.isEmpty()) { int sep = newText.indexOf(separator); assert sep != -1; result[i] = newText.substring(0, sep + suffix.length()); result[j] = newText.substring(sep + suffix.length() + prefix.length()); return; } String commonPrefix = StringUtil.commonPrefix(rangeText1, newText); result[i] = commonPrefix; result[j] = newText.substring(commonPrefix.length()); return; } String middleText = getRangeText(hostText, i + 1); int m = newText.indexOf(middleText); if (m != -1) { result[i] = newText.substring(0, m); result[i+1] = null; calculateMinEditSequence(hostText, newText.substring(m+middleText.length()), result, i + 2, j); return; } middleText = getRangeText(hostText, j - 1); m = newText.lastIndexOf(middleText); if (m != -1) { result[j] = newText.substring(m+middleText.length()); result[j-1] = null; calculateMinEditSequence(hostText, newText.substring(0, m), result, i, j-2); return; } result[i] = ""; result[j] = ""; calculateMinEditSequence(hostText, newText, result, i+1, j-1); } }