Class TreeFormatter


  • public abstract class TreeFormatter
    extends Object
    Definition of different tree formatter strategies.
    Since:
    5.0
    Version:
    5.0
    • Field Detail

      • TREE

        public static final TreeFormatter TREE
        Formats a given tree to a tree string representation.
             mul
             ├── div
             │   ├── cos
             │   │   └── 1.0
             │   └── cos
             │       └── π
             └── sin
                 └── mul
                     ├── 1.0
                     └── z
          
      • PARENTHESES

        public static final TreeFormatter PARENTHESES
        Formats a given tree to a parentheses string representation.
             mul(div(cos(1.0),cos(π)),sin(mul(1.0,z)))
         
      • LISP

        public static final TreeFormatter LISP
        Formats a given tree to a lisp string representation.
             (mul (div (cos 1.0) (cos π)) (sin (mul 1.0 z)))
         
      • DOT

        public static final TreeFormatter DOT
        A tree formatter for .dot string representations. This strings can be used to create nice looking tree images. The tree
             mul(div(cos(1.0),cos(π)),sin(mul(1.0,z)))
         
        is rendered into this dot string
         digraph Tree {
             node_001 [label="div"];
             node_002 [label="cos"];
             node_003 [label="1.0"];
             node_004 [label="cos"];
             node_000 [label="mul"];
             node_009 [label="z"];
             node_005 [label="π"];
             node_006 [label="sin"];
             node_007 [label="mul"];
             node_008 [label="1.0"];
             node_000 -> node_001;
             node_001 -> node_002;
             node_002 -> node_003;
             node_001 -> node_004;
             node_004 -> node_005;
             node_000 -> node_006;
             node_006 -> node_007;
             node_007 -> node_008;
             node_007 -> node_009;
         }
         
        This dot string can be rendered into the following graph:

        Dot-tree

    • Method Detail

      • format

        public abstract <V> String format​(Tree<V,​?> tree,
                                          Function<? super V,​? extends CharSequence> mapper)
        Formats the given tree to its string representation. The given mapper is used for converting the node type V to a string value.
        Type Parameters:
        V - the tree node type
        Parameters:
        tree - the input tree to format
        mapper - the tree node value mapper
        Returns:
        the string representation of the given tree
        Throws:
        NullPointerException - if one of the arguments is null
      • format

        public String format​(Tree<?,​?> tree)
        Formats the given tree to its string representation.
        Parameters:
        tree - the input tree to format
        Returns:
        the string representation of the given tree
        Throws:
        NullPointerException - if the tree is null
      • dot

        public static TreeFormatter dot​(String treeName)
        A tree formatter for .dot string representations. This strings can be used to create nice looking tree images. The tree
             mul(div(cos(1.0),cos(π)),sin(mul(1.0,z)))
         
        is rendered into this dot string
         digraph Tree {
             node_001 [label="div"];
             node_002 [label="cos"];
             node_003 [label="1.0"];
             node_004 [label="cos"];
             node_000 [label="mul"];
             node_009 [label="z"];
             node_005 [label="π"];
             node_006 [label="sin"];
             node_007 [label="mul"];
             node_008 [label="1.0"];
             node_000 -> node_001;
             node_001 -> node_002;
             node_002 -> node_003;
             node_001 -> node_004;
             node_004 -> node_005;
             node_000 -> node_006;
             node_006 -> node_007;
             node_007 -> node_008;
             node_007 -> node_009;
         }
         
        This dot string can be rendered into the following graph:

        Dot-tree

        Parameters:
        treeName - the name of the digraph
        Returns:
        a dot string formatter
        Throws:
        NullPointerException - if the given tree name is null