List<Range> (@NotNull List<? extends Range> ranges, @NotNull Range change) { if (ranges.isEmpty()) return singletonList(change); Range lastRange = ranges.get(ranges.size() - 1); if (lastRange.end1 == change.start1 && lastRange.end2 == change.start2) { Range mergedChange = new Range(lastRange.start1, change.end1, lastRange.start2, change.end2); return ContainerUtil.append(ranges.subList(0, ranges.size() - 1), mergedChange); } else { return ContainerUtil.append(ranges, change); } }