Class TreeHelper


  • public class TreeHelper
    extends Object
    Helper class for flow tree related stuff.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • TreeHelper

        public TreeHelper()
    • Method Detail

      • pathToNode

        public static Node pathToNode​(TreePath path)
        Converts the path to a node (the last component in a path).
        Parameters:
        path - the path to the actor
        Returns:
        the node
      • pathsToNodes

        public static Node[] pathsToNodes​(TreePath[] paths)
        Converts the paths to actors (the last component in a path).
        Parameters:
        paths - the paths to the actors
        Returns:
        the actors
      • pathToActor

        public static Actor pathToActor​(TreePath path)
        Converts the path to an actor (the last component in a path). Does not return the "full" actor.
        Parameters:
        path - the path to the actor
        Returns:
        the actor
      • pathToActor

        public static Actor pathToActor​(TreePath path,
                                        boolean full)
        Converts the path to an actor (the last component in a path). "Full" actor means including (potential) sub-tree.
        Parameters:
        path - the path to the actor
        full - whether to return the full actor
        Returns:
        the actor
      • pathsToActors

        public static Actor[] pathsToActors​(TreePath[] paths)
        Converts the paths to actors (the last component in a path). Does not return the "full" actor.
        Parameters:
        paths - the paths to the actors
        Returns:
        the actors
      • pathsToActors

        public static Actor[] pathsToActors​(TreePath[] paths,
                                            boolean full)
        Converts the paths to actors (the last component in a path). "Full" actor means including (potential) sub-tree.
        Parameters:
        paths - the paths to the actors
        full - whether to return the full actor
        Returns:
        the actors
      • pathToNested

        public static List pathToNested​(TreePath path)
        Converts the path to nested node format (the last component in a path).
        Parameters:
        path - the path to the actor
        Returns:
        the nested format
      • pathsToNested

        public static List[] pathsToNested​(TreePath[] paths)
        Converts the paths to actors (the last component in a path).
        Parameters:
        paths - the paths to the actors
        Returns:
        the actors
      • treePathToActorPath

        public static ActorPath treePathToActorPath​(TreePath path)
        Turns a TreePath into a ActorPath.
        Parameters:
        path - the path to convert
        Returns:
        the generated path
      • buildTree

        public static Node buildTree​(List nested)
        Builds the tree from the nested commandlines.
        Parameters:
        nested - the nested commandlines
        Returns:
        the root node, null if failed to build
      • buildTree

        public static Node buildTree​(List nested,
                                     MessageCollection warnings,
                                     MessageCollection errors)
        Builds the tree from the nested commandlines.
        Parameters:
        nested - the nested commandlines
        warnings - for storing any warnings
        errors - for storing any errors
        Returns:
        the root node, null if failed to build
      • buildTree

        protected static Node buildTree​(Node root,
                                        List nested,
                                        MessageCollection warnings,
                                        MessageCollection errors,
                                        ArrayConsumer consumer)
        Builds the tree from the nested commandlines.
        Parameters:
        root - the root node to add to
        nested - the nested commandlines
        warnings - for storing any warnings
        errors - for storing any errors
        Returns:
        the root node, null if failed to build
      • buildTree

        public static Node buildTree​(Actor root)
        Builds the tree with the given root.
        Parameters:
        root - the root actor, can be null
        Returns:
        the root node
      • buildTree

        public static Node buildTree​(Node parent,
                                     Actor actor,
                                     boolean append)
        Builds the tree recursively.
        Parameters:
        parent - the parent to add the actor to
        actor - the actor to add
        append - whether to append the sub-tree to the parent or just return it (recursive calls always append the sub-tree!)
        Returns:
        the generated node
      • buildTree

        protected static Node[] buildTree​(Node parent,
                                          Actor[] actors,
                                          boolean append)
        Builds the tree recursively.
        Parameters:
        parent - the parent to add the actor to
        actors - the actors to add
        append - whether to append the sub-tree to the parent or just return it (recursive calls always append the sub-tree!)
        Returns:
        the generated nodes
      • indent

        protected static String indent​(String s,
                                       int numBlanks)
        Inserts blanks at the start of the string.
        Parameters:
        s - the string to process
        numBlanks - the number of blanks to insert
        Returns:
        the processed string
      • getCommandLines

        protected static void getCommandLines​(Node node,
                                              List<String> cmdlines,
                                              boolean noExtActors)
        Adds the node and its children to the list of commandlines.
        Parameters:
        node - the node to add
        cmdlines - the command lines to add to
      • getCommandLines

        public static List<String> getCommandLines​(Node root)
        Returns the nested commandlines. Indentation in blanks represents nesting level.
        Parameters:
        root - the root node
        Returns:
        the tree as nested commandlines
      • getCommandLines

        public static List<String> getCommandLines​(Node root,
                                                   boolean noExtActors)
        Returns the nested commandlines. Indentation in blanks represents nesting level.
        Parameters:
        root - the root node
        noExtActors - whether to exclude external actors
        Returns:
        the tree as nested commandlines
      • getNested

        protected static void getNested​(Node node,
                                        List nested,
                                        boolean noExtActors)
        Adds the node and its children to the nested format.
        Parameters:
        node - the node to add
        nested - the nested format to add to
      • getNested

        public static List getNested​(Node root)
        Returns the nested format.
        Parameters:
        root - the root node
        Returns:
        the tree as nested format
      • getNested

        public static List getNested​(Node root,
                                     boolean noExtActors)
        Returns the nested format.
        Parameters:
        root - the root node
        noExtActors - whether to exclude external actors
        Returns:
        the tree as nested format