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-...
Sent from the Drools: User forum mailing list archive at
Nabble.com.