List<String> (@NotNull Collection<? extends HgRepository> repositories, boolean bookmarkType) { Collection<String> common = null; for (HgRepository repository : repositories) { Collection<String> names = bookmarkType ? HgUtil.getSortedNamesWithoutHashes(repository.getBookmarks()) : repository.getOpenedBranches(); common = common == null ? names : ContainerUtil.intersection(common, names); } return common != null ? StreamEx.of(common).sorted(StringUtil::naturalCompare).toList() : Collections.emptyList(); }