private void cleanUpHistoryTree ( HistoryNode node ) { if ( node == null || node . children == null ) { return ; } Iterator < HistoryNode > iterator = node . children . iterator ( ) ; while ( iterator . hasNext ( ) ) { HistoryNode child = iterator . next ( ) ; // clean up child cleanUpHistoryTree ( child ) ; // clean up current node; if ( shouldRemoveNode ( child ) ) { iterator . remove ( ) ; } } }
Clean up the Tree by DFS traversal .