/** * Generic traversal, without evaluator. * * @param node The initial node. Must not be null. * @param method The traversal method. Must not be null. * @param order The traversal order. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. */ public void traverse(N node, TraversalMethod method, TraversalOrder order, EdgeDirection direction, Visitor<N> visitor) { traverse(node, method, order, direction, visitor, null); }
/** * Breadth first post order traversal without evaluator. * * @param node The initial node. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. */ public void traverseBreadthFirstPost(N node, EdgeDirection direction, Visitor<N> visitor) { traverseBreadthFirst(node, TraversalOrder.POST_ORDER, direction, visitor, null); }
/** * Depth first pre order traversal without evaluator. * * @param node The initial node. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. */ public void traverseDepthFirstPre(N node, EdgeDirection direction, Visitor<N> visitor) { traverseDepthFirst(node, TraversalOrder.PRE_ORDER, direction, visitor, null); }
/** * Most generic traversal function. * * @param node The initial node. Must not be null. * @param method The traversal method. Must not be null. * @param order The traversal order. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. Must not be null. * @param evaluator An optional evaluator used to control traversal * termination. */ public void traverse(N node, TraversalMethod method, TraversalOrder order, EdgeDirection direction, Visitor<N> visitor, Evaluator<N> evaluator) { Checks.isNotNull(node, "node"); Checks.isNotNull(method, "method"); Checks.isNotNull(order, "order"); Checks.isNotNull(direction, "direction"); Checks.isNotNull(visitor, "visitor"); if (method == TraversalMethod.BREADTH_FIRST) { traverseBreadthFirst(node, order, direction, visitor, evaluator); } else { traverseDepthFirst(node, order, direction, visitor, evaluator); } }
private void test(List<TestTreeNode> expected, TestTreeNode start, TraversalMethod method, TraversalOrder order, EdgeDirection direction) { final List<TestTreeNode> visited = new ArrayList<>(); traverser.traverse(start, method, order, direction, n -> visited.add(n)); assertEquals(expected, visited); }
/** * Breadth first pre order traversal without evaluator. * * @param node The initial node. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. */ public void traverseBreadthFirstPre(N node, EdgeDirection direction, Visitor<N> visitor) { traverseBreadthFirst(node, TraversalOrder.PRE_ORDER, direction, visitor, null); }
/** * Depth first post order traversal without evaluator. * * @param node The initial node. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. */ public void traverseDepthFirstPost(N node, EdgeDirection direction, Visitor<N> visitor) { traverseDepthFirst(node, TraversalOrder.POST_ORDER, direction, visitor, null); }
private void test(List<TestTreeNode> expected, TestTreeNode start, TestTreeNode stop, TraversalMethod method, TraversalOrder order, EdgeDirection direction) { final List<TestTreeNode> visited = new ArrayList<>(); traverser.traverse(start, method, order, direction, n -> visited.add(n), n -> n == stop ? Evaluation.PRUNE : Evaluation.CONTINUE); assertEquals(expected, visited); }
/** * Breadth first pre order traversal. * * @param node The initial node. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. * @param evaluator An optional evaluator used to control traversal * termination. */ public void traverseBreadthFirstPre(N node, EdgeDirection direction, Visitor<N> visitor, Evaluator<N> evaluator) { traverseBreadthFirst(node, TraversalOrder.PRE_ORDER, direction, visitor, evaluator); }
/** * Depth first traversal without evaluator. * * @param node The initial node. Must not be null. * @param order The traversal order. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. */ public void traverseDepthFirst(N node, TraversalOrder order, EdgeDirection direction, Visitor<N> visitor) { traverseDepthFirst(node, order, direction, visitor, null); }
/** * Breadth first traversal without evaluator. * * @param node The initial node. Must not be null. * @param order The traversal order. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. */ public void traverseBreadthFirst(N node, TraversalOrder order, EdgeDirection direction, Visitor<N> visitor) { traverseBreadthFirst(node, order, direction, visitor, null); }
/** * Depth first post order traversal. * * @param node The initial node. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. * @param evaluator An optional evaluator used to control traversal * termination. */ public void traverseDepthFirstPost(N node, EdgeDirection direction, Visitor<N> visitor, Evaluator<N> evaluator) { traverseDepthFirst(node, TraversalOrder.POST_ORDER, direction, visitor, evaluator); }
/** * Breadth first post order traversal. * * @param node The initial node. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. * @param evaluator An optional evaluator used to control traversal * termination. */ public void traverseBreadthFirstPost(N node, EdgeDirection direction, Visitor<N> visitor, Evaluator<N> evaluator) { traverseBreadthFirst(node, TraversalOrder.POST_ORDER, direction, visitor, evaluator); }
/** * Depth first pre order traversal. * * @param node The initial node. Must not be null. * @param direction The edge direction to follow for traversal. Must not be null. * @param visitor Visitor that will be invoked for each visited node. * @param evaluator An optional evaluator used to control traversal * termination. */ public void traverseDepthFirstPre(N node, EdgeDirection direction, Visitor<N> visitor, Evaluator<N> evaluator) { traverseDepthFirst(node, TraversalOrder.PRE_ORDER, direction, visitor, evaluator); }