0

面临流口水列表迭代的问题

GoodsShipment有 GoodsItems 列表 GoodsItem Documents列表

我的要求是,需要检查至少一份文件是否可用。

我试过这个但失败了

写了一个类来检查目的

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

谁能帮帮我..提前谢谢

4

1 回答 1

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
于 2014-11-27T16:28:40.060 回答