There are a few errors in the rules
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
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:
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 ) )
System.out.println( $plus );
System.out.println( $mins );
The other rule is fine.
On 02/28/2014 09:54 AM, Sandhya Sree wrote:
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
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"
FileData(fileOld == fileNew)
System.out.println("files are equal");
rule "files not equal"
not FileData(fileOld == fileNew)
System.out.println("files are not equal");
function void difference(List fileOld, List fileNew)
ArrayList<String> add = new ArrayList<String>(fileNew);
System.out.println("files Added: " + add);
ArrayList<String> remove = new ArrayList<String>(fileOld);
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 list