/** * Sorts children of a node using a comparator * * @param node Node instance whose children to be sorted * @param comparator Comparator to use in sorting */ public static void sortNode(TreeNode node, Comparator comparator) { TreeNodeList children = (TreeNodeList) node.getChildren(); if (children != null && !children.isEmpty()) { Object[] childrenArray = children.toArray(); Arrays.sort(childrenArray, comparator); for (int i = 0; i < childrenArray.length; i++) { children.setSibling(i, (TreeNode) childrenArray[i]); } for (int i = 0; i < children.size(); i++) { sortNode(children.get(i), comparator); } } } }
/** * Sorts children of a node using a comparator * * @param node Node instance whose children to be sorted * @param comparator Comparator to use in sorting */ public static void sortNode(TreeNode node, Comparator comparator) { TreeNodeList children = (TreeNodeList) node.getChildren(); if (children != null && !children.isEmpty()) { Object[] childrenArray = children.toArray(); Arrays.sort(childrenArray, comparator); for (int i = 0; i < childrenArray.length; i++) { children.setSibling(i, (TreeNode) childrenArray[i]); } for (int i = 0; i < children.size(); i++) { sortNode(children.get(i), comparator); } } } }