Hi Charles,
This sounds rather like a JAVA question, but well
1. You should use the compareTo method, inherited from Comparable.
2. about the rules itself, it should be more something like
$A1 : ActionArchive($mp1 : mediaPool);
$A2 : ActionArchive(this != $A1, mediaPool.compareTo($mp1) < 0);
3. Having a huge number of actionArchives, you might want to consider storing them as an
arra in a global variable and using the from operator in your rule.
Hope this helps,
Darko
-------- Original-Nachricht --------
Datum: Thu, 03 Jul 2008 17:17:51 -0500
Von: Charles Binford <Charles.Binford(a)sun.com>
An: rules-users(a)lists.jboss.org
Betreff: [rules-users] Comparing Strings (sort order)
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....
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein:
http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx