[rules-users] Comparing Strings (sort order)
Charles Binford
Charles.Binford at Sun.COM
Thu Jul 3 18:17:51 EDT 2008
I'm trying to figure out how to compare strings in drools. I'd prefer
to just be able to say something like:
when
obj(member > "string")
....
This doesn't work because the > or < operations are not allowed (though
I saw in a May 6th post Edson gave a pointer to how to add it.) Next I
tried using eval(). Based on everything I've read this should work. My
problem is getting the syntax correct. My object "ActionArchive" has a
member called "mediaPool". I'd like to choose the one with the lowest
(alphabetically) mediaPool string.
Try one.....
rule "testme"
when
$ar : ActionArchive($mp : mediaPool)
not (eval (ActionArchive(getMediaPool().CompareTo($mp)) < 0))
then
System.out.println("low mp= " + $ar.getMediaPool());
end
-----------
Rule Compilation error : [Rule name=junk, agendaGroup=MAIN, salience=0,
no-loop=false]
rules/Rule_testme_0.java (8:997) : The method getMediaPool() is
undefined for the type Rule_junk_0
Try two......
rule "testme"
when
$ar : ActionArchive($mp : mediaPool)
not (eval (ActionArchive(mediaPool.CompareTo($mp)) < 0))
then
System.out.println("low mp= " + $ar.getMediaPool());
end
-----------
Rule Compilation error : [Rule name=testme, agendaGroup=MAIN,
salience=0, no-loop=false]
rules/Rule_testme_0.java (8:999) : mediaPool cannot be resolved
Thanks for any pointers.
Charles
p.s. consider this a vote for adding > < support for Strings....
More information about the rules-users
mailing list