package com.roy;

import com.googlecode.aviator.AviatorEvaluator;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：楼兰
 * @date ：Created in 2021/7/2
 * @description:
 **/

public class AviatorDemo {

    /**
     * Aviator支持三种类型计算：Boolean，字符串，和数字类型，数字类型只支持结果为Long
     * @param args
     */
    public static void main(String[] args) {
        //数字型计算
        System.out.println(AviatorEvaluator.execute("1+2+3"));
        //字符型计算
        String exp1 = "'Hello '+ name";
        Map<String,Object> env1 = new HashMap<>();
        env1.put("name","tony");
        System.out.println(AviatorEvaluator.execute(exp1, env1));
        //判断型计算
        String exp2 = "a+b>c";
        Map<String,Object> env2 = new HashMap<>();
        env2.put("a",5);
        env2.put("b",6);
        env2.put("c",7);
        System.out.println(AviatorEvaluator.execute(exp2, env2));
        //https://blog.csdn.net/qq_27384769/article/details/80639122

    }
}
