针对SWITH函数的增强
package plus;
import com.fr.function.SWITCH;
import com.fr.general.ComparatorUtils;
import com.fr.script.Calculator;
import com.fr.stable.Primitive;
import com.fr.stable.UtilEvalError;
import com.fr.stable.script.Node;
public class SwitchExtension extends SWITCH {
@Override
public Object evalExpression(Node args) throws UtilEvalError {
if (args.length < 2) {
return Primitive.ERROR_NAME;
} else {
Calculator calculator = this.getCalculator();
Object cal = calculator.evalValue(args0]);
int argsLength=args.length;
for(int i = 1; i < (argsLength%2==0?argsLength-1:argsLength); i += 2) {//新增判断是否有默认值
Object var5 = calculator.evalValue(args);
if (ComparatorUtils.equals(cal, var5) && i + 1 < args.length) {
return calculator.eval(args1]);
}
}
if(argsLength%2==0) {
return calculator.eval(args1]);//无符合条件的结果情况下且有默认值则采用默认值
}
return Primitive.NULL;
}
}
}