List<MyNode> (final TreePath[] paths) { List<MyNode> nodes = ContainerUtil.mapNotNull(paths, path -> { Object node = path.getLastPathComponent(); return node instanceof MyNode ? (MyNode)node : null; }); MultiMap<RemoveConfigurableHandler, MyNode> grouped = groupNodes(nodes); List<MyNode> removedNodes = new ArrayList<>(); for (Map.Entry<RemoveConfigurableHandler, Collection<MyNode>> entry : grouped.entrySet()) { //noinspection unchecked boolean removed = entry.getKey().remove(getEditableObjects(entry.getValue())); if (removed) { removedNodes.addAll(entry.getValue()); } } return removedNodes; }