Given your enum, this .drl

declare Step
   id: String
   status: Status
end

rule insertion
salience ( 10 )
when
then
  Step step = new Step();
  step.setId( "One" );
  step.setStatus( Status.PENDING );
  insert( step );
end

rule testPending
when
    $step: Step( status == Status.PENDING )
##    $step: Step( status != Status.ACTIVE )
##    $step: Step( status.active == false )
then
    System.out.println( "testPending " + $step.getId() );
end

and Drools 5.2.0 Final, all three patterns result in a firing of rule testPending.

-W


On 26 October 2011 19:38, lhorton <LHorton@abclegal.com> wrote:
5.2.0.Final

I am seeing some confusing behaviour in enum comparisons in LHS rule
conditions.  I have an enum class, "Status" (full source below) that is an
attribute on several of our domain objects.  I'm comparing the enum in
several ways, and the rule fires differently when I use syntax that AFAIK
ought to have the same result.

for example, say there is a Step with status of Status.PENDING.  if I write:

$step : Step(status.active == false)    // rule DOES fire

$step : Step(status != Status.ACTIVE)    // rule does NOT fire, but should

I am testing this with the same objects and same test each time.  can anyone
explain why the two comparisons do not get the same result?

here is the definition of Status:

public enum Status {

       PENDING("Pending"),
       ACTIVE("Active"),
       COMPLETE("Complete");

       private final String label;

       private Status(String label) {
               this.label = label;
       }

       public String getLabel() {
               return label;
       }

       public boolean isPending(){
               return label.equals("Pending");
       }

       public boolean isActive(){
               return label.equals("Active");
       }

       public boolean isComplete(){
               return label.equals("Complete");
       }

       public static boolean isPending(Status status) {
               return (status == null) ? false : status.isPending();
       }

       public static boolean isActive(Status status) {
               return (status == null) ? false : status.isActive();
       }

       public static boolean isComplete(Status status) {
               return (status == null) ? false : status.isComplete();
       }

       public static Status fromString(String name) {
               if (name != null) {
                       Status types[] = Status.values();
                       for(Status s : types) {
                               if (name.equalsIgnoreCase(s.toString())) {
                                       return s;
                               }
                       }
               }
               return null;
       }
}


--
View this message in context: http://drools.46999.n3.nabble.com/confusing-behaviour-of-enum-comparison-tp3455245p3455245.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users