本文整理汇总了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);
}
示例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);
}
示例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());
}
示例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));
}
示例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));
}
示例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());
}
示例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());
}
示例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));
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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()));
}
示例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);
}
示例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));
}