<br>&nbsp;&nbsp;&nbsp; It all depends on how many simultaneous instances you have in your working memory. If you have just a few instances, a simple and single rule can handle your case... you don&#39;t need to check for nulls, unless you want to explicitly handle them:
<br><br>rule &quot;Overlapping Dates&quot;<br>&nbsp;&nbsp; when<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $a : Address (&nbsp; )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $b : Address ( this != $a, beginDate &gt; $a.beginDate, beginDate &lt; $a.endDate )<br>&nbsp;&nbsp; then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // $a and $b overlap<br>end
<br><br>&nbsp;&nbsp;&nbsp; Now, I had to do the same thing for a system that handled telecom calls and we had hundreds of thousands of call objects at once in the working memory. As you may be aware, rules like the one above have the potential to generate combinatorial explosions. In my case, I created a high performance data structure to index the dates and detect the overlaps and used the rules only to drive the execution (of course, there were hundreds of other rules doing other things too). This way I avoided the combinatorial explosion.
<br><br>&nbsp;&nbsp;&nbsp; Hope it helps.<br><br>&nbsp;&nbsp;&nbsp; Edson<br><br><div><span class="gmail_quote">2007/8/29, Brian Enderle &lt;<a href="mailto:brianke@gmail.com">brianke@gmail.com</a>&gt;:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have a situation where I need to check for overlapping dates in a collection<br>of previous addresses.&nbsp;&nbsp;I am only performing this check after checking that<br>the beginDate and endDate are not null.<br><br>Currently I am using an eval to perform an outside method.&nbsp;&nbsp;Does anyone know
<br>if and how I could perform this same check using Drools.<br><br>Curently my rules look something like this<br><br>gloabl java.lang.Boolean dateErrorExists;&nbsp;&nbsp; // starts off as false<br>global ValidationUtils utils;<br>
<br>rule &quot;beginDate must exist&quot;<br>&nbsp;&nbsp; when<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Address ( beginDate != null )<br>&nbsp;&nbsp; then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dateMissing = true;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;display error&gt;<br>end<br><br>rule &quot;endDate must exist&quot;<br>&nbsp;&nbsp; when
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Address ( endDate != null )<br>&nbsp;&nbsp; then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dateMissing = true;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;display error&gt;<br>end<br><br>rule &quot;Previous Address dates cannot overlap&quot;<br>&nbsp;&nbsp; salience -10<br>&nbsp;&nbsp; when<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eval (dateMissing)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eval (utils.doAddressDatesOverlap())<br>&nbsp;&nbsp; then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;display error&gt;<br>end<br><br>Our system simply runs thru the data checking the rules (no facts are changed)<br>so the dateMissing global is reset to false everytime we perform our
<br>validation.<br><br>The downside to this is I am having to re-get the data from the DB within the<br>doAddressDatesOverlap() function.&nbsp;&nbsp;This function orders the Address objects by<br>their startDates and then compares the endDate of one with the startDate of
<br>the next and returns false if they overlap.<br><br>If anyone knows of a cleaner, simpler or better way to perform this check<br>within Drools I would appreciate the input.<br><br>Thanks in advance,<br>Brian Enderle<br>
<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">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br><br clear="all"><br>-- <br>&nbsp;&nbsp;Edson Tirelli<br>&nbsp;&nbsp;Software Engineer - JBoss Rules Core Developer<br>&nbsp;&nbsp;Office: +55 11 3529-6000<br>&nbsp;&nbsp;Mobile: +55 11 9287-5646
<br>&nbsp;&nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>