thanks Davide. that was really helping.
i get the output displayed twice.
what can i do about it.
On Fri, Feb 28, 2014 at 8:50 PM, Davide Sottara <dsotty(a)gmail.com> wrote:
There are a few errors in the rules
1)
not FileData( fileOld == fileNew )
will fire either 1) when there is a FileData with different lists OR 2)
when there is no FileData at all in the workingMemory
2)
the rule should not compile, unless fileOld and fileNew are STATIC fields
of the class FileData. Is this the case? If so, why?
The problem is that the rule will fire also when there is no FileData in
the WM, so calling the function there is pointless
Your rule should be rewritten as : (notice that the != operator is
overloaded, so it correctly computes "not equals")
FileData( fileOld != fileNew )
3) To do what you want, you don't even need the function - if you prefer
to use functions and code, consider dropping Drools.
A possible rule-based approach to your problem is this:
rule "Deltas"
when
FileData( $old : fileOld, $new : fileNew, fileOld != fileNew )
accumulate( $s : String( this not memberOf $old ) from $new, $plus :
collectList( $s ) )
accumulate( $t : String( this not memberOf $new ) from $old, $mins :
collectList( $t ) )
then
System.out.println( $plus );
System.out.println( $mins );
end
The other rule is fine.
Best
Davide
On 02/28/2014 09:54 AM, Sandhya Sree wrote:
hi,
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.
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.
here is my rule file:
rule "files are equal"
when
FileData(fileOld == fileNew)
then
System.out.println("files are equal");
end
rule "files not equal"
when
not FileData(fileOld == fileNew)
then
System.out.println("files are not equal");
difference(FileData.getFileOld(),FileData.getFileNew());
end
function void difference(List fileOld, List fileNew)
{
ArrayList<String> add = new ArrayList<String>(fileNew);
add.removeAll(fileOld);
System.out.println("files Added: " + add);
ArrayList<String> remove = new ArrayList<String>(fileOld);
remove.removeAll(fileNew);
System.out.println("files Removed: " + remove);
}
but this displays the following error...
Rule Compilation error : [Rule name='files not equal']
Cannot make a static reference to the non-static method getFileOld() from
the type FileData
Cannot make a static reference to the non-static method getFileNew() from
the type FileData
what can be done??
_______________________________________________
rules-users mailing
listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users