在drools中遇到List迭代的问题
GoodsShipment 包含 GoodsItems 列表, GoodsItem 包含文档
列表我的要求是,需要检查至少一个文件是否可用。
我试过这个 但失败了写一个课程以检查目的
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
任何人都可以帮助我.. 提前谢谢
答案 0 :(得分:0)
您的代码有点不寻常,但规则应该这样做。请注意,我使用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