[rules-users] Collecting properties in a rule

LCode j_whittlesea at hotmail.com
Sat Nov 12 18:15:49 EST 2011


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.



More information about the rules-users mailing list