public class SubstitutionVisitor extends DoNothingVisitor
Jep jep = new Jep(); Node node = jep.parse("x^2+x"); SubstitutionVisitor sv = new SubstitutionVisitor(jep); Node sub = jep.parse("sin(y)"); Node res = sv.substitute(node,"x",sub);Will give the expression "(sin(y))^2+sin(y)".
Modifier and Type | Field and Description |
---|---|
protected Operator |
assign |
protected DeepCopyVisitor |
dcv |
Constructor and Description |
---|
SubstitutionVisitor()
Constructor to uses as a JepComponent.
|
SubstitutionVisitor(Jep j) |
Modifier and Type | Method and Description |
---|---|
void |
init(Jep j)
Initialize the component.
|
Node |
substitute(Node orig,
Node sub)
Substitutes into orig the equation given by sub
|
Node |
substitute(Node orig,
Node[] subs) |
Node |
substitute(Node orig,
java.lang.String[] names1,
Node[] replacements1)
Substitutes all occurrences of a set of variable var with a set of replacements.
|
Node |
substitute(Node orig,
java.lang.String[] names1,
java.lang.Object[] values)
Substitute a set of names with a set of values.
|
Node |
substitute(Node orig,
java.lang.String[] oldNames,
java.lang.String[] newNames)
Substitute a set of variable names with a new set of names.
|
Node |
substitute(Node orig,
java.lang.String name,
Node replacement)
Substitutes all occurrences of variable var with replacement.
|
Node |
substitute(Node orig,
java.lang.String name,
java.lang.Object value)
Substitute a single variable with a given value.
|
java.lang.Object |
visit(ASTVarNode node,
java.lang.Object data)
Visit a variable node.
|
childrenHaveChanged, copyChildrenIfNeeded, getFunctionTable, getLightWeightInstance, getNodeFactory, getOperatorTable, getVariableTable, visit, visit, visit, visit, visitChildren, visitNode
protected Operator assign
protected DeepCopyVisitor dcv
public SubstitutionVisitor(Jep j)
public SubstitutionVisitor()
init(Jep)
method must be called to set the jep instance.public void init(Jep j)
JepComponent
init
in interface JepComponent
init
in class DoNothingVisitor
j
- the current Jep instancepublic Node substitute(Node orig, java.lang.String name, Node replacement) throws ParseException
orig
- the expression we wish to perform the substitution onname
- the name of the variablereplacement
- the expression var is substituted forParseException
public Node substitute(Node orig, Node sub) throws ParseException
orig
- the equation to substitute intosub
- and equation of the form x=....ParseException
- if sub is of the wrong formpublic Node substitute(Node orig, Node[] subs) throws ParseException
ParseException
public Node substitute(Node orig, java.lang.String[] names1, Node[] replacements1) throws ParseException
orig
- the expression we wish to perform the substitution onnames1
- the names of the variablereplacements1
- the expression var is substituted forParseException
public Node substitute(Node orig, java.lang.String[] names1, java.lang.Object[] values) throws ParseException
orig
- names1
- values
- ParseException
public Node substitute(Node orig, java.lang.String name, java.lang.Object value) throws ParseException
orig
- equation to perform substitution onname
- variable namevalue
- value to useParseException
public Node substitute(Node orig, java.lang.String[] oldNames, java.lang.String[] newNames) throws ParseException
orig
- oldNames
- the old variable namenewNames
- the new variable namesParseException
public java.lang.Object visit(ASTVarNode node, java.lang.Object data) throws JepException
DoNothingVisitor
visit
in interface ParserVisitor
visit
in class DoNothingVisitor
JepException
Copyright © 2018 Singular Systems http://www.singularsys.com/jep