<div dir="ltr">thanks Davide. that was really helping. <div>i get the output displayed twice. </div><div>what can i do about it.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 28, 2014 at 8:50 PM, Davide Sottara <span dir="ltr">&lt;<a href="mailto:dsotty@gmail.com" target="_blank">dsotty@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <div>There are a few errors in the rules<br>
      <br>
      1)<br>
      not FileData( fileOld == fileNew )<br>
      will fire either 1) when there is a FileData with different lists
      OR 2) when there is no FileData at all in the workingMemory<br>
      <br>
      2)<br>
      the rule should not compile, unless fileOld and fileNew are STATIC
      fields of the class FileData. Is this the case? If so, why?<br>
      The problem is that the rule will fire also when there is no
      FileData in the WM, so calling the function there is pointless<br>
      <br>
      Your rule should be rewritten as : (notice that the != operator is
      overloaded, so it correctly computes &quot;not equals&quot;)<br>
      <br>
      FileData( fileOld != fileNew )<br>
      <br>
      3) To do what you want, you don&#39;t even need the function - if you
      prefer to use functions and code, consider dropping Drools.<br>
      A possible rule-based approach to your problem is this:<br>
      <br>
      <tt>rule &quot;Deltas&quot;</tt><tt><br>
      </tt><tt>when</tt><tt><br>
      </tt><tt>    FileData( $old : fileOld, $new : fileNew, fileOld !=
        fileNew ) </tt><tt><br>
      </tt><tt>    accumulate( $s : String( this not memberOf $old )
        from $new, $plus : collectList( $s ) ) </tt><tt><br>
      </tt><tt>    accumulate( $t : String( this not memberOf $new )
        from $old, $mins : collectList( $t ) ) </tt><tt><br>
      </tt><tt>then</tt><tt><br>
      </tt><tt>    System.out.println( $plus ); </tt><tt><br>
      </tt><tt>    System.out.println( $mins );</tt><tt><br>
      </tt><tt>end</tt><br>
      <br>
      The other rule is fine.<br>
      <br>
      Best<span class="HOEnZb"><font color="#888888"><br>
      Davide</font></span><div><div class="h5"><br>
      <br>
      <br>
      On 02/28/2014 09:54 AM, Sandhya Sree wrote:<br>
    </div></div></div>
    <blockquote type="cite"><div><div class="h5">
      <div dir="ltr">hi,
        <div>im new to drools..im trying to create a project as follows.
          i have a class called Monitor  which monitors a folder and
          creates two lists called fileOld( which is the list of
          filenames in that folder at time t1)  and fileNew(which is the
          list of filenames in that folder at time t2). i have another
          class called FileData which contains two members fileOld and
          fileNew (list of strings) with getters,setters and
          constructor. fileOld and fileNew from Monitor Class are passed
          to FileData class.</div>
        <div><br>
        </div>
        <div>now i have to compare these two lists in a rule file and if
          they are not equal i have to print the lists of files added/
          deleted. how to do this in drools.</div>
        <div><br>
        </div>
        <div>here is my rule file:</div>
        <div><br>
        </div>
        <div>
          <div>rule &quot;files are equal&quot;</div>
          <div> </div>
          <div>    when </div>
          <div>        FileData(fileOld == fileNew)        </div>
          <div>        </div>
          <div>    then</div>
          <div>       System.out.println(&quot;files are equal&quot;);</div>
          <div>       </div>
          <div><br>
          </div>
          <div>end</div>
          <div><br>
          </div>
          <div>rule &quot;files not equal&quot;</div>
          <div><br>
          </div>
          <div>  when</div>
          <div>        not FileData(fileOld == fileNew)</div>
          <div>    then</div>
          <div>       System.out.println(&quot;files are not equal&quot;);</div>
          <div>     
             difference(FileData.getFileOld(),FileData.getFileNew()); </div>
          <div><br>
          </div>
          <div>end</div>
          <div><br>
          </div>
          <div><br>
          </div>
          <div>function void difference(List fileOld, List fileNew)</div>
          <div>{</div>
          <div>      </div>
          <div><br>
          </div>
          <div><span style="white-space:pre-wrap"> </span>  
            ArrayList&lt;String&gt; add = new
            ArrayList&lt;String&gt;(fileNew);</div>
          <div><span style="white-space:pre-wrap"> </span>  
            add.removeAll(fileOld);</div>
          <div><span style="white-space:pre-wrap"> </span>  
            System.out.println(&quot;files Added: &quot; + add);</div>
          <div><br>
          </div>
          <div><span style="white-space:pre-wrap"> </span>  
            ArrayList&lt;String&gt; remove = new
            ArrayList&lt;String&gt;(fileOld);</div>
          <div><span style="white-space:pre-wrap"> </span>  
            remove.removeAll(fileNew);</div>
          <div><span style="white-space:pre-wrap"> </span>  
            System.out.println(&quot;files Removed: &quot; + remove);</div>
          <div>}   </div>
          <div>
                   </div>
        </div>
        <div><br>
        </div>
        <div>but this displays the following error...</div>
        <div><br>
        </div>
        <div>
          <div>Rule Compilation error : [Rule name=&#39;files not equal&#39;]</div>
          <div>Cannot make a static reference to the non-static method
            getFileOld() from the type FileData</div>
          <div>Cannot make a static reference to the non-static method
            getFileNew() from the type FileData</div>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>what can be done??</div>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><div class=""><pre>_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a></pre>
    </div></blockquote>
    <br>
  </div>

<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></blockquote></div><br></div>