java.lang.Object
io.jenetics.prog.op.ConstRewriter<T>
- Type Parameters:
T
- the operation type the rewriter is working on
- All Implemented Interfaces:
TreeRewriter<Op<T>>
This class rewrites constant expressions to its single value.
The following example shows how to use the rewriter for a double operation tree:
final TreeNode<Op<Double>> tree = MathExpr.parseTree("1 + 2 + 3 + 4");
ConstRewriter.ofType(Double.class).rewrite(tree);
assert tree.getValue().equals(Const.of(10.0));
- Since:
- 5.2
- Version:
- 5.2
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ConstRewriter
<Double> Const rewriter for double operation trees. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ConstRewriter
<T> Create a new rewriter for constant operation subtrees (expressions).int
Applies the rewriting to the given (mutable)tree
.toString()
type()
Return the operation type this rewriter is working on.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.jenetics.ext.rewriting.TreeRewriter
rewrite
-
Field Details
-
DOUBLE
Const rewriter for double operation trees.
-
-
Method Details
-
type
Return the operation type this rewriter is working on.- Returns:
- the operation type this rewriter is working on
-
rewrite
Description copied from interface:TreeRewriter
Applies the rewriting to the given (mutable)tree
. The tree rewrite is done in place. Via thelimit
parameter, the termination of the tree-rewrite process can be guaranteed.- Specified by:
rewrite
in interfaceTreeRewriter<T>
- Parameters:
node
- the tree to be rewrittenlimit
- the maximal number this rewrite rule is applied to the given tree. This guarantees the termination of the rewrite method.- Returns:
- the number of rewrites applied to the input
tree
-
toString
-
ofType
Create a new rewriter for constant operation subtrees (expressions).- Type Parameters:
T
- the type of the operation tree- Parameters:
type
- the type of the operation tree- Returns:
- a new rewriter for constant operation subtrees (expressions)
- Throws:
NullPointerException
- if the giventype
isnull
-