简介
WAST 是一个高性能 Java 工具集库包,包括 JSON、YAML、CSV、HttpClient、JDBC 和 EL 引擎.
性能特色
- JSON 性能比当前所有开源 JSON 库应该都要快,包括当前性能强势的 Fastjson2.
- El 表达式引擎在性能上同样远超其他开源的 Java 库.
- YAML 模块性能大概是 snakeyaml 的 5-20 倍
源码地址
- gitee: https://gitee.com/xiaoch0209/wast
- github: https://github.com/wycst/wast
v0.0.19 更新内容:
- El表达式支持内嵌子表达式(计算变量);
- El表达式强化三目运算符号解析;
- El表达式支持boolean类型的异或运算;
- El表达式修复JDK6环境解析子表达式(函数参数)因为substring导致偏移bug问题;
- jdbc添加字段非空条件(is not null);
- JSONNode支持bytes和流作为输入源;
- JDK高版本(18+)Record类型反射权限问题修复;
内嵌子表达式用法
EvaluateEnvironment environment = EvaluateEnvironment.create();
Map vars = new HashMap();
vars.put("a", 10);
vars.put("b", 2);
vars.put("c", 3);
// 定义一个拓展变量d和2个计算变量e和f
environment.binding("d", 8);
environment.bindingComputed("e", "a + b - c * d"); // e = -12
environment.bindingComputed("f", "e << 1"); // f = -24
environment.registerStaticMethods(true, Arrays.class, System.class);
log.info("run first ====================");
// 注意:运行时必须带上environment
log.info("e -> {}", Expression.eval("e", vars, environment));
log.info("f -> {}", Expression.eval("f", vars, environment));
log.info(" -> {}", Expression.eval("asList(a, b, c, d, e, f)", vars, environment));
log.info("a + e + f -> {}", Expression.eval("a + e + f", vars, environment));
// 修改输入变量a,b,c 都放大10倍
vars.put("a", 100);
vars.put("b", 20);
vars.put("c", 30);
log.info("run second ====================");
log.info("e -> {}", Expression.eval("e", vars, environment));
log.info("f -> {}", Expression.eval("f", vars, environment));
log.info(" -> {}", Expression.eval("asList(a, b, c, d, e, f)", vars, environment));
log.info("a + e + f -> {}", Expression.eval("a + e + f", vars, environment));