如何从drl Drools中的累积返回列表? [英] How to return a list from inside of accumulate in drl Drools?

查看:792
本文介绍了如何从drl Drools中的累积返回列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的规则

rule "Multiple bookings via same mobile"
    when
        (stayDateGroupingIteration : StayDateGroupingDto($stayGroupedBookings : stayGroupedBookings)) and (QueryTypeDto( queryType == "multiple" ))
        $travellerCount :Number() from accumulate(BookingSummaryDtoList( $bookingSummaryDtoList : bookingSummaryDtoList) from $stayGroupedBookings,
        init( int count=0; List<String> globalList= new ArrayList(); Set<String> duplicateSet=new HashSet();),
        action(
        for(Object bookingSummary : $bookingSummaryDtoList)
        {

            if(((BookingSummaryDto)bookingSummary).getTravellerId()!=null)
            {   
                String travellerId=((BookingSummaryDto)bookingSummary).getTravellerId().toString();
                Set<String> finalDuplicateSet=MultiBookingFraudServiceImpl.checkDuplicates(travellerId,globalList,duplicateSet);
                count=count+1;
            }
        }
        ),
        result( new Integer(count)))
    then
        //some action to be taken here
        System.out.println($travellerCount);
end

我该如何退货

finalDuplicateSet

finalDuplicateSet

从累加代替计数,我也不想在我的java类中使用任何全局变量或静态变量.可以做到吗?还是需要采取其他方法?

from the accumulate in place of count, I don't want to use any global variables or static variables in my java class also. can this be done or do I need to follow some other approach?

推荐答案

希望此代码帮助您获得所需的内容:

Hope this code Help you in getting what you want :

rule "Multiple bookings via same mobile"
    when
        (stayDateGroupingIteration : StayDateGroupingDto($stayGroupedBookings : stayGroupedBookings)) and (QueryTypeDto( queryType == "multiple" ))
        $duplicateTravellerList :List() from accumulate(BookingSummaryDtoList( $bookingSummaryDtoList : bookingSummaryDtoList) from $stayGroupedBookings,
        init( int count=0; List<String> globalList= new ArrayList(); Set<String> duplicateSet=new HashSet(); List<String> finalDuplicateSet=new ArrayList();),
        action(
        for(Object bookingSummary : $bookingSummaryDtoList)
        {

            if(((BookingSummaryDto)bookingSummary).getTravellerId()!=null)
            {   
                String travellerId=((BookingSummaryDto)bookingSummary).getTravellerId().toString();
                finalDuplicateSet.add(MultiBookingFraudServiceImpl.checkDuplicates(travellerId,globalList,duplicateSet));
                count=count+1;
            }
        }
        ),
        result( new ArrayList(finalDuplicateSet)))
    then
        //some action to be taken here
        System.out.println($duplicateTravellerList);
end

这篇关于如何从drl Drools中的累积返回列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆