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