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