[rules-users] Ordered lists in drl

LCode j_whittlesea at hotmail.com
Fri Nov 18 14:18:37 EST 2011


I am trying to write a rule via the guided rule editor and (again!!) I am
really struggling.

The following is a simplified explanation of my scenario:

I have a model where there is one 'Supermarket' object which has a list of
integers 'locationID'. Elsewhere I have another list of 'Place' objects,
each of which has an integer locationReference. 

Something like this....

                <Supermarket name = 'asda'>
                        <LocationID>21</LocationID>
                        <LocationID>18</LocationID>
                        <LocationID>19</LocationID>
                </Supermarket>
		
                <Places>
			<Place>
				<LocationReference>21</LocationReference>
			</Place>
			<Place>
				<LocationReference>18</LocationReference>
			</Place>
			<Place>
				<LocationReference>19</LocationReference>
			</Place>
		</Places>


I need to write a rule that fires when the *order* of locationIDs does not
match the order of the locationReferences. So the above example would be
fine but the model below would not...

                <Supermarket name = 'asda'>
                        <LocationID>18</LocationID>
                        <LocationID>21</LocationID>
                        <LocationID>19</LocationID>
                </Supermarket>
		
                <Places>
			<Place>
				<LocationReference>21</LocationReference>
			</Place>
			<Place>
				<LocationReference>18</LocationReference>
			</Place>
			<Place>
				<LocationReference>19</LocationReference>
			</Place>
		</Places>

I know that drools does not consider the order of facts in the model,
however since both facts are java.util.Lists I wonder if it possible to
compare the elements at position 0, 1, 2 etc. I am afraid my drl skills are
really not up to scratch. 

Any thoughts?

--
View this message in context: http://drools.46999.n3.nabble.com/Ordered-lists-in-drl-tp3519453p3519453.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list