Search in sources :

Example 16 with Expression

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"));
}
Also used : Expression(com.googlecode.aviator.Expression) HashMap(java.util.HashMap) AviatorObject(com.googlecode.aviator.runtime.type.AviatorObject)

Example 17 with Expression

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);
}
Also used : Expression(com.googlecode.aviator.Expression) HashMap(java.util.HashMap)

Example 18 with Expression

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);
}
Also used : Expression(com.googlecode.aviator.Expression) StringToken(com.googlecode.aviator.lexer.token.StringToken) Test(org.junit.Test)

Example 19 with Expression

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);
}
Also used : Expression(com.googlecode.aviator.Expression) Test(org.junit.Test)

Example 20 with Expression

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);
}
Also used : Expression(com.googlecode.aviator.Expression) Test(org.junit.Test)

Aggregations

Expression (com.googlecode.aviator.Expression)31 Test (org.junit.Test)16 HashMap (java.util.HashMap)8 NumberToken (com.googlecode.aviator.lexer.token.NumberToken)3 AviatorString (com.googlecode.aviator.runtime.type.AviatorString)3 Map (java.util.Map)3 PatternToken (com.googlecode.aviator.lexer.token.PatternToken)2 StringToken (com.googlecode.aviator.lexer.token.StringToken)2 CollectRep (com.usthe.common.entity.message.CollectRep)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AviatorEvaluator (com.googlecode.aviator.AviatorEvaluator)1 AviatorEvaluatorInstance (com.googlecode.aviator.AviatorEvaluatorInstance)1 BaseExpression (com.googlecode.aviator.BaseExpression)1 LiteralExpression (com.googlecode.aviator.LiteralExpression)1 CompareNotSupportedException (com.googlecode.aviator.exception.CompareNotSupportedException)1 CompileExpressionErrorException (com.googlecode.aviator.exception.CompileExpressionErrorException)1 ExpressionRuntimeException (com.googlecode.aviator.exception.ExpressionRuntimeException)1 ExpressionSyntaxErrorException (com.googlecode.aviator.exception.ExpressionSyntaxErrorException)1 DelegateToken (com.googlecode.aviator.lexer.token.DelegateToken)1