Given your enum, this .drl<br><br>declare Step<br>   id: String<br>   status: Status<br>end<br><br>rule insertion<br>salience ( 10 )<br>when<br>then<br>  Step step = new Step();<br>  step.setId( &quot;One&quot; );<br>  step.setStatus( Status.PENDING );<br>
  insert( step );<br>end<br><br>rule testPending<br>when<br>    $step: Step( status == Status.PENDING )<br>##    $step: Step( status != Status.ACTIVE )<br>##    $step: Step( status.active == false )<br>then<br>    System.out.println( &quot;testPending &quot; + $step.getId() );<br>
end<br><br>and Drools 5.2.0 Final, all three patterns result in a firing of rule testPending.<br><br>-W<br><br><br><div class="gmail_quote">On 26 October 2011 19:38, lhorton <span dir="ltr">&lt;<a href="mailto:LHorton@abclegal.com">LHorton@abclegal.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">5.2.0.Final<br>
<br>
I am seeing some confusing behaviour in enum comparisons in LHS rule<br>
conditions.  I have an enum class, &quot;Status&quot; (full source below) that is an<br>
attribute on several of our domain objects.  I&#39;m comparing the enum in<br>
several ways, and the rule fires differently when I use syntax that AFAIK<br>
ought to have the same result.<br>
<br>
for example, say there is a Step with status of Status.PENDING.  if I write:<br>
<br>
$step : Step(status.active == false)    // rule DOES fire<br>
<br>
$step : Step(status != Status.ACTIVE)    // rule does NOT fire, but should<br>
<br>
I am testing this with the same objects and same test each time.  can anyone<br>
explain why the two comparisons do not get the same result?<br>
<br>
here is the definition of Status:<br>
<br>
public enum Status {<br>
<br>
        PENDING(&quot;Pending&quot;),<br>
        ACTIVE(&quot;Active&quot;),<br>
        COMPLETE(&quot;Complete&quot;);<br>
<br>
        private final String label;<br>
<br>
        private Status(String label) {<br>
                this.label = label;<br>
        }<br>
<br>
        public String getLabel() {<br>
                return label;<br>
        }<br>
<br>
        public boolean isPending(){<br>
                return label.equals(&quot;Pending&quot;);<br>
        }<br>
<br>
        public boolean isActive(){<br>
                return label.equals(&quot;Active&quot;);<br>
        }<br>
<br>
        public boolean isComplete(){<br>
                return label.equals(&quot;Complete&quot;);<br>
        }<br>
<br>
        public static boolean isPending(Status status) {<br>
                return (status == null) ? false : status.isPending();<br>
        }<br>
<br>
        public static boolean isActive(Status status) {<br>
                return (status == null) ? false : status.isActive();<br>
        }<br>
<br>
        public static boolean isComplete(Status status) {<br>
                return (status == null) ? false : status.isComplete();<br>
        }<br>
<br>
        public static Status fromString(String name) {<br>
                if (name != null) {<br>
                        Status types[] = Status.values();<br>
                        for(Status s : types) {<br>
                                if (name.equalsIgnoreCase(s.toString())) {<br>
                                        return s;<br>
                                }<br>
                        }<br>
                }<br>
                return null;<br>
        }<br>
}<br>
<font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/confusing-behaviour-of-enum-comparison-tp3455245p3455245.html" target="_blank">http://drools.46999.n3.nabble.com/confusing-behaviour-of-enum-comparison-tp3455245p3455245.html</a><br>

Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>