<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">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 "not equals")<br>
      <br>
      FileData( fileOld != fileNew )<br>
      <br>
      3) To do what you want, you don'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 "Deltas"</tt><tt><br>
      </tt><tt>when</tt><tt><br>
      </tt><tt>&nbsp;&nbsp;&nbsp; FileData( $old : fileOld, $new : fileNew, fileOld !=
        fileNew ) </tt><tt><br>
      </tt><tt>&nbsp;&nbsp;&nbsp; accumulate( $s : String( this not memberOf $old )
        from $new, $plus : collectList( $s ) ) </tt><tt><br>
      </tt><tt>&nbsp;&nbsp;&nbsp; accumulate( $t : String( this not memberOf $new )
        from $old, $mins : collectList( $t ) ) </tt><tt><br>
      </tt><tt>then</tt><tt><br>
      </tt><tt>&nbsp;&nbsp;&nbsp; System.out.println( $plus ); </tt><tt><br>
      </tt><tt>&nbsp;&nbsp;&nbsp; System.out.println( $mins );</tt><tt><br>
      </tt><tt>end</tt><br>
      <br>
      The other rule is fine.<br>
      <br>
      Best<br>
      Davide<br>
      <br>
      <br>
      On 02/28/2014 09:54 AM, Sandhya Sree wrote:<br>
    </div>
    <blockquote
cite="mid:CAJftt0E+P8vz6UdGGQQ35RCeGkORDFLB=NCE-RUbFm9ZKhjv_A@mail.gmail.com"
      type="cite">
      <div dir="ltr">hi,
        <div>im new to drools..im trying to create a project as follows.
          i have a class called Monitor &nbsp;which monitors a folder and
          creates two lists called fileOld( which is the list of
          filenames in that folder at time t1) &nbsp;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 "files are equal"</div>
          <div>&nbsp;</div>
          <div>&nbsp; &nbsp; when&nbsp;</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; FileData(fileOld == fileNew) &nbsp; &nbsp; &nbsp; &nbsp;</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div>
          <div>&nbsp; &nbsp; then</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp;System.out.println("files are equal");</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp;</div>
          <div><br>
          </div>
          <div>end</div>
          <div><br>
          </div>
          <div>rule "files not equal"</div>
          <div><br>
          </div>
          <div>&nbsp; when</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; not FileData(fileOld == fileNew)</div>
          <div>&nbsp; &nbsp; then</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp;System.out.println("files are not equal");</div>
          <div>&nbsp; &nbsp; &nbsp;
            &nbsp;difference(FileData.getFileOld(),FileData.getFileNew());&nbsp;</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>&nbsp; &nbsp; &nbsp;&nbsp;</div>
          <div><br>
          </div>
          <div><span class="" style="white-space:pre"> </span> &nbsp;
            ArrayList&lt;String&gt; add = new
            ArrayList&lt;String&gt;(fileNew);</div>
          <div><span class="" style="white-space:pre"> </span> &nbsp;
            add.removeAll(fileOld);</div>
          <div><span class="" style="white-space:pre"> </span> &nbsp;
            System.out.println("files Added: " + add);</div>
          <div><br>
          </div>
          <div><span class="" style="white-space:pre"> </span> &nbsp;
            ArrayList&lt;String&gt; remove = new
            ArrayList&lt;String&gt;(fileOld);</div>
          <div><span class="" style="white-space:pre"> </span> &nbsp;
            remove.removeAll(fileNew);</div>
          <div><span class="" style="white-space:pre"> </span> &nbsp;
            System.out.println("files Removed: " + remove);</div>
          <div>} &nbsp;&nbsp;</div>
          <div>
            &nbsp; &nbsp; &nbsp; &nbsp;</div>
        </div>
        <div><br>
        </div>
        <div>but this displays the following error...</div>
        <div><br>
        </div>
        <div>
          <div>Rule Compilation error : [Rule name='files not equal']</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 class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></pre>
    </blockquote>
    <br>
  </body>
</html>