use of com.googlecode.aviator.Expression in project java-demo by xiaofu.
the class FucntionTest method main.
public static void main(String[] args) {
String aa = " xxxobj.type=='1' && splitStartsWith('class',' ','F8','') && (xxxobj.modify==nil || xxobj.modify!='JG' )";
AviatorEvaluator.addFunction(new SplitEquals());
AviatorEvaluator.addFunction(new SplitContains());
AviatorEvaluator.addFunction(new SplitStartsWith());
Expression express = AviatorEvaluator.compile(aa, true);
Map<String, Object> env = new HashMap<String, Object>();
Map<String, Object> obj = new HashMap<String, Object>();
obj.put("class", "F8");
obj.put("type", '1');
env.put("xxxobj", obj);
System.out.println(express.execute(env));
// System.out.println(env.get("output"));
}
use of com.googlecode.aviator.Expression in project aviatorscript by killme2008.
the class CompileExample method main.
public static void main(String[] args) {
String expression = "a-(b-c)>100";
// 编译表达式
Expression compiledExp = AviatorEvaluator.compile(expression);
Map<String, Object> env = new HashMap<String, Object>();
env.put("a", 100.3);
env.put("b", 45);
env.put("c", -199.100);
// 执行表达式
Boolean result = (Boolean) compiledExp.execute(env);
System.out.println(result);
}
use of com.googlecode.aviator.Expression in project aviatorscript by killme2008.
the class ASMCodeGeneratorUnitTest method testOnConstant_String.
@Test
public void testOnConstant_String() throws Exception {
this.codeGenerator.onConstant(new StringToken("hello", 0, 0));
Expression exp = this.codeGenerator.getResult(true);
Object result = exp.execute();
assertEquals("hello", result);
}
use of com.googlecode.aviator.Expression in project aviatorscript by killme2008.
the class ASMCodeGeneratorUnitTest method testOnConstant_Boolean_False.
@Test
public void testOnConstant_Boolean_False() throws Exception {
this.codeGenerator.onConstant(Variable.FALSE);
Expression exp = this.codeGenerator.getResult(true);
Object result = exp.execute();
assertEquals(Boolean.FALSE, result);
}
use of com.googlecode.aviator.Expression in project aviatorscript by killme2008.
the class ASMCodeGeneratorUnitTest method testOnConstant_Boolean_True.
@Test
public void testOnConstant_Boolean_True() throws Exception {
this.codeGenerator.onConstant(Variable.TRUE);
Expression exp = this.codeGenerator.getResult(true);
Object result = exp.execute();
assertEquals(Boolean.TRUE, result);
}
Aggregations