当前位置:网站首页>Aviator an expression evaluation engine
Aviator an expression evaluation engine
2022-06-25 06:18:00 【WD Technology】
1. brief introduction
Aviator It's a high performance 、 Lightweight java Expression evaluation engine implemented by language , Mainly used for dynamic evaluation of various expressions . Now there are a lot of open source available java Expression evaluation engine , Why do we still need Avaitor Well ?
Aviator The design goal is lightweight and high performance , Compared with Groovy、JRuby It's heavy , Aviator A very small , Plus dependent packages 537K, Not counting dependent packages, there are only 70K; Of course , Aviator The syntax of is limited , It's not a complete language , It's just a small set of languages .
secondly , Aviator The implementation idea of is very different from other lightweight evaluators , Other evaluators generally run by interpretation , and Aviator It is to compile the expression directly into JVM Bytecode , hand JVM To carry out . Simply speaking , Aviator Is positioned between Groovy Such a heavyweight scripting language and IKExpression Between such lightweight expression engines .
2. User manual
(1)、Aviator The use of is centralized through com.googlecode.aviator.AviatorEvaluator This entry class handles , The simplest example , Perform a calculation 1+2+3 The expression of :
val result = AviatorEvaluator.execute("1+2+3")
println(result) //6
(2)、 If it's on ALWAYS_PARSE_FLOATING_POINT_NUMBER_INTO_DECIMAL Options , Then the floating-point numbers appearing in the expression will be resolved to BigDecimal, This is for the convenience of some users who require high-precision calculation , I don't want to add... To floating point numbers M The suffix is marked as BigDecimal
AviatorEvaluator.setOption(Options.ALWAYS_PARSE_FLOATING_POINT_NUMBER_INTO_DECIMAL, true)
(3)、 from 4.0.0 Start , aviator Support semicolon ; Separated multiline expressions , The result of evaluating a multiline expression will be the result of the last expression , for example
val result = AviatorEvaluator.execute("println('hello world'); 1+2+3 ; 100-1")
println(result)
// Output results :
//hello world
//99
3、 Execution example
First compile an expression containing variables , Then execute the environment with different variables . That's better performance
//compile Method can compile an expression into Expression The intermediate object of ,
// When the expression is to be executed, pass in env And call Expression Of execute The method can
public static void main(String[] args){
String expStr="a*b";
Expression expression=AviatorEvaluator.compile(expStr);
Map<String,Object> env=new HashMap<>();// Notice that it must be <String,Object> Of
env.put("a",3L);
env.put("b",2L);
System.out.println("result:"+expression.execute(env));
}
边栏推荐
- Monitoring access: how to grant minimum WMI access to the monitoring service account
- Wind farm visualization: wind farm data
- DF command – displays disk space usage
- JS implementation mouse can achieve the effect of left and right scrolling
- What does cardinality mean in set
- [v2.0] automatic update system based on motion step API (support disconnection reconnection and data compensation)
- Forecast report on output demand and supply scale of global and Chinese structural ceramics market for semiconductor equipment (2022 Edition)
- Aiot project that is an introduction to the basics of the Internet of things and can be implemented in practice
- Click to send text messages without response is a common problem for many users in building the elegant grass Dragonfly Q system - solve the problem of clicking to send text messages without response
- delphi-UUID
猜你喜欢
Processes and threads - concepts and process scheduling
[v2.0] automatic update system based on motion step API (support disconnection reconnection and data compensation)
Trial version of routing history and routing back and history of SAP ui5
Methods for obtaining some information of equipment
[road of system analyst] collection of wrong questions in the chapters of Applied Mathematics and economic management
Invalid bound statement (not found)
Guess the size of the number
Digitalization, transformation?
Rhcsa--- day 6 operation
[golang] leetcode intermediate - Search rotation sort array & search two-dimensional matrix II
随机推荐
MySQL transaction learning notes (I) first encounter
[v2.0] automatic update system based on motion step API (support disconnection reconnection and data compensation)
Research Report on brand strategic management and marketing trends in the global and Chinese preserved fruit market 2022
Ping command – test network connectivity between hosts
The elephant turns around and starts the whole body. Ali pushes Maoxiang not only to Jingdong
Netstat command – displays network status
Data7202 statistical analysis
Observation configuring wmic
Invalid bound statement (not found)
How to use asemi FET 7n80 and how to use 7n80
Vegetables sklearn - xgboost (2)
Why study discrete mathematics
Kotlin reflection -- Notes
Vscode voice notes to enrich information (Part 1)
Asemi fast recovery diode us1m parameters, us1m recovery time, us1m voltage drop
Count the grid
What is hybrid web containers for SAP ui5
Global and Chinese kaolin market operation scale and investment development proposal report 2022
After five years of software testing in ByteDance, I was dismissed in December to remind my brother of paddling
How often should you refactor- How often should you refactor?