void (int startIndex, int endIndex, @NotNull SegmentArrayWithData newData) { int oldLen = endIndex - startIndex; int newLen = newData.getSegmentCount(); int delta = newLen - oldLen; if (delta < 0) { remove(endIndex + delta, endIndex); } else if (delta > 0) { SegmentArrayWithData deltaData = new SegmentArrayWithData(myStorage.createStorage()); for (int i = oldLen; i < newLen; i++) { deltaData.setElementAt(i - oldLen, newData.getSegmentStart(i), newData.getSegmentEnd(i), newData.getSegmentData(i)); } insert(deltaData, startIndex + oldLen); } int common = Math.min(newLen, oldLen); replace(startIndex, newData, common); }