Reputation: 856
I have the following enum, it contains label and field values. I would like to return the field by passing in the label name.
Can anyone make any suggestions?
public enum Table (
NAME("name", "FULL_NAME");
public final String label;
public final String field;
private Table(String label, String field) {
this.label = label;
this.field = field;
}
}
Upvotes: 0
Views: 62
Reputation: 7790
Add method getField
to your enum
public enum Table (
NAME("name", "FULL_NAME");
public final String label;
public final String field;
private Table(String label, String field) {
this.label = label;
this.field = field;
}
public static String getField(String label) {
String result = null;
for(Table t : Table.values()) {
if(t.label.equals(label) {
result = t.field;
break;
}
}
return result;
}
}
Upvotes: 2