I have switch case with 50 String checks in case as given below:
switch(str){
case "Employee number":
//setter
break;
}
I want to put them in Enum with description as given below:
enum myenum{
EMPLOYEE_NUMBER("Employee number"),
FIRST_NAME("First name");
private String desc;
private myenum(String desc) {
this.setDesc(desc);
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
Now, From Source i am getting String "Employee Number" and i want to write switch case in such a way that we can compare description of enum with incoming string input in Case.
I tried some methods in enum
myenum.valueOf(a); // This return enum value but not parameter
myenum.values // This is array which is also not useful here
Kindly suggest how it is achievable in Enum? I am using Java 8
and also suggest Is enum right choice here? or shall i create Static string class with all 50 values or any other best wayout?