Package io.jenetics.prog.op
Class ConstRewriter<T>
- 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>>
public final class ConstRewriter<T> extends Object implements TreeRewriter<Op<T>>
This class rewrites constant expressions to its single value.The following example show 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
Fields Modifier and Type Field Description static ConstRewriter<Double>
DOUBLE
Const rewriter for double operation trees.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> ConstRewriter<T>
ofType(Class<? extends T> type)
Create a new rewriter for constant operation sub-trees (expressions).int
rewrite(TreeNode<Op<T>> node, int limit)
String
toString()
Class<T>
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 Detail
-
DOUBLE
public static final ConstRewriter<Double> DOUBLE
Const rewriter for double operation trees.
-
-
Method Detail
-
type
public Class<T> type()
Return the operation type this rewriter is working on.- Returns:
- the operation type this rewriter is working on
-
rewrite
public int rewrite(TreeNode<Op<T>> node, int limit)
- Specified by:
rewrite
in interfaceTreeRewriter<T>
-
ofType
public static <T> ConstRewriter<T> ofType(Class<? extends T> type)
Create a new rewriter for constant operation sub-trees (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 sub-trees (expressions)
- Throws:
NullPointerException
- if the giventype
isnull
-
-