public static void visitPreOrder ( Node node , Visitor visitor , Predicate < Node > traverseChildrenPred ) { visitor . visit ( node ) ; if ( traverseChildrenPred . apply ( node ) ) { for ( Node c = node . getFirstChild ( ) ; c != null ; c = c . getNext ( ) ) { visitPreOrder ( c , visitor , traverseChildrenPred ) ; } } }
A pre - order traversal calling Visitor . visit for each child matching the predicate .