Code Monkey home page Code Monkey logo

aviator-1's Introduction

Aviator

Build Status Code Quality: Java Maven Central

📖 English Documentation | 📖 中文文档


Aviator是一个轻量级、高性能的Java表达式执行引擎,它动态地将表达式编译成字节码并运行。

特性介绍

  1. 支持绝大多数运算操作符,包括算术操作符、关系运算符、逻辑操作符、位运算符、正则匹配操作符(=~)、三元表达式(?:)。
  2. 支持操作符优先级和括号强制设定优先级。
  3. 支持赋值
  4. 逻辑运算符支持短路运算。
  5. 支持丰富类型,例如nil、整数和浮点数、字符串、正则表达式、日期、变量等,支持自动类型转换和提升。
  6. 支持lambda匿名函数和闭包
  7. 内置一套强大的常用函数库
  8. 自定义函数,易于扩展,支持函数调用点参数列表捕获Java 方法批量导入
  9. 重载运算符
  10. 支持大数运算(BigInteger)和高精度运算(BigDecimal
  11. 支持多行表达式以及定制化求值器实例
  12. 小巧并性能优秀,提供大量的定制选项
  13. Function missing 机制,类似 Ruby 的 method missing。

更多详情,请访问主页

News

  • 4.2.9, Some bug fixes(#184, #186) and supports list/array elements assignment.
  • 4.2.8, Fixed #181 and wraps function returned value to ensure it's not null (replaced by AviatorNil).
  • 4.2.7, Fixed parser bug #177

Dependency

<dependency>
  <groupId>com.googlecode.aviator</groupId>
  <artifactId>aviator</artifactId>
  <version>{version}</version>
</dependency>

可以在 search.maven.org 查看可用的版本。

快速开始

int[] a = ...;
Map<String, Object> env = new HashMap<String, Object>();
env.put("a", a);

AviatorEvaluator.execute("1 + 2 + 3");
AviatorEvaluator.execute("a[1] + 100", env);
AviatorEvaluator.execute("'a[1]=' + a[1]", env);

// 求数组长度
AviatorEvaluator.execute("count(a)", env);

// 求数组总和
AviatorEvaluator.execute("reduce(a, +, 0)", env);

// 检测数组每个元素都在 0 <= e < 10 之间
AviatorEvaluator.execute("seq.every(a, seq.and(seq.ge(0), seq.lt(10)))", env);

// Lambda 求和
AviatorEvaluator.execute("reduce(a, lambda(x,y) -> x + y end, 0)", env);

// 导入 String 类实例方法作为自定义函数
AviatorEvaluator.addInstanceFunctions("s", String.class);
AviatorEvaluator.execute("s.indexOf('hello', 'l')");
AviatorEvaluator.execute("s.replaceAll('hello', 'l', 'x')");

// 导入静态方法作为自定义函数
AviatorEvaluator.addStaticFunctions("sutil", StringUtils.class);
AviatorEvaluator.execute("sutil.isBlank('hello')");

// 启用基于反射的 function missing 机制,调用任意 public 实例方法,无需导入
AviatorEvaluator.setFunctionMissing(JavaMethodReflectionFunctionMissing.getInstance());
// 调用 String#indexOf
System.out.println(AviatorEvaluator.execute("indexOf('hello world', 'w')"));
// 调用 Long#floatValue
System.out.println(AviatorEvaluator.execute("floatValue(3)"));
// 调用 BigDecimal#add
System.out.println(AviatorEvaluator.execute("add(3M, 4M)"));

更详细的请阅读用户指南

Links

aviator-1's People

Contributors

killme2008 avatar oldratlee avatar aliiohs avatar guoqiwen8 avatar einverne avatar m-razavi avatar xcorail avatar fanofxiaofeng avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.