<div dir="ltr">The problem here is even if multiple files are added, there is only one event object created. i want to have like say if 3 new files are added, 3 event objects must be created, and all three event objects must be added to List&lt;Event&gt; listOfEvents. <div>
<br></div><div><br></div><div>Thanks.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 10, 2014 at 11:48 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>The &quot;accumulates&quot; should not be in the
      &quot;then&quot; part of a rule (see my previous email).<br>
      That rule gave you two lists, in the variables $plus and $mins,
      that you can use in the consequence.<br>
      <br>
      If you need to process each file separately, you may want to do
      something like this:<br>
      <br>
      <div><font face="arial, sans-serif">rule &quot;new file&quot;</font></div><div class="">
      <div><font face="arial, sans-serif">when</font></div>
      <div><font face="arial, sans-serif">    FileData($old : fileOld,
          $new : fileNew, fileOld != fileNew)</font></div>
      </div><div><font face="arial, sans-serif">   </font><font face="arial,
          sans-serif"><font face="arial, sans-serif"> $newFile : String(
            this not memberOf $old ) from $new</font><br>
        </font></div>
      <div>
        <font face="arial, sans-serif">then   <br>
             // create new event for a new file : new Event(...)<br>
             // add to list : Event.listOfEvents.add(...)<br>
        </font></div>
      <font face="arial, sans-serif">end</font>
      <div><br>
      </div>
      You&#39;ll need another rule for the files that have been removed.<br>
      <br>
      Notice that your Event class has no way to distinguish &quot;added&quot;
      from &quot;removed&quot; files, you may want to<br>
      add a boolean or something there.<br>
      Best<br>
      Davide<div><div class="h5"><br>
      <br>
      On 03/10/2014 07:04 PM, 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>i also have another class called Event which is as follows:</div>
        <div>
          <div>public class Event {</div>
          <div><span style="white-space:pre-wrap"> </span></div>
          <div><span style="white-space:pre-wrap"> </span> public
            static String name;</div>
          <div><span style="white-space:pre-wrap"> </span> private
             File source;</div>
          <div><span style="white-space:pre-wrap"> </span> private
             Date timeStamp;</div>
          <div>        public  static  List&lt;Event&gt; listOfEvents =
            new ArrayList&lt;Event&gt;();</div>
          <div><span style="white-space:pre-wrap"> </span></div>
          <div><span style="white-space:pre-wrap"> </span> </div>
          <div><span style="white-space:pre-wrap"> </span>public
            Event(String name, File source, Date timeStamp) {</div>
          <div><span style="white-space:pre-wrap"> </span><a href="http://this.name" target="_blank">this.name</a>
            = name;</div>
          <div><span style="white-space:pre-wrap"> </span>this.source
            = source;</div>
          <div><span style="white-space:pre-wrap"> </span>this.timeStamp
            = timeStamp;</div>
          <div><span style="white-space:pre-wrap"> </span>}</div>
          <div><span style="white-space:pre-wrap"> </span></div>
          <div><span style="white-space:pre-wrap"> </span></div>
          <div><span style="white-space:pre-wrap"> </span>public
            String getName() {</div>
          <div><span style="white-space:pre-wrap"> </span>return
            name;</div>
          <div><span style="white-space:pre-wrap"> </span>}</div>
          <div><span style="white-space:pre-wrap"> </span>public
            void setName(String name) {</div>
          <div><span style="white-space:pre-wrap"> </span><a href="http://this.name" target="_blank">this.name</a>
            = name;</div>
          <div><span style="white-space:pre-wrap"> </span>}</div>
          <div><span style="white-space:pre-wrap"> </span>public
            File getSource() {</div>
          <div><span style="white-space:pre-wrap"> </span>return
            source;</div>
          <div><span style="white-space:pre-wrap"> </span>}</div>
          <div><span style="white-space:pre-wrap"> </span>public
            void setSource(File source) {</div>
          <div><span style="white-space:pre-wrap"> </span>this.source
            = source;</div>
          <div><span style="white-space:pre-wrap"> </span>}</div>
          <div><span style="white-space:pre-wrap"> </span>public
            Date getTimeStamp() {</div>
          <div><span style="white-space:pre-wrap"> </span>return
            timeStamp;</div>
          <div><span style="white-space:pre-wrap"> </span>}</div>
          <div><span style="white-space:pre-wrap"> </span>public
            void setTimeStamp(Date timeStamp) {</div>
          <div><span style="white-space:pre-wrap"> </span>this.timeStamp
            = timeStamp;</div>
          <div><span style="white-space:pre-wrap"> </span>}</div>
          <div><span style="white-space:pre-wrap"> </span></div>
        </div>
        <div><br>
        </div>
        <div>now i have to compare these two lists(fileOld and fileNew)
          in a rule file and if they are not equal i have to create an
          event object for every file added and deleted and put it in
          the List&lt;Event&gt; listOfEvents.</div>
        <div><br>
        </div>
        <div>here is my rule file:</div>
        <div><br>
        </div>
        <div>
          <div><span style="font-family:arial,sans-serif;font-size:13px">r</span><font face="arial, sans-serif">rule &quot;files are equal&quot;</font></div>
          <div><span style="font-family:arial,sans-serif">    when </span></div>
          <div><font face="arial, sans-serif">         FileData( fileOld
              == fileNew)</font></div>
          <div><font face="arial, sans-serif">    then</font></div>
          <div><font face="arial, sans-serif">     
               System.out.println(&quot;files are equal&quot;);</font></div>
          <div><font face="arial, sans-serif">    </font><span style="font-family:arial,sans-serif">end</span></div>
          <div><font face="arial, sans-serif"><br>
            </font></div>
          <div><font face="arial, sans-serif"><br>
            </font></div>
          <div><font face="arial, sans-serif">rule &quot;files not equal&quot;</font></div>
          <div><font face="arial, sans-serif">when</font></div>
          <div><font face="arial, sans-serif">    FileData($old :
              fileOld, $new : fileNew, fileOld != fileNew)</font></div>
          <div><font face="arial, sans-serif">    </font></div>
          <div>
            <font face="arial, sans-serif">then</font></div>
          <div><font face="arial, sans-serif">   accumulate( $s :
              String( this not memberOf $old ) from $new, $plus :
              collectList( $s ) ) </font></div>
          <div><font face="arial, sans-serif">   accumulate( $t :
              String( this not memberOf $new ) from $old, $mins :
              collectList( $t ) ) </font></div>
          <div><font face="arial, sans-serif"> 
               System.out.println(&quot;files added:&quot; + $plus ); </font></div>
          <div><font face="arial, sans-serif">   System.out.println(
              &quot;files deleted:&quot; + $mins );</font></div>
          <div>
            <font face="arial, sans-serif">end</font></div>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>how can i loop through each of the file added or deleted
          and create an Event Class object for every file added and
          deleted  and finally add all the created objects to
          List&lt;Event&gt; listOfEvents..</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>Thanks.</div>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><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>
    </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>