Class VariationDiffTraversal<L extends Label>
java.lang.Object
org.variantsync.diffdetective.variation.diff.traverse.VariationDiffTraversal<L>
Class for traversing VariationDiffs and accumulating results.
VariationDiffs are directed, acyclic graphs but not actually trees.
Thus, a recursive traversal of VariationDiffs will yield to many nodes being visited multiple times or
even infeasible runtimes when VariationDiffs are very deep.
A VariationDiffTraversal guarantees that each node in a VariationDiff is visited at most once.
A VariationDiffTraversal does not give any guarantees on the order nodes are visited in but it
is a depth-first search like approach.
The order in which nodes are visited is customizable with a
VariationDiffVisitor
that decides on each
visited node, how to proceed the traversal.- Author:
- Paul Bittner
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <L extends Label>
VariationDiffTraversal<L>Creates a new traversal that will invoke the given callback once for each node in a visited VariationDiff.private boolean
markAsVisited
(DiffNode<L> node) Treat the given node as already visited regardless whether this is actually true or not.void
Start the traversal of a VariationDiff at the given DiffNode.void
visit
(VariationDiff<L> tree) Start the traversal of the given tree at its root.void
visitChildrenOf
(DiffNode<L> subtree) Continues the traversal by visiting all children of the given node sequentially.static <L extends Label>
VariationDiffTraversal<L>with
(VariationDiffVisitor<L> visitor) Creates a traversal with the given visitor.
-
Field Details
-
visited
-
visitor
-
-
Constructor Details
-
VariationDiffTraversal
-
-
Method Details
-
with
Creates a traversal with the given visitor.- Parameters:
visitor
- Visitor that is invoked on each node and always decides how to proceed the traversal.- Returns:
- The new traversal.
-
forAll
Creates a new traversal that will invoke the given callback once for each node in a visited VariationDiff.- Parameters:
procedure
- Callback that is invoked exactly once on each DiffNode in a VariationDiff.- Returns:
- The new traversal that will visit each node exactly once.
-
visit
Start the traversal of the given tree at its root.- Parameters:
tree
- The tree to traverse.
-
visit
Start the traversal of a VariationDiff at the given DiffNode.- Parameters:
subtree
- The node at which to start the traversal.
-
visitChildrenOf
Continues the traversal by visiting all children of the given node sequentially.- Parameters:
subtree
- The node whose children to visit.
-
markAsVisited
Treat the given node as already visited regardless whether this is actually true or not.- Parameters:
node
- Node that should be treated as already visited.- Returns:
- True if the node was unvisited and is now marked visited. False if the node was already marked visited.
-