Set<Integer> (@NotNull Collection<? extends CommitId> heads) { Set<Integer> result = new HashSet<>(); for (int id = 0; id < myLinearGraph.nodesCount(); id++) { if (heads.contains(myFunction.apply(id))) { result.add(id); } } return result; }