【问题标题】:facing issue to iterate list in drools面临迭代流口水列表的问题
【发布时间】:2014-11-27 13:45:46
【问题描述】:

在drools中面临列表迭代问题

GoodsShipment 具有 GoodsItems 列表和 GoodsItemDocuments

的列表

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

我试过这个 但失败了

写了一个类来检查目的

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

谁能帮帮我.. 提前谢谢

【问题讨论】:

    标签: drools drools-guvnor drools-planner drools-fusion drools-flow


    【解决方案1】:

    您的代码有些不寻常,但规则应该这样做。请注意,我使用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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-15
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多