Set<Object> (Collection elements) { Set<Object> target = new HashSet<>(); if (elements != null) { for (Object each : elements) { final Object node = ((TreePath)each).getLastPathComponent(); if (node instanceof DefaultMutableTreeNode) { final Object descriptor = ((DefaultMutableTreeNode)node).getUserObject(); if (descriptor instanceof NodeDescriptor) { final Object element = myUi.getElementFromDescriptor((NodeDescriptor)descriptor); if (element != null) { target.add(element); } } } } } return target; }