In this code I get a compiler error, see comment:
public enum Type {
CHANGESET(\"changeset\"),
NEW_TICKET(\"newticket\"),
TICKET_CHANGED(\"editedti
How about this; doesn't require you to make code changes at two places which is kind of error prone IMO:
enum Type {
CHANGESET("changeset"),
NEW_TICKET("newticket"),
TICKET_CHANGED("editedticket"),
CLOSED_TICKET("closedticket");
private static final Map tracNameMap =
new HashMap();
private final String name;
public Type typeForName(final String name) {
if (tracNameMap.containsKey(name)) {
return tracNameMap.get(name);
} else {
for (final Type t : Type.values()) {
if (t.name.equals(name)) {
tracNameMap.put(name, t);
return t;
}
}
throw new IllegalArgumentException("Invalid enum name");
}
}
private Type(String name) {
this.name = name;
}
}