/** * Returns a copy of the tree starting at the given node. * * @param tree The tree to copy (may be {@code null}). * @return A mutable copy of the given tree, or {@code null} if the tree was null. * @todo Use {@code getUserObject} when we can. * @since 2.5 */ public static MutableTreeNode copy(final TreeNode node) { if (node == null) { return null; } final DefaultMutableTreeNode target = new DefaultMutableTreeNode(node.toString(), node.getAllowsChildren()); final Enumeration children = node.children(); if (children != null) { while (children.hasMoreElements()) { final TreeNode child = (TreeNode) children.nextElement(); target.add(copy(child)); } } return target; }