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


Java OptimizerFactory.setDefaultOptimizer方法代码示例

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


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

示例1: testBindingNullToPrimitiveTypes

import org.mvel2.optimizers.OptimizerFactory; //导入方法依赖的package包/类
public void testBindingNullToPrimitiveTypes() {
    Map<String, Object> vars = createTestMap();
    ((Foo) vars.get("foo")).setCountTest(10);

    OptimizerFactory.setDefaultOptimizer("reflective");
    Serializable s = MVEL.compileSetExpression("foo.countTest");
    MVEL.executeSetExpression(s, vars, null);

    assertEquals(((Foo) vars.get("foo")).getCountTest(), 0);

    OptimizerFactory.setDefaultOptimizer("ASM");
    s = MVEL.compileSetExpression("foo.countTest");
    MVEL.executeSetExpression(s, vars, null);

    assertEquals(((Foo) vars.get("foo")).getCountTest(), 0);

    MVEL.executeSetExpression(s, vars, null);

    assertEquals(((Foo) vars.get("foo")).getCountTest(), 0);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:21,代码来源:CoreConfidenceTests.java

示例2: 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

示例3: testTypeCoercion2

import org.mvel2.optimizers.OptimizerFactory; //导入方法依赖的package包/类
public void testTypeCoercion2() {
    OptimizerFactory.setDefaultOptimizer("reflective");
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("base",
            Base.class);

    Serializable s = compileExpression("java.math.BigInteger x = new java.math.BigInteger( \"5\" );" +
            " x + base.intValue;",
            ctx);

    Map vars = new HashMap();
    vars.put("base",
            new Base());

    Number x = (Number) executeExpression(s,
            vars);

    assertEquals(15,
            x.intValue());
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:22,代码来源:CoreConfidenceTests.java

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: testBindingNullToPrimitiveTypes4

import org.mvel2.optimizers.OptimizerFactory; //导入方法依赖的package包/类
public void testBindingNullToPrimitiveTypes4() {
    Map<String, Object> vars = createTestMap();
    ((Foo) vars.get("foo")).charTestFld = 'a';

    OptimizerFactory.setDefaultOptimizer("reflective");
    Serializable s = MVEL.compileSetExpression("foo.charTestFld");
    MVEL.executeSetExpression(s, vars, null);

    assertEquals(((Foo) vars.get("foo")).charTestFld, 0);

    OptimizerFactory.setDefaultOptimizer("ASM");
    s = MVEL.compileSetExpression("foo.charTestFld");
    MVEL.executeSetExpression(s, vars, null);

    assertEquals(((Foo) vars.get("foo")).charTestFld, 0);

    MVEL.executeSetExpression(s, vars, null);

    assertEquals(((Foo) vars.get("foo")).charTestFld, 0);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:21,代码来源:CoreConfidenceTests.java

示例10: testDataConverterStrictMode

import org.mvel2.optimizers.OptimizerFactory; //导入方法依赖的package包/类
public void testDataConverterStrictMode() throws Exception {
    OptimizerFactory.setDefaultOptimizer("ASM");

    DataConversion.addConversionHandler(Date.class,
            new MVELDateCoercion());

    ParserContext ctx = new ParserContext();
    ctx.addImport("Cheese",
            Cheese.class);
    ctx.setStrongTyping(true);
    ctx.setStrictTypeEnforcement(true);

    Locale.setDefault(Locale.US);

    Cheese expectedCheese = new Cheese();
    expectedCheese.setUseBy(new SimpleDateFormat("dd-MMM-yyyy").parse("10-Jul-1974"));

    ExpressionCompiler compiler = new ExpressionCompiler("c = new Cheese(); c.useBy = '10-Jul-1974'; return c");
    Cheese actualCheese = (Cheese) executeExpression(compiler.compile(ctx),
            createTestMap());
    assertEquals(expectedCheese.getUseBy(),
            actualCheese.getUseBy());
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:24,代码来源:CoreConfidenceTests.java

示例11: executeRules

import org.mvel2.optimizers.OptimizerFactory; //导入方法依赖的package包/类
protected void executeRules() throws TaskException {
    // show what's in first
    for (Object o: rulesMemoryContext) {
        LOG.debug("in memory context=" + o);
    }

    // JBRULES-2253: NoClassDefFoundError with the ASM optimizer when optimizing MVEL consequences.
    // Use the reflective optimizer as a workaround - this may reduce rules performance.
    // @see http://mvel.codehaus.org/Optimizers
    OptimizerFactory.setDefaultOptimizer("reflective");
    LOG.debug("Using MVEL thread accessor optimizer: " + OptimizerFactory.getThreadAccessorOptimizer());
    LOG.debug("Using MVEL accessor compiler: " + OptimizerFactory.getDefaultAccessorCompiler());

    KnowledgeBase knowledgeBase;
    StatelessKnowledgeSession statelessSession;
    try {
        knowledgeBase = readKnowledgeBase();
        statelessSession = knowledgeBase.newStatelessKnowledgeSession();
    } catch (Exception e) {
        throw new TaskException(e);
    }

    // add the log object for the rules to use
    statelessSession.setGlobal("LOG", LOG);
    statelessSession.execute(rulesMemoryContext);
}
 
开发者ID:maxdelo77,项目名称:replyit-master-3.2-final,代码行数:27,代码来源:RulesBaseTask.java

示例12: testBindListToArray

import org.mvel2.optimizers.OptimizerFactory; //导入方法依赖的package包/类
public void testBindListToArray() {
    Map<String, Object> vars = createTestMap();

    ArrayList<String> list = new ArrayList<String>();
    list.add("a");
    list.add("b");
    list.add("c");

    OptimizerFactory.setDefaultOptimizer("reflective");
    Serializable s = MVEL.compileSetExpression("foo.charArray");

    MVEL.executeSetExpression(s, vars, list);

    assertEquals(((Foo) vars.get("foo")).getCharArray().length, 3);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:16,代码来源:CoreConfidenceTests.java

示例13: testNewUsingWith

import org.mvel2.optimizers.OptimizerFactory; //导入方法依赖的package包/类
public void testNewUsingWith() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addImport(Foo.class);
    ctx.addImport(Bar.class);

    Serializable s = compileExpression("[ 'foo' : (with ( new Foo() )" +
            " { bar = with ( new Bar() ) { name = 'ziggy' } }) ]",
            ctx);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals("ziggy",
            (((Foo) ((Map) executeExpression(s)).get("foo")).getBar().getName()));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:15,代码来源:CoreConfidenceTests.java

示例14: testJIRA170b

import org.mvel2.optimizers.OptimizerFactory; //导入方法依赖的package包/类
public void testJIRA170b() {
    OptimizerFactory.setDefaultOptimizer("ASM");

    List<Integer> staticDispatch = Arrays.asList(2, 1, 0);
    List<Integer> multimethodDispatch = Arrays.asList(3, 2, 1);

    //       invokeJIRA170("Dynamic", ctxJIRA170(false, false), varsJIRA170(), multimethodDispatch);
    //       invokeJIRA170("Strict", ctxJIRA170(true, false), varsJIRA170(), multimethodDispatch);
    invokeJIRA170("Strong", ctxJIRA170(false, true), varsJIRA170(), staticDispatch);
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:11,代码来源:CoreConfidenceTests.java

示例15: testMapsAndLists2

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

    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addImport(HashMap.class);
    ctx.addImport(ArrayList.class);
    ctx.addInput("list",
            List.class);

    String expression = "m = new HashMap();\n" + "l = new ArrayList();\n" + "l.add(\"first\");\n" +
            "m.put(\"content\", l);\n" + "list.add(((ArrayList)m[\"content\"])[0]);";

    Serializable s = compileExpression(expression,
            ctx);

    Map vars = new HashMap();
    List list = new ArrayList();
    vars.put("list",
            list);

    Boolean result = (Boolean) executeExpression(s,
            vars);

    assertNotNull(result);
    assertTrue(result);
    assertEquals(1,
            list.size());
    assertEquals("first",
            list.get(0));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:32,代码来源:CoreConfidenceTests.java


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