Darko,  thanks for the reply.  I'm new to both JAVA and Drools, so any pointers in either are appreciated.

I was trying to use the compareTo method but can't figure out the right syntax to make drools happy.  In my original examples I was using 'CompareTo' while your answer has lowercase 'c' in 'compareTo'.  In either case I'm still failing to compile.  Using your suggested code I get the following:
    [22,56]: unknown:22:56 Unexpected token '$mp1'

Based on the following from the drools documentation:
6.5.2.1.1.1. JavaBeans as facts
A field is an accessible method on the object. If your model objects follow the java bean pattern, then fields are exposed using "getXXX" or "isXXX" methods (these are methods that take no arguments, and return something). You can access fields either by using the bean-name convention (so "getType" can be accessed as "type") - we use the standard jdk Introspector class to do this mapping.
I didn't think I could use any compare that took an argument unless I used the eval function.

Charles

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@sun.com>
An: rules-users@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@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users