在drools中迭代列表面临的问题
drools中列表迭代面临的问题 GoodsShipment有GoodsItems的列表和 GoodsItem拥有文档列表 我的要求是,需要检查至少一个文件是否可用 我试过这个 但失败了 编写一个用于检查的类在drools中迭代列表面临的问题,drools,drools-guvnor,drools-planner,drools-fusion,drools-flow,Drools,Drools Guvnor,Drools Planner,Drools Fusion,Drools Flow,drools中列表迭代面临的问题 GoodsShipment有GoodsItems的列表和 GoodsItem拥有文档列表 我的要求是,需要检查至少一个文件是否可用 我试过这个 但失败了 编写一个用于检查的类 public class CheckDocument { public boolean flag = false; public CheckPreviousDocument() { } public boolean getPreviousDocument(
public class CheckDocument {
public boolean flag = false;
public CheckPreviousDocument() {
}
public boolean getPreviousDocument(GoodsShipment goodsshipment) {
List<GoodsItem> list = goodsshipment.getGoodsItems();
Iterator<GoodsItem> itr = list.iterator();
while (itr.hasNext()) {
GovernmentAgencyGoodsItem document = itr.next();
if (document.getDocuments().size() > 0) {
flag = true;
break;
}
}
return flag;
}
}
rule "previousDocuments minimum 1"
when
$o: GoodsShipment()
%x: CheckPreviousDocuments(previousDocuments($o) == false)
then
insert(-------------)
end
公共类检查文档{
公共布尔标志=false;
公开检查以前的文档(){
}
公共布尔getPreviousDocument(GoodsShipment GoodsShipment){
List List=goodsshipment.getGoodsItems();
迭代器itr=list.Iterator();
while(itr.hasNext()){
GovernmentAgencyGoodsItem document=itr.next();
if(document.getDocuments().size()>0){
flag=true;
打破
}
}
返回标志;
}
}
规则“以前的文件至少1”
什么时候
$o:货物装运()
%x:CheckPreviousDocuments(previousDocuments($o)==false)
然后
插入(--------------)
终止
谁能帮帮我吗。。
提前感谢您的代码有点不寻常,但这样规则就可以了。注意,我使用了
Document
作为由GovernmentAgencyGoodsItem.getDocuments()
返回的列表中元素的类型
rule atLeastOne
when
$gs: GoodsShipment()
List( size > 0 )
from accumulate ( $gi: GoodsItem() from $gs.getGoodsItems() and
$d: Document() from $gi.getDocuments();
collectList( $d ) )
then
// $gs contains at least one Document
end