<br> Yes, the "from collect" is new to 4.0.<br> If you are using 3.0.6, you must use 2 rules and a helper class to do the count:<br><br>rule "counting"<br>salience 10<br>when<br> $counter : Counter()
<br> Student( name == "Drools" )<br>then<br> $counter.setValue( $counter.getValue() + 1 );<br>end<br><br>rule "Total instances"<br>when<br> $counter : Counter( )<br>then<br> System.out.println
( "Total instances = "+$counter.getValue() );<br>end<br><br> Please not the higher salience value in the first rule. Also, remember to assert all your objects into the working memory, not only the list.<br> The Counter class is a simple java bean to help you do the count.
<br><br> Hope it helps.<br> <br> []s<br> Edson<br><br><div><span class="gmail_quote">2007/6/1, <a href="mailto:rajesh_sachin10@yahoo.co.in">rajesh_sachin10@yahoo.co.in</a> <<a href="mailto:rajesh_sachin10@yahoo.co.in">
rajesh_sachin10@yahoo.co.in</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi<br>I'm working on Drools 3.06. I am not able to decipher the drl snippet you have posted.
<br>I'am not clear about the <b>'from collect'</b> Keywords. My problem statement is to get the number of<br>occurance of a Student(Name =="Drools") in a collection.<br><br>Please find below a small java snippet which is equivalent to what I'm tring to do.
<br><br>int count = 0;<br>List<Student> nameList = getListofNames();<br>while(nameList.iterator().hasNext())<br> {<br> Student student = (Student)nameList.iterator().next();<br> if(Student.getName.equals
("Drools"))<br> {<br> count++;<br> }<br> }<br>System.out.println("Occurance Count" + count);<br><br><br>Edson Tirelli-3 wrote:<br>><br>> Nope, if you want actual instances you must use "collect":
<br>><br>> when<br>> context : Context(state == Context:START_UP)<br>> list : ArrayList( size > 0 ) from collect( ClassName(varName =="value" )<br>> )<br>> then<br>> // list has your matching ClassName objects
<br>> end<br>><br>> []s<br>> Edson<br>><br>><br>><br>> 2007/6/1, Rajesh.Sachin10 <<a href="mailto:rajesh_sachin10@yahoo.co.in">rajesh_sachin10@yahoo.co.in</a>>:<br>>><br>>><br>
>> Its possible to use 'exists' keyword to get the number of occurance?<br>>><br>>> Eg:<br>>><br>>> context : Context(state == Context:START_UP) exists ClassName(varName ==<br>>> "value")
<br>>><br>>><br>>> The ClassName is an Object array..... So to get the number of occurance<br>>> of<br>>> the "value" in varName, we have any method or keywords?<br>>> --<br>>> View this message in context:
<br>>> <a href="http://www.nabble.com/Usage-of-%27exists%27-keyword-to-get-the-number-of-occurance--tf3853750.html#a10917875">http://www.nabble.com/Usage-of-%27exists%27-keyword-to-get-the-number-of-occurance--tf3853750.html#a10917875
</a><br>>> Sent from the drools - user mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br>>><br>>> _______________________________________________<br>>> rules-users mailing list
<br>>> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
<br>>><br>><br>><br>><br>> --<br>> Edson Tirelli<br>> Software Engineer - JBoss Rules Core Developer<br>> Office: +55 11 3529-6000<br>> Mobile: +55 11 9287-5646<br>> JBoss, a division of Red Hat @
<a href="http://www.jboss.com">www.jboss.com</a><br>><br>> _______________________________________________<br>> rules-users mailing list<br>> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org
</a><br>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>><br>><br>Quoted from:<br><a href="http://www.nabble.com/Usage-of-%27exists%27-keyword-to-get-the-number-of-occurance--tf3853750.html#a10918988">
http://www.nabble.com/Usage-of-%27exists%27-keyword-to-get-the-number-of-occurance--tf3853750.html#a10918988</a><br><br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer
<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>