[rules-users] accumulate function

Wendy Mungovan w.mungovan at yahoo.com
Wed Sep 21 07:12:55 EDT 2011



I'm assuming that c6066 is really a number and not a string....if not you will need to change this to parse the string into a number.

I think something like this should do it.  You first get the list from a SegmentGroup8 then sum the values you need. This is untested code.


$seg: SegmentGroup8()

$sum: Number() from accumulate( $cntTotal: ControlTotal() from $seg.getCnt(), sum($cntTotal.getC6066()))


________________________________
From: pamerida <elpamm at hotmail.com>
To: rules-users at lists.jboss.org
Sent: Tuesday, September 20, 2011 5:35 PM
Subject: [rules-users] accumulate function

Hi everyone, 

I have this scenario:
I have assserted a few elements of the type "SegmentGroup8" into the working
memory, this SegmentGroup8 class have inside a list called private
List<ControlTotal> cnt;

What I need to achieve is to perform a "sum" of one of the fields called
c6066 inside the ControlTotal for all the SegmentGroup8 asserted into the
WM...

I would like to use the accumulate functions but I really dont know how, any
help would be appreciated, thanks in advance...

the classes code is the following...


public class SegmentGroup8
    implements Serializable
{

    private List<ControlTotal> cnt;
    private List<MonetaryAmount> moa;

public List<ControlTotal> getCnt() {
        return cnt;
    }

    public void setCnt(List<ControlTotal> cnt) {
        this.cnt = cnt;
    }

......
}



public class ControlTotal extends Segment
    implements Serializable
{

    private String c6069;
    private String c6066;
    
........

    public String getC6069() {
        return c6069;
    }

    public void setC6069(String c6069) {
        this.c6069 = c6069;
    }

    public String getC6066() {
        return c6066;
    }

    public void setC6066(String c6066) {
        this.c6066 = c6066;
    }

.........
}





--
View this message in context: http://drools.46999.n3.nabble.com/accumulate-function-tp3353507p3353507.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110921/cda4de74/attachment.html 


More information about the rules-users mailing list