void (@NotNull List<? extends AbstractTreeNode<TreeElement>> ungrouped, @NotNull Grouper grouper) { Map<TreeElement,AbstractTreeNode> ungroupedObjects = collectValues(ungrouped); Collection<Group> groups = grouper.group(this, ungroupedObjects.keySet()); Map<Group, GroupWrapper> groupNodes = createGroupNodes(groups); for (Group group : groups) { if (group == null) { LOG.error(grouper + " returned null group: "+groups); } GroupWrapper groupWrapper = groupNodes.get(group); Collection<TreeElement> children = group.getChildren(); for (TreeElement node : children) { if (node == null) { LOG.error(group + " returned null child: " + children); } CachingChildrenTreeNode child = createChildNode(node); groupWrapper.addSubElement(child); AbstractTreeNode abstractTreeNode = ungroupedObjects.get(node); abstractTreeNode.setParent(groupWrapper); } } }