【发布时间】:2014-04-01 05:39:19
【问题描述】:
我使用地图来放置条件。 我的对象:
public class TestTO implements Serializable {
private String resultStr;
private List resultList;
private Map resultMap;
private Map parameterMap;
... ...
}
执行 Drools 规则:
public static Map getMapResult(TestTO rulesTo) throws Exception {
StatelessKnowledgeSession kSession = getKnowledgeSession();
AgendaEventListener ael = mock( AgendaEventListener.class );
kSession.addEventListener(ael);
kSession.execute(rulesTo);
Map resultMap = rulesTo.getResultMap();
if (resultMap != null && !resultMap.isEmpty())
return resultMap;
else throw new RuntimeException("EMPTY");
}
我的测试方法:
public void TestA() throws Exception{
Map<String, Object> test= new HashMap<String, Object>();
test.put("str1", "0");//string
test.put("str2", "SC");//string
test.put("dec1", new BigDecimal(372));//bigdecimal
TestTO m = new TestTo();
m.setParameterMap(test);
for(int i=0;i<22;i++){
m.setResultMap(new HashMap<String, Object>());
Map result=RuleTest.getMapResult(m);
}
}
现在我有一个关于规则文件的问题,如何从parameterMap 中获取"dec1",因为这个映射的值是Object ,if we get the value from this map by key. it's ok. but how to convert the value fromobjecttobigdecimal`?我尝试使用两种方式在 drl 文件中获取价值:
1.to.getParameterMap()["gt"]>=300.但它有一些问题。
2.to.getParameterMap()["gt"]>=300B。也许没关系。
为什么第二个没问题(我认为)?
我不必为 drools 方言指定默认值。所以我认为默认是“java”。
java方言是否支持300B?
非常感谢!
【问题讨论】:
-
如果你现在每个对象都有一个 BigDecimal,为什么不直接转换它呢?另一种方法是使用 Object.getClass() 询问它是否是 BigDecimal
-
不是每个对象,只有 1-3 个是 BigDecimal。我只想知道 300B 是正确还是不正确。 @LeoPflug
-
因为我不知道,可能不知道。如果你想检查一个 BigInteger 是否更大,你必须使用它的方法。