basic feature
-
Based on the simple calculation model of the inverse Polish style, the biggest feature is simplicity. -
Short circuit optimization is supported (nodes that do not need to be calculated will be skipped as needed during the operation (boolean operation and ternary operation have such requirements). -
The operation rules are based on JavaScript familiar to front-end developers and can be used for expression implementation of template engines. -
It is also a superset of JSON interpretation engines, which can be used to interpret JSON data sources. -
Simple operation interface, which can easily redefine operation rules. -
Due to the simple implementation of the engine itself, the program size is very small (JAR files are only 22k, and similar tools OGNL 168k); It is suitable for embedding other environments that require strict file size, such as the webstart applet that needs to be downloaded.
Basic Usage
import org . xidea . el . Expression ;
import org . xidea . el . ExpressionImpl ;
import java . util . HashMap ;
public class Test {
public static void main ( String [] args ){
Expression el = new ExpressionImpl ( "var1 +2 * var2" );
//Expression el = new ExpressionImpl("var1 +2 * var2",new CalculaterImpl());// You can also define your own operation rules
HashMap context = new HashMap ();
context . put ( "var1" , one hundred and eleven );
context . put ( "var2" , two hundred and twenty-two );
Object result1 = el . evaluate ( context ); //555
context . put ( "var2" , three hundred and thirty-three );
Object result2 = el . evaluate ( context ); //777
System . out . println ( "result1:" );
System . out . println ( result1 );
System . out . println ( "result2:" );
System . out . println ( result2 );
}
}