本文整理汇总了Java中org.nfunk.jep.ASTVarNode类的典型用法代码示例。如果您正苦于以下问题:Java ASTVarNode类的具体用法?Java ASTVarNode怎么用?Java ASTVarNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ASTVarNode类属于org.nfunk.jep包,在下文中一共展示了ASTVarNode类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: set
import org.nfunk.jep.ASTVarNode; //导入依赖的package包/类
public void set(EvaluatorI pv, Node node, Object value) throws ParseException {
Node lhsNode = node.jjtGetChild(0);
if (!(lhsNode instanceof ASTVarNode))
throw new ParseException("Ele: lhs must be a variable");
ASTVarNode vn = (ASTVarNode) lhsNode;
Variable var = vn.getVar();
Object rhs = pv.eval(node.jjtGetChild(1));
int index = -1;
if (rhs instanceof Number) {
index = ((Number) rhs).intValue() - 1;
} else if (rhs instanceof Vector) {
Vector vec = (Vector) rhs;
if (vec.size() != 1)
throw new ParseException("Ele: only single dimension arrays supported in JEP");
index = ((Number) vec.firstElement()).intValue() - 1;
} else
throw new ParseException("Ele: rhs must be a number");
Object oldVarVal = var.getValue();
if (!(oldVarVal instanceof Vector))
throw new ParseException("Ele: the value of the variable must be a Vector");
Vector newVarVal = (Vector) ((Vector) oldVarVal).clone();
newVarVal.set(index, value);
var.setValue(newVarVal);
}
示例2: set
import org.nfunk.jep.ASTVarNode; //导入依赖的package包/类
public void set(EvaluatorI pv, Node node, Object value)
throws ParseException {
Node lhsNode = node.jjtGetChild(0);
if(!(lhsNode instanceof ASTVarNode))
throw new ParseException("Ele: lhs must be a variable");
ASTVarNode vn = (ASTVarNode) lhsNode;
Variable var = pv.getSymbolTable().getVar(vn.getVarName());
Object rhs = pv.eval(node.jjtGetChild(1));
int index=-1;
if(rhs instanceof Number)
{
index=((Number) rhs).intValue()-1;
}
else if(rhs instanceof Vector)
{
Vector vec = (Vector) rhs;
if(vec.size()!=1) throw new ParseException("Ele: only single dimension arrays supported in JEP");
index = ((Number) vec.firstElement()).intValue()-1;
}
else throw new ParseException("Ele: rhs must be a number");
Object oldVarVal = var.getValue();
if(!(oldVarVal instanceof Vector))
throw new ParseException("Ele: the value of the variable must be a Vector");
Vector newVarVal = (Vector) ((Vector) oldVarVal).clone();
newVarVal.set(index,value);
var.setValue(newVarVal);
}
示例3: set
import org.nfunk.jep.ASTVarNode; //导入依赖的package包/类
public void set(EvaluatorI pv, Node node, Object value)
throws ParseException {
Node lhsNode = node.jjtGetChild(0);
if(!(lhsNode instanceof ASTVarNode))
throw new ParseException("Ele: lhs must be a variable");
ASTVarNode vn = (ASTVarNode) lhsNode;
Variable var = vn.getVar();
Object rhs = pv.eval(node.jjtGetChild(1));
int index=-1;
if(rhs instanceof Number)
{
index=((Number) rhs).intValue()-1;
}
else if(rhs instanceof Vector)
{
Vector vec = (Vector) rhs;
if(vec.size()!=1) throw new ParseException("Ele: only single dimension arrays supported in JEP");
index = ((Number) vec.firstElement()).intValue()-1;
}
else throw new ParseException("Ele: rhs must be a number");
Object oldVarVal = var.getValue();
if(!(oldVarVal instanceof Vector))
throw new ParseException("Ele: the value of the variable must be a Vector");
Vector newVarVal = (Vector) ((Vector) oldVarVal).clone();
newVarVal.set(index,value);
var.setValue(newVarVal);
}