The rule below assumes that markets is List&lt;Market&gt; in Town and ids is List&lt;Integer&gt; in a Market.<br><br>It does not rely on Market or even Location objects being facts, and there&#39;s no problem if a location id is re-used in another town.<br>
<br>rule findThree<br>when<br>    $t: Town( $name: name, $markets: markets )<br>    $s: HashSet( $size: size ==3 )<br>            from accumulate( $m: Market() from $markets,<br>                             init( HashSet set = new HashSet(); )<br>
                             action( set.addAll( $m.getIds() ); )<br>                             result( set ) )<br>then<br>    System.out.println( $name + &quot; is a three-location town &quot; + $s );<br>end<br><br><br>
<div class="gmail_quote">2011/11/14 Michael Anstis <span dir="ltr">&lt;<a href="mailto:michael.anstis@gmail.com">michael.anstis@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Something like this?<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;">    $t : Town( )</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    $s : SuperMarket( town == $t, $lid : locationId )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    $ls : HashSet( size == 3) from ( Location( locationId = $lid ) )</span><br style="font-family: courier new,monospace;">

<br>I suspect Location would have to override equals and hashCode correctly.<br><br>Once you have some DRL that works I&#39;d suggest moving to Guvnor.<div><div></div><div class="h5"><br><br><div class="gmail_quote">On 12 November 2011 23:15, LCode <span dir="ltr">&lt;<a href="mailto:j_whittlesea@hotmail.com" target="_blank">j_whittlesea@hotmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I am trying to write a rule via the guided rule editor and I am really<br>
struggling.<br>
<br>
The following is a simplified explanation of my scenario:<br>
<br>
I have a model where there are lots of &#39;Town&#39; objects, each town has any<br>
number of &#39;Supermarket&#39; objects and each supermarket has a list of integers<br>
&#39;locationID&#39;.<br>
<br>
Something like this....<br>
<br>
        &lt;Town&gt;<br>
                &lt;Supermarket name = &#39;asda&#39;&gt;<br>
                        &lt;LocationID&gt;15&lt;/LocationID&gt;<br>
                        &lt;LocationID&gt;18&lt;/LocationID&gt;<br>
                &lt;/Supermarket&gt;<br>
                &lt;Supermarket name = &#39;tesco&#39;&gt;<br>
                        &lt;LocationID&gt;13&lt;/LocationID&gt;<br>
                &lt;/Supermarket&gt;<br>
                &lt;Supermarket name = &#39;lidl&#39;&gt;<br>
                        &lt;LocationID&gt;13&lt;/LocationID&gt;<br>
                        &lt;LocationID&gt;15&lt;/LocationID&gt;<br>
                        &lt;LocationID&gt;18&lt;/LocationID&gt;<br>
                &lt;/Supermarket&gt;<br>
        &lt;/Town&gt;<br>
<br>
(apologies to the Sainsburys shoppers!!)<br>
<br>
I need to write a rule that fires when there are precisely 3 unique location<br>
ID&#39;s in the whole town.<br>
<br>
So in the example above the complete list of locationIDs would be 13, 13,<br>
15, 15, 18, 18<br>
With the following unique numbers 13, 15, 18<br>
therefore the rule would fire as there are 3 unique numbers.<br>
<br>
I hope that makes some sense.<br>
<br>
I understand that I should collect the locationIDs into a java.util.Set in<br>
order to count unique entries and I can collect together all supermarkets<br>
into an arraylist. However I cannot for the life of me seem to collect<br>
LocationID across all supermarkets.<br>
<br>
Thank you so much in anticipation, I realise this was rather long-winded!<br>
<span><font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Collecting-properties-in-a-rule-tp3503523p3503523.html" target="_blank">http://drools.46999.n3.nabble.com/Collecting-properties-in-a-rule-tp3503523p3503523.html</a><br>


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" target="_blank">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>
</font></span></blockquote></div><br>
</div></div><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>
<br></blockquote></div><br>