package com.ruoyi.project.business.dto.JEPCustomFunction;

import org.nfunk.jep.EvaluatorI;
import org.nfunk.jep.Node;
import org.nfunk.jep.ParseException;
import org.nfunk.jep.function.CallbackEvaluationI;
import org.nfunk.jep.function.PostfixMathCommand;

/**
 * 类似contains  用于查找在指定索引 位置开始，查询某个字符串中 是否存在某个字符串
 *
 * @author jubs
 */
public class IFCustomFunction extends PostfixMathCommand implements CallbackEvaluationI {
    public IFCustomFunction() {
        // 使用参数的数量
        numberOfParameters = 3;
    }

    @Override
    public Object evaluate(Node node, EvaluatorI pv) throws ParseException {
        int num = node.jjtGetNumChildren();
        if (!this.checkNumberOfParameters(num)) {
            throw new ParseException("If operator must have 3 arguments.");
        } else {
            Object judgeCondition = pv.eval(node.jjtGetChild(0));
            Object trueValue = pv.eval(node.jjtGetChild(1));
            Object falseValue = pv.eval(node.jjtGetChild(2));
            if (judgeCondition instanceof Boolean) {
                return (Boolean)judgeCondition ? trueValue: falseValue;
            } else {


            }
        }
        return null;
    }
}
