Class VariationDiffTraversal<L extends Label>

java.lang.Object
org.variantsync.diffdetective.variation.diff.traverse.VariationDiffTraversal<L>

public class VariationDiffTraversal<L extends Label> extends Object
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 Details

  • Constructor Details

  • Method Details

    • with

      public static <L extends Label> VariationDiffTraversal<L> with(VariationDiffVisitor<L> visitor)
      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

      public static <L extends Label> VariationDiffTraversal<L> forAll(Consumer<DiffNode<L>> procedure)
      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

      public void visit(VariationDiff<L> tree)
      Start the traversal of the given tree at its root.
      Parameters:
      tree - The tree to traverse.
    • visit

      public void visit(DiffNode<L> subtree)
      Start the traversal of a VariationDiff at the given DiffNode.
      Parameters:
      subtree - The node at which to start the traversal.
    • visitChildrenOf

      public void visitChildrenOf(DiffNode<L> subtree)
      Continues the traversal by visiting all children of the given node sequentially.
      Parameters:
      subtree - The node whose children to visit.
    • markAsVisited

      private boolean markAsVisited(DiffNode<L> node)
      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.