Package io.jenetics.ext.util
Class TreeFormatter
- java.lang.Object
-
- io.jenetics.ext.util.TreeFormatter
-
public abstract class TreeFormatter extends Object
Definition of different tree formatter strategies.- Since:
- 5.0
- Version:
- 5.0
-
-
Field Summary
Fields Modifier and Type Field Description static TreeFormatter
DOT
A tree formatter for .dot string representations.static TreeFormatter
LISP
Formats a given tree to a lisp string representation.static TreeFormatter
PARENTHESES
Formats a given tree to a parentheses string representation.static TreeFormatter
TREE
Formats a given tree to a tree string representation.
-
Constructor Summary
Constructors Modifier Constructor Description protected
TreeFormatter()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static TreeFormatter
dot(String treeName)
A tree formatter for .dot string representations.String
format(Tree<?,?> tree)
Formats the giventree
to its string representation.abstract <V> String
format(Tree<V,?> tree, Function<? super V,? extends CharSequence> mapper)
Formats the giventree
to its string representation.
-
-
-
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 treemul(div(cos(1.0),cos(π)),sin(mul(1.0,z)))
is rendered into this dot stringdigraph 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:
-
-
Constructor Detail
-
TreeFormatter
protected TreeFormatter()
-
-
Method Detail
-
format
public abstract <V> String format(Tree<V,?> tree, Function<? super V,? extends CharSequence> mapper)
Formats the giventree
to its string representation. The givenmapper
is used for converting the node typeV
to a string value.- Type Parameters:
V
- the tree node type- Parameters:
tree
- the input tree to formatmapper
- the tree node value mapper- Returns:
- the string representation of the given
tree
- Throws:
NullPointerException
- if one of the arguments isnull
-
format
public String format(Tree<?,?> tree)
Formats the giventree
to its string representation.- Parameters:
tree
- the input tree to format- Returns:
- the string representation of the given
tree
- Throws:
NullPointerException
- if thetree
isnull
-
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 treemul(div(cos(1.0),cos(π)),sin(mul(1.0,z)))
is rendered into this dot stringdigraph 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:- Parameters:
treeName
- the name of the digraph- Returns:
- a dot string formatter
- Throws:
NullPointerException
- if the given tree name isnull
-
-