<div>Don&#39;t think procedurally, just write the *rule* for a missing post ;-)</div><div><br></div>rule &quot;missing fence post&quot;<div>when</div><div>    FencePost( $d: distanceFromStart )</div><div>    FencePost( distanceFromStart == $d + 2*FencePost.GAP )<br>
    not FencePost( distanceFromStart == $d + FencePost.GAP )<br>then</div><div>    System.out.println( &quot;Missing: &quot; + ($d + FencePost.GAP) );</div><div>end</div><div><br></div><div>-W<br><br><div class="gmail_quote">
On 9 February 2012 16:41, mikeg <span dir="ltr">&lt;<a href="mailto:mike@thegoldners.com">mike@thegoldners.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I need to write a rule to identify a missing element in a group of facts.<br>
<br>
For example, let us say I want to ensure that my fence has a fence post<br>
every 8 feet.  My fact declaration is as follows:<br>
<br>
declare FencePost<br>
  identifier : String<br>
  distanceFromStart: Long<br>
end<br>
<br>
If I add the following facts into my session:<br>
<br>
FencePost(&quot;a&quot;, 0)<br>
FencePost(&quot;x&quot;, 8)<br>
FencePost(&quot;e&quot;, 24)<br>
<br>
I want a rule that will notify the user that there is a missing fence post<br>
between &quot;x&quot; and &quot;e&quot;.<br>
<br>
I&#39;ve been looking into using &quot;collect&quot; into a TreeSet/TreeMap to get a<br>
collection sorted on the &quot;distanceFromStart&quot;, but I cannot figure out how to<br>
compare adjacent elements in the collection.<br>
<br>
Any ideas?<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/How-do-I-write-a-rule-to-detect-a-missing-value-in-a-group-of-facts-tp3729818p3729818.html" target="_blank">http://drools.46999.n3.nabble.com/How-do-I-write-a-rule-to-detect-a-missing-value-in-a-group-of-facts-tp3729818p3729818.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">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>