Skip to content

Instantly share code, notes, and snippets.

@gkazior
Created February 8, 2016 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkazior/f70b20094e3a9d6e09cb to your computer and use it in GitHub Desktop.
Save gkazior/f70b20094e3a9d6e09cb to your computer and use it in GitHub Desktop.
public enum EntityType {
Customer("CS"),
ContactPerson("CP");
EntityType(String symbol) {
this.symbol = symbol;
}
private String symbol;
public String getName() {
return name();
}
public String getSymbol() {
return symbol;
}
public static EntityType nameToEntityType(String name) {
for (EntityType et: EntityType.values()) {
if (et.getName().equals(name)) {
return et;
}
}
throw new IllegalArgumentException(name + " cannot be converted to EntityType");
}
public static EntityType symbolToEntityType(String symbol) {
for (EntityType et: EntityType.values()) {
if (et.symbol.equals(symbol)) {
return et;
}
}
throw new IllegalArgumentException(symbol + " cannot be converted to EntityType");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment