[jboss-jira] [JBoss JIRA] (DROOLS-173) Collect and accumulate conditions not working togheter

Alvaro Pantoja (JIRA) jira-events at lists.jboss.org
Wed Jun 19 08:46:21 EDT 2013


     [ https://issues.jboss.org/browse/DROOLS-173?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alvaro Pantoja updated DROOLS-173:
----------------------------------

    Attachment: rule-test.log


Agenda & WM log
                
> Collect and accumulate conditions not working togheter
> ------------------------------------------------------
>
>                 Key: DROOLS-173
>                 URL: https://issues.jboss.org/browse/DROOLS-173
>             Project: Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>    Affects Versions: 6.0.0.Beta3
>            Reporter: Alvaro Pantoja
>            Assignee: Mark Proctor
>         Attachments: rule-test.log
>
>
> Running this example:
> > import java.util.ArrayList
> >
> > declare Item
> >     code: int
> >     price: int
> >     present: boolean
> > end
> >
> > rule "Init"
> > when
> > then
> >     insert(new Item(1,40,false));
> >     insert(new Item(2,40,false));
> >     insert(new Item(3,40,false));
> >     insert(new Item(4,40,false));
> > end
> >
> > rule "CollectAndAccumulateRule"
> > when
> >     //At least two items that aren't presents
> >     objList: ArrayList(size>=2) from collect( Item(present==false))
> >     //Total price bigger than 100
> >     price: Number(intValue>=100) from accumulate( Item($w:price, present==false), sum($w))
> > then
> >
> >     System.out.println("Sum: "+price);
> >     System.out.println("Items size: "+objList.size());
> >     
> >     //Look for the minor price item
> >     Item min = null;
> >     for(Object obj: objList){
> >         if (min!=null){
> >             min = (min.getPrice()>((Item)obj).getPrice())?(Item)obj:min;
> >         }
> >         else {
> >             min = (Item)obj;
> >         }
> >     }
> >     
> >     //And make it a present
> >     if (min!=null){
> >         modify(min){setPresent(true)};
> >     }
> > end
> Leads to an extra activacion and execution of rule "CollectAndAccumulateRule". It doesn't matter wich order conditions have, as long as there ara an "accumulate" and a "collect".
> Expected output would be:
>     Sum: 160.0
>     Items size: 4
>     Sum: 120.0
>     Items size: 3
> But is:
>     Sum: 160.0
>     Items size: 4
>     Sum: 120.0
>     Items size: 4
>     Sum: 120.0
>     Items size: 3
> Find attached agenda and working memory log snapshot

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list