Set<ShelvedChangeList> (@NotNull ChangesTree tree, @NotNull Predicate<? super ShelvedChangeList> condition) { TreePath[] selectionPaths = tree.getSelectionPaths(); if (selectionPaths == null) return Collections.emptySet(); return StreamEx.of(selectionPaths) .map(path -> TreeUtil.findObjectInPath(path, ShelvedChangeList.class)) .filter(nonNull()) .filter(condition) .collect(Collectors.toSet()); }