List<Configurable> (Map<String, Node<HierarchicalConfigurable>> tree, Node<HierarchicalConfigurable> node) { if (node.myChildren == null) { if (node.myValue == null) { // for group only return new ArrayList<>(); } return null; } List<Configurable> list = new ArrayList<>(node.myChildren.size()); for (Iterator<Object> iterator = node.myChildren.iterator(); iterator.hasNext(); iterator.remove()) { Object child = iterator.next(); if (child instanceof Configurable) { list.add((Configurable)child); } else { @SuppressWarnings("unchecked") // expected type Node<HierarchicalConfigurable> value = (Node<HierarchicalConfigurable>)child; if (getConfigurables(tree, value) != null) { throw new IllegalStateException("unexpected algorithm state"); } list.add(value.myValue); tree.remove(value.myValue.getId()); } } if (node.myValue == null) { return list; // for group only } for (Configurable configurable : list) { node.myValue = node.myValue.addChild(configurable); } return null; }