List<String> (@NotNull Collection<String> paths, boolean caseSensitive) { List<String> sortedPaths = new ArrayList<>(paths); sortedPaths.sort(null); String prevPath = null; Iterator<String> it = sortedPaths.iterator(); while (it.hasNext()) { String path = it.next(); if (prevPath != null && FileUtil.startsWith(path, prevPath, caseSensitive)) { it.remove(); } else { prevPath = path; } } return sortedPaths; }