|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.singularsys.jep.walkers.DoNothingVisitor com.singularsys.jep.walkers.SubstitutionVisitor
public class SubstitutionVisitor
Allows substitution of a given variable with an expression tree. For example
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)".
Field Summary | |
---|---|
protected Operator |
assign
|
protected DeepCopyVisitor |
dcv
|
Fields inherited from class com.singularsys.jep.walkers.DoNothingVisitor |
---|
ft, jep, nf, ot, vt |
Constructor Summary | |
---|---|
SubstitutionVisitor()
Constructor to uses as a JepComponent. |
|
SubstitutionVisitor(Jep j)
|
Method Summary | |
---|---|
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[] names,
Node[] replacements)
Substitutes all occurrences of a set of variable var with a set of replacements. |
Node |
substitute(Node orig,
java.lang.String[] names,
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. |
Methods inherited from class com.singularsys.jep.walkers.DoNothingVisitor |
---|
copyChildrenIfNeeded, getFunctionTable, getLightWeightInstance, getNodeFactory, getOperatorTable, getVariableTable, visit, visit, visit, visit, visitChildren, visitNode |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Operator assign
protected DeepCopyVisitor dcv
Constructor Detail |
---|
public SubstitutionVisitor(Jep j)
public SubstitutionVisitor()
init(Jep)
method must be called to set the jep instance.
Method Detail |
---|
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 for
ParseException
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[] names, Node[] replacements) throws ParseException
orig
- the expression we wish to perform the substitution onnames
- the names of the variablereplacements
- the expression var is substituted for
ParseException
public Node substitute(Node orig, java.lang.String[] names, java.lang.Object[] values) throws ParseException
orig
- names
- 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 use
ParseException
public Node substitute(Node orig, java.lang.String[] oldNames, java.lang.String[] newNames) throws ParseException
orig
- oldNames
- the old variable namenewNames
- the new variable names
ParseException
public java.lang.Object visit(ASTVarNode node, java.lang.Object data) throws JepException
DoNothingVisitor
visit
in interface ParserVisitor
visit
in class DoNothingVisitor
JepException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |