then里获取已知类型的事实对象
需求:当在then里写推理规则时,想要获取"ValueOfParameter"类型的事实对象,但是when里并没有定义,则需求另取。
drools.getWorkingMemory() ——是一个workingmemory对象
WorkingMemory workingmemory = drools.getWorkingMemory();
String Obj = CommonUtils.ObjectofWorkingmemory(drools.getWorkingMemory(),"ValueOfParameter");
写在外面的java方法:
public static List<Object> ObjectofWorkingmemory(WorkingMemory workingmemory, String Conb){
List<Object> result = new ArrayList<Object>();
List<Object> copy = new ArrayList<Object>();
Iterator it = workingmemory.iterateObjects();
while(it.hasNext())
{
copy.add(it.next());
}
for(Object s : copy){
if(s.getClass().getSimpleName().equals(Conb)){ //这里不用 instanceof 主要是因为Conb和s不支持不好解释了。。。
result.add(s);
}
}
return result;
}
浙公网安备 33010602011771号