当前位置: 首页>>代码示例>>Java>>正文


Java OptimizerFactory类代码示例

本文整理汇总了Java中org.mvel2.optimizers.OptimizerFactory的典型用法代码示例。如果您正苦于以下问题:Java OptimizerFactory类的具体用法?Java OptimizerFactory怎么用?Java OptimizerFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OptimizerFactory类属于org.mvel2.optimizers包,在下文中一共展示了OptimizerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: optimize

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
private Object optimize(Object ctx, Object elCtx, VariableResolverFactory variableResolverFactory) {

        if (DynamicOptimizer.isOverloaded()) {
            DynamicOptimizer.enforceTenureLimit();
        }

        AccessorOptimizer ao = OptimizerFactory.getAccessorCompiler("ASM");
        switch (type) {
            case DynamicOptimizer.REGULAR_ACCESSOR:
                _accessor = ao.optimizeAccessor(context, property, ctx, elCtx, variableResolverFactory, false, null);
                return ao.getResultOptPass();
            case DynamicOptimizer.OBJ_CREATION:
                _accessor = ao.optimizeObjectCreation(context, property, ctx, elCtx, variableResolverFactory);
                return _accessor.getValue(ctx, elCtx, variableResolverFactory);
            case DynamicOptimizer.COLLECTION:
                _accessor = ao.optimizeCollection(AbstractParser.getCurrentThreadParserContext(), ctx, null, property, ctx, elCtx, variableResolverFactory);
                return _accessor.getValue(ctx, elCtx, variableResolverFactory);
        }
        return null;
    }
 
开发者ID:codehaus,项目名称:mvel,代码行数:21,代码来源:DynamicGetAccessor.java

示例2: testMVEL226

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testMVEL226() {

        A226 a = new A226();
        Map m = Collections.singletonMap("a", a);
        Map<String, Object> nestMap = Collections.<String, Object>singletonMap("foo", "bar");
        String ex = "a.?map['foo']";
        Serializable s;

        assertNull(MVEL.getProperty(ex, m));

        OptimizerFactory.setDefaultOptimizer("ASM");
        s = MVEL.compileExpression(ex);
        assertNull(MVEL.executeExpression(s, m));
        a.map = nestMap;
        assertEquals("bar", MVEL.executeExpression(s, m));
        a.map = null;

        OptimizerFactory.setDefaultOptimizer(OptimizerFactory.DYNAMIC);

        s = MVEL.compileExpression(ex);
        assertNull(MVEL.executeExpression(s, m));
        a.map = nestMap;
        assertEquals("bar", MVEL.executeExpression(s, m));
    }
 
开发者ID:codehaus,项目名称:mvel,代码行数:25,代码来源:PropertyAccessTests.java

示例3: testJIRA207

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testJIRA207() {
        String ex = "x = 0; y = 0;" +
                "def foo() { x = 1; System.out.println('Word up'); }\n" +
                "def bar() { y = 1;  System.out.println('Peace out'); }\n" +
                "def doMany(fps) {\n" +
                "foreach(f : fps) { System.out.println(f); f(); }\n" +
                "}\n" +
                "doMany([foo,bar]);" +
                "x == 1 && y == 1;";

        Boolean bool;

//        Boolean bool = (Boolean) MVEL.eval(ex, new HashMap());
//        assertTrue(bool);

        OptimizerFactory.setDefaultOptimizer("ASM");
        Serializable s = MVEL.compileExpression(ex);

        bool = (Boolean) MVEL.executeExpression(s, new HashMap());
        assertTrue(bool);

        OptimizerFactory.setDefaultOptimizer("dynamic");
    }
 
开发者ID:codehaus,项目名称:mvel,代码行数:24,代码来源:FunctionsTest.java

示例4: start

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void start() {
    //Create two of the same expressions
    final String expression = "firstname";
    final String expression2 = "lastname";

    //Create a bean to run expressions against
    final Bean bean = new Bean();

    //Use reflection mode
    OptimizerFactory.setDefaultOptimizer(OptimizerFactory.SAFE_REFLECTIVE);

    //Compile the expressions
    Serializable mvelExp1 = MVEL.compileExpression(expression);
    Serializable mvelExp2 = MVEL.compileExpression(expression2);

    //run the threads
    runThreads(bean, mvelExp1, mvelExp2);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:19,代码来源:MVELThreadTest.java

示例5: testJIRA164

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testJIRA164() {
    Serializable s = MVEL.compileExpression("1 / (var1 + var1) * var1",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();
    double var1 = 1d;

    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));

    s = MVEL.compileExpression("1 / (var1 + var1) * var1", ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));

}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:ArithmeticTests.java

示例6: testJIRA164b

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testJIRA164b() {
    Serializable s = MVEL.compileExpression("1 + 1 / (var1 + var1) * var1",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 1d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((1 + 1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));

    s = MVEL.compileExpression("1 + 1 / (var1 + var1) * var1",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((1 + 1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:ArithmeticTests.java

示例7: testJIRA164c

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testJIRA164c() {
    Serializable s = MVEL.compileExpression("1 + 1 / (var1 + var1 + 2 + 3) * var1",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 1d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((1 + 1 / (var1 + var1 + 2 + 3) * var1), MVEL.executeExpression(s, vars));

    s = MVEL.compileExpression("1 + 1 / (var1 + var1 + 2 + 3) * var1",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((1 + 1 / (var1 + var1 + 2 + 3) * var1), MVEL.executeExpression(s, vars));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:ArithmeticTests.java

示例8: testJIRA164d

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testJIRA164d() {
    Serializable s = MVEL.compileExpression("1 + 1 + 1 / (var1 + var1) * var1",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 1d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((1 + 1 + 1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));

    s = MVEL.compileExpression("1 + 1 + 1 / (var1 + var1) * var1",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((1 + 1 + 1 / (var1 + var1) * var1), MVEL.executeExpression(s, vars));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:ArithmeticTests.java

示例9: testJIRA164e

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testJIRA164e() {
    Serializable s = MVEL.compileExpression("10 + 11 + 12 / (var1 + var1 + 51 + 71) * var1 + 13 + 14",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 1d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((float) (10 + 11 + 12 / (var1 + var1 + 51 + 71) * var1 + 13 + 14),
            ((Double) MVEL.executeExpression(s, vars)).floatValue());

    s = MVEL.compileExpression("10 + 11 + 12 / (var1 + var1 + 51 + 71) * var1 + 13 + 14",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((float) (10 + 11 + 12 / (var1 + var1 + 51 + 71) * var1 + 13 + 14),
            ((Double) MVEL.executeExpression(s, vars)).floatValue());
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:19,代码来源:ArithmeticTests.java

示例10: testJIRA164f

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testJIRA164f() {
    Serializable s = MVEL.compileExpression("10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 1d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((float) (10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14),
            ((Double) MVEL.executeExpression(s, vars)).floatValue());

    s = MVEL.compileExpression("10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");
    assertEquals((float) (10 + 11 + 12 / (var1 + 1 + var1 + 51 + 71) * var1 + 13 + 14),
            ((Double) MVEL.executeExpression(s, vars)).floatValue());
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:19,代码来源:ArithmeticTests.java

示例11: testJIRA164h

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testJIRA164h() {
    Serializable s = MVEL.compileExpression("1 - var1 * (var1 * var1 * (var1 * var1) * var1) * var1",
            ParserContext.create().stronglyTyped().withInput("var1", double.class));
    Map vars = new HashMap();

    double var1 = 2d;
    vars.put("var1", var1);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals((float) (1 - var1 * (var1 * var1 * (var1 * var1) * var1) * var1),
            ((Double) MVEL.executeExpression(s, vars)).floatValue());

    s = MVEL.compileExpression("1 - var1 * (var1 * var1 * (var1 * var1) * var1) * var1",
            ParserContext.create().withInput("var1", double.class));
    OptimizerFactory.setDefaultOptimizer("ASM");

    assertEquals((float) (1 - var1 * (var1 * var1 * (var1 * var1) * var1) * var1),
            ((Double) MVEL.executeExpression(s, vars)).floatValue());
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:20,代码来源:ArithmeticTests.java

示例12: testThisReferenceMapVirtualObjects1

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testThisReferenceMapVirtualObjects1() {
    // Create our root Map object
    Map<String, String> map = new HashMap<String, String>();
    map.put("foo", "bar");

    VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
    factory.createVariable("this", map);

    OptimizerFactory.setDefaultOptimizer("reflective");

    // Run test
    assertEquals(true,
            executeExpression(compileExpression("this.foo == 'bar'"),
                    map,
                    factory));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:CoreConfidenceTests.java

示例13: testThisReferenceMapVirtualObjects2

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testThisReferenceMapVirtualObjects2() {
    // Create our root Map object
    Map<String, String> map = new HashMap<String, String>();
    map.put("foo",
            "bar");

    VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
    factory.createVariable("this",
            map);

    // I think we can all figure this one out.

    if (!Boolean.getBoolean("mvel2.disable.jit")) OptimizerFactory.setDefaultOptimizer("ASM");

    // Run test
    assertEquals(true,
            executeExpression(compileExpression("this.foo == 'bar'"),
                    map,
                    factory));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:21,代码来源:CoreConfidenceTests.java

示例14: testSataticClassImportViaFactoryAndWithModification

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testSataticClassImportViaFactoryAndWithModification() {
    OptimizerFactory.setDefaultOptimizer("ASM");
    MapVariableResolverFactory mvf = new MapVariableResolverFactory(createTestMap());
    ClassImportResolverFactory classes = new ClassImportResolverFactory();
    classes.addClass(Person.class);

    ResolverTools.appendFactory(mvf,
            classes);

    assertEquals(21,
            executeExpression(
                    compileExpression("p = new Person('tom'); p.age = 20; " +
                            "with( p ) { age = p.age + 1 }; return p.age;",
                            classes.getImportedClasses()),
                    mvf));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:17,代码来源:CoreConfidenceTests.java

示例15: testExecuteCoercionTwice

import org.mvel2.optimizers.OptimizerFactory; //导入依赖的package包/类
public void testExecuteCoercionTwice() {
    OptimizerFactory.setDefaultOptimizer("reflective");

    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("foo",
            new Foo());
    vars.put("$value",
            new Long(5));

    ExpressionCompiler compiler = new ExpressionCompiler("with (foo) { countTest = $value };");

    ParserContext ctx = new ParserContext();
    ctx.setSourceFile("test.mv");
    ctx.setDebugSymbols(true);

    CompiledExpression compiled = compiler.compile(ctx);

    executeExpression(compiled, null, vars);
    executeExpression(compiled, null, vars);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:21,代码来源:CoreConfidenceTests.java


注:本文中的org.mvel2.optimizers.OptimizerFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。