Fragment (@NotNull Fragment next) { int newStartOffset = Math.min(offset, next.offset); int newOrigEndOffset = Math.max(offset + oldLength, adjustBackward(next.offset + next.oldLength)); int newUpdatedEndOffset = Math.max(next.adjustForward(offset + newLength), next.offset + next.newLength); return new Fragment(newStartOffset, newOrigEndOffset - newStartOffset, newUpdatedEndOffset - newStartOffset); }