<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">The "accumulates" should not be in the
"then" 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 "new file"</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><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'll need another rule for the files that have been removed.<br>
<br>
Notice that your Event class has no way to distinguish "added"
from "removed" files, you may want to<br>
add a boolean or something there.<br>
Best<br>
Davide<br>
<br>
On 03/10/2014 07:04 PM, Sandhya Sree wrote:<br>
</div>
<blockquote
cite="mid:CAJftt0EDJi-AKiYfjpHnzVPUprtntAaVb0i=dJrAzJNFiK4JNg@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 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 class="" style="white-space:pre"> </span></div>
<div><span class="" style="white-space:pre"> </span> public
static String name;</div>
<div><span class="" style="white-space:pre"> </span> private
File source;</div>
<div><span class="" style="white-space:pre"> </span> private
Date timeStamp;</div>
<div> public static List<Event> listOfEvents =
new ArrayList<Event>();</div>
<div><span class="" style="white-space:pre"> </span></div>
<div><span class="" style="white-space:pre"> </span> </div>
<div><span class="" style="white-space:pre"> </span>public
Event(String name, File source, Date timeStamp) {</div>
<div><span class="" style="white-space:pre"> </span><a
moz-do-not-send="true" href="http://this.name">this.name</a>
= name;</div>
<div><span class="" style="white-space:pre"> </span>this.source
= source;</div>
<div><span class="" style="white-space:pre"> </span>this.timeStamp
= timeStamp;</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span></div>
<div><span class="" style="white-space:pre"> </span></div>
<div><span class="" style="white-space:pre"> </span>public
String getName() {</div>
<div><span class="" style="white-space:pre"> </span>return
name;</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>public
void setName(String name) {</div>
<div><span class="" style="white-space:pre"> </span><a
moz-do-not-send="true" href="http://this.name">this.name</a>
= name;</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>public
File getSource() {</div>
<div><span class="" style="white-space:pre"> </span>return
source;</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>public
void setSource(File source) {</div>
<div><span class="" style="white-space:pre"> </span>this.source
= source;</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>public
Date getTimeStamp() {</div>
<div><span class="" style="white-space:pre"> </span>return
timeStamp;</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </span>public
void setTimeStamp(Date timeStamp) {</div>
<div><span class="" style="white-space:pre"> </span>this.timeStamp
= timeStamp;</div>
<div><span class="" style="white-space:pre"> </span>}</div>
<div><span class="" style="white-space:pre"> </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<Event> 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 "files are equal"</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("files are equal");</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 "files not equal"</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("files added:" + $plus ); </font></div>
<div><font face="arial, sans-serif"> System.out.println(
"files deleted:" + $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<Event> listOfEvents..</div>
<div><br>
</div>
<div><br>
</div>
<div>Thanks.</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>