Collection<MavenProject> (@NotNull Collection<MavenProject> mavenProjects) { var mavenProjectsToSkip = new HashSet<MavenProject>(); for (var mavenProject : mavenProjects) { var aggregator = mavenProject; while ((aggregator = findAggregator(aggregator)) != null) { if (mavenProjects.contains(aggregator)) { mavenProjectsToSkip.add(mavenProject); break; } } } return mavenProjects.stream().filter(mavenProject -> !mavenProjectsToSkip.contains(mavenProject)).toList(); }