panda.el.opt.logic.QuestionSelectOpt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
package panda.el.opt.logic;
import panda.el.ELContext;
import panda.el.ELException;
import panda.el.opt.AbstractTwoOpt;
/**
* 三元运算符: ':'
* 说明,三元表达式包含两个运算符:'?',':'.整个表达式的结果由它们共同完成.而每个符号承担一部分操作.
* '?':包含两个操作对象,即,'?'左侧的逻辑表达式,与'?'右侧的第一值.
':':也包含两个操作对象,即,':'前面生成的'?'对象,与':'右侧的第二个值.
* 在进行运算的时候,是先运算':',而':'中将条件的判断委托到'?'当中.然后':'对象根据'?'中的返回 结果分别读取'?'中的的左值或,':'的右值
*/
public class QuestionSelectOpt extends AbstractTwoOpt {
public int getPriority() {
return 13;
}
public Object calculate(ELContext ec) {
if (!(left instanceof QuestionOpt)) {
throw new ELException("三元表达式错误!");
}
QuestionOpt qo = (QuestionOpt)left;
Boolean cval = (Boolean)qo.calculate(ec);
if (cval) {
return qo.getRight(ec);
}
return getRight(ec);
}
public String operator() {
return ":";
}
}