StringBuilder (CharSequence chars) { StringBuilder stringBuilder = new StringBuilder(chars); int shift = 0; for (TextRange outerElementRange : myOuterAndRemoveRanges) { if (outerElementRange instanceof RangeToRemove) { CharSequence textToRemove = ((RangeToRemove)outerElementRange).myTextToRemove; if (textToRemove != null) { stringBuilder.insert(outerElementRange.getStartOffset() + shift, textToRemove); shift += textToRemove.length(); } } else { stringBuilder.delete(outerElementRange.getStartOffset() + shift, outerElementRange.getEndOffset() + shift); shift -= outerElementRange.getLength(); } } return stringBuilder; }