public List < PlanNode > findAllFirstNodesAtOrBelow ( Type typeToFind ) { List < PlanNode > results = new LinkedList < PlanNode > ( ) ; LinkedList < PlanNode > queue = new LinkedList < PlanNode > ( ) ; queue . add ( this ) ; while ( ! queue . isEmpty ( ) ) { PlanNode aNode = queue . poll ( ) ; if ( aNode . getType ( ) == Type . PROJECT ) { results . add ( aNode ) ; } else { queue . addAll ( 0 , aNode . getChildren ( ) ) ; } } return results ; }
Look at nodes below this node searching for nodes that have the supplied type . As soon as a node with a matching type is found then no other nodes below it are searched .