Set<TextRange> (Set<? extends TextRange> allRanges) { Set<TextRange> filtered = new LinkedHashSet<>(allRanges.size()); for (TextRange outer : allRanges) { boolean contains = anyRangeContains(allRanges, outer); if (!contains) filtered.add(outer); } return filtered; }