I tried to use Enum on LHS [ Ticket(status == EStatus.OK) ], I get compile time error something like following:
BuildError: Unable to Analyse Expression status == EStatus.OK
Error: unable to resolve method using strict-mode:....
Solution:
In rule LHS, we have to compare with a Constant value... for example: user : User(age > 60) - here we are comparing age with Constant value 60.
So for using Enum, Ticket(status == EStatus.OK)... I had to use some constant in place of EStatus.OK to compare this with status. For this reason, I used one static method in Enum.
So, the LHS of rule now looks like: Ticket(status == EStatus.getEStatus(1))
and EStatus enum is like following:
public enum EStatus
{
// you can use values other than int also
OK(1),
ERROR(2);
private int value;
EStatus(int number)
{
this.value = number;
}
public int valueOf()
{
return this.value;
}
public static EStatus getEStatus(int value){
EStatus eStatus = null;
for(EStatus e : EStatus.values()){
if(e.valueOf() == value){
eStatus = d;
break;
}
}
return eStatus;
}
}
I have tested this using jdk 1.6 and both in Linux and Windows environment.
Enjoy coding!