Hi,<br><br>You have to &quot;let go&quot; of the need to explicitly iterate collections within rules.<br><br>You wouldn&#39;t normally think about iterating all records yourself in a database when performing a SQL statement like this:-<br>
<br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">select sum(ch.claimAmount) as total from claim c, claimHistory ch where c.claimId = ch.fk_claimId;</span><br style="font-family: courier new,monospace;">
</div><br>So your rules can work in much the same way:-<br><br style="font-family: courier new,monospace;"><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">global Long total;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">when</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    $c : Claim()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    $h : ClaimHistory( claimId == $c.claimId )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">then</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    total = total + $h.getClaimAmount();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">end</span><br>
</div><br>This rule will activate for every combination of Claim and ClaimHistory (where claim ID&#39;s match) in Working Memory.<br><br>Relating this to your example you should be able to do the following:-<br><br><span style="font-family: courier new,monospace;">when</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    $c : DURClaim()<br>    $ch : ClaimsHistory()<br>    $h : DURClaim() from $ch.getHistory()<br>then</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    //Do some computation involving $c and $h</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">end</span><br><br>This will match on every combination of DURClaim and ClaimsHistory&#39;s DURClaim in Working Memory. AFAIK Drools does not support Java&#39;s generics in pattern matching so I have shown use of &quot;ClaimsHistory&quot; rather than using &quot;List&quot; to prevent matching on any other List you may have in WM. Obviously you&#39;d need to insert &quot;claims&quot; into WM not &quot;historyClaims&quot;.<br>
<span style="font-family: courier new,monospace;"></span><br>If ClaimsHistory.getHistory returned a List of objects of a class other than DURClaim you could have used the option to explode the list first using a higher salience rule (as in my earlier email) however, in your case, it&#39;d be difficult to prevent matching between different instances of DURClaim that represent different &quot;inClaim&quot; objects if the rule simply contained two &quot;DURClaim&quot; patterns.<br>
<br>With kind regards,<br><br>Mike<br><br><div class="gmail_quote">On 5 May 2011 13:03, sdinoo <span dir="ltr">&lt;<a href="mailto:sdinoo@gmail.com">sdinoo@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi Michael<br>
<br>
Thank you for helping me out - but I need some more help<br>
<br>
Pardon my ignorance, but I am still not clear how this can be done<br>
I am looking for something in the language that will allow me to iterate<br>
through the entire List/Vector object by object and then access each object<br>
instances values like Object.getClaimAmount<br>
<br>
Here is my calling program<br>
        public static final void main(String[] args) {<br>
                DURUtils rc = new DURUtils();<br>
<br>
                //Load the claims from CSV into History<br>
                ClaimsHistory claims = new ClaimsHistory();<br>
                List&lt;DurClaim&gt; historyClaims = claims.getHistory();<br>
                System.out.println(&quot;List Size = &quot; + historyClaims.size());<br>
<br>
                //Create a New Incoming object<br>
                IncomingClaim ic = new IncomingClaim();<br>
                DurClaim inClaim = ic.getIncomingClaim();<br>
<br>
        try {<br>
                        // load up the knowledge base<br>
                        KnowledgeBase kbase = readKnowledgeBase();<br>
                        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();<br>
                        KnowledgeRuntimeLogger logger =<br>
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, &quot;test&quot;);<br>
                        // start a new process instance<br>
                        ksession.insert(inClaim);<br>
                        ksession.insert(historyClaims);<br>
                        ksession.startProcess(&quot;com.drughistory&quot;);<br>
                        ksession.fireAllRules();<br>
                        logger.close();<br>
                } catch (Throwable t) {<br>
                        t.printStackTrace();<br>
                }<br>
<br>
                }<br>
<br>
        private static KnowledgeBase readKnowledgeBase() throws Exception {<br>
                KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
<br>
kbuilder.add(ResourceFactory.newClassPathResource(&quot;trials/ClaimProcessing.bpmn&quot;),<br>
ResourceType.BPMN2);<br>
                //kbuilder.add(ResourceFactory.newClassPathResource(&quot;DurClaimRules.drl&quot;),<br>
ResourceType.DRL);<br>
                kbuilder.add(ResourceFactory.newClassPathResource(&quot;trials/History.drl&quot;),<br>
ResourceType.DRL);<br>
                return kbuilder.newKnowledgeBase();<br>
        }<br>
<br>
All I want to do is some computation using the<br>
incomingClaim with a List of the historyClaims<br>
The incoming claim and the historyclaims are of the same model claim called<br>
DURClaim<br>
<br>
Again, this may be a very elemental question but I thought there would be an<br>
easier way of doing this as I would like to keep the iteration processing in<br>
the rule rather than outside in a Java Class<br>
<font color="#888888"><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Looping-through-a-vector-object-in-a-rule-tp2897872p2903115.html" target="_blank">http://drools.46999.n3.nabble.com/Looping-through-a-vector-object-in-a-rule-tp2897872p2903115.html</a><br>

</font><div><div></div><div class="h5">Sent from the Drools: User forum mailing list archive at Nabble.com.<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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>