public static void sort ( BaseComponent parent , boolean recurse ) { if ( parent == null || parent . getChildren ( ) . size ( ) < 2 ) { return ; } int i = 1 ; int size = parent . getChildren ( ) . size ( ) ; while ( i < size ) { Treenode item1 = ( Treenode ) parent . getChildren ( ) . get ( i - 1 ) ; Treenode item2 = ( Treenode ) parent . getChildren ( ) . get ( i ) ; if ( compare ( item1 , item2 ) > 0 ) { parent . swapChildren ( i - 1 , i ) ; i = i == 1 ? 2 : i - 1 ; } else { i ++ ; } } if ( recurse ) { for ( BaseComponent child : parent . getChildren ( ) ) { sort ( child , recurse ) ; } } }
Alphabetically sorts children under the specified parent .