TextRange (@NotNull List<? extends TextRange> textRanges) { if(textRanges.isEmpty()) return TextRange.EMPTY_RANGE; int lowerBound = textRanges.get(0).getStartOffset(); int upperBound = textRanges.get(0).getEndOffset(); for(int i = 1; i < textRanges.size(); ++i) { TextRange textRange = textRanges.get(i); lowerBound = Math.min(lowerBound, textRange.getStartOffset()); upperBound = Math.max(upperBound, textRange.getEndOffset()); } return new TextRange(lowerBound, upperBound); }