Class TraversalResult<V,R>

java.lang.Object
com.phasmidsoftware.visitor.java.TraversalResult<V,R>
Type Parameters:
V - the node type
R - the result type produced by the Evaluator

public final class TraversalResult<V,R> extends Object
What a traversal found.

Instances are created by Traversals; there is no public constructor. All three accessors return unmodifiable views.

  • Method Details

    • visited

      public List<V> visited()
      The nodes that were visited, in the order they were visited.

      No node appears twice: the traversal keeps a visited set.

      Returns:
      the visited nodes, in visit order
    • results

      public List<R> results()
      The results the Evaluator produced, in visit order.

      Nodes for which the evaluator returned Optional.empty() are absent, so this list may be shorter than visited(). For the traversals that take no evaluator, each node evaluates to itself and this list equals visited().

      Returns:
      the results, in visit order
    • cameFrom

      public Map<V,V> cameFrom()
      Which node each node was first reached from.

      The start node is absent, having been reached from nowhere. The map records first discovery: a node reached again by a longer route keeps its original predecessor.

      This map is always empty for Traversals.traverseTree(Object, NeighbourFunction, NeighbourFunction, Order), because the traversal engine does not record came-from for a tree — the parent of each node is already known from the tree's own shape.

      Returns:
      the predecessor map, empty if the traversal did not record one
    • toString

      public String toString()
      Overrides:
      toString in class Object