[rules-users] Collecting properties in a rule
Michael Anstis
michael.anstis at gmail.com
Mon Nov 14 03:10:01 EST 2011
Something like this?
when
$t : Town( )
$s : SuperMarket( town == $t, $lid : locationId )
$ls : HashSet( size == 3) from ( Location( locationId = $lid ) )
I suspect Location would have to override equals and hashCode correctly.
Once you have some DRL that works I'd suggest moving to Guvnor.
On 12 November 2011 23:15, LCode <j_whittlesea at hotmail.com> wrote:
> I am trying to write a rule via the guided rule editor and I am really
> struggling.
>
> The following is a simplified explanation of my scenario:
>
> I have a model where there are lots of 'Town' objects, each town has any
> number of 'Supermarket' objects and each supermarket has a list of integers
> 'locationID'.
>
> Something like this....
>
> <Town>
> <Supermarket name = 'asda'>
> <LocationID>15</LocationID>
> <LocationID>18</LocationID>
> </Supermarket>
> <Supermarket name = 'tesco'>
> <LocationID>13</LocationID>
> </Supermarket>
> <Supermarket name = 'lidl'>
> <LocationID>13</LocationID>
> <LocationID>15</LocationID>
> <LocationID>18</LocationID>
> </Supermarket>
> </Town>
>
> (apologies to the Sainsburys shoppers!!)
>
> I need to write a rule that fires when there are precisely 3 unique
> location
> ID's in the whole town.
>
> So in the example above the complete list of locationIDs would be 13, 13,
> 15, 15, 18, 18
> With the following unique numbers 13, 15, 18
> therefore the rule would fire as there are 3 unique numbers.
>
> I hope that makes some sense.
>
> I understand that I should collect the locationIDs into a java.util.Set in
> order to count unique entries and I can collect together all supermarkets
> into an arraylist. However I cannot for the life of me seem to collect
> LocationID across all supermarkets.
>
> Thank you so much in anticipation, I realise this was rather long-winded!
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Collecting-properties-in-a-rule-tp3503523p3503523.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111114/c9c00042/attachment.html
More information about the rules-users
mailing list