Class Tree<T>

java.lang.Object
com.illumon.iris.db.v2.locations.util.Tree<T>
Type Parameters:
T -

public class Tree<T> extends Object
Simple tree/node structure.
  • Constructor Details

    • Tree

      public Tree(T value)
      Construct a Tree with the given value and no children.
      Parameters:
      value - the value at this node
  • Method Details

    • add

      public void add(Tree<T> child)
      Add a child node.
      Parameters:
      child - the child to add
    • leaves

      public List<T> leaves()
      Traverse the tree and return a list of all leaf nodes.
      Returns:
      all the leaf items
    • visit

      public <R> void visit(BiFunction<T,R,R> consumer, R context)
      Visit all the nodes of the tree. The provided Consumer may take actions such as printing, and may modify the context (e.g. to change indentation).
      
                   // This example prints out the TLP tree with indentation
                   System.out.println("visit:");
                   result.vist((tlp1, context) -> {
                       System.out.println(context + tlp1.getName());
                       return context + "    ";
                   }, "  ");
       
      Type Parameters:
      R - the context type
      Parameters:
      consumer - will be called on each node, may transform the context
      context - a context that may be useful in the visitation