Skip to content

Instantly share code, notes, and snippets.

@busti
Created May 18, 2016 19:11
Show Gist options
  • Save busti/6b66b68eac241dfdcfa4180bbe8f2dfc to your computer and use it in GitHub Desktop.
Save busti/6b66b68eac241dfdcfa4180bbe8f2dfc to your computer and use it in GitHub Desktop.
Crappy runtime Enum
import java.util.Set;
import java.util.TreeSet;
class RuntimeEnum {
private final Set<String> allowedValues;
private String value;
public RuntimeEnum(String[] vals) {
allowedValues = new TreeSet<String>();
allowedValues.addAll(vals);
//Initializing the value with the firts allowed value.
value = vals[0];
}
public boolean setValue(String val) {
if (allowedValues.contains(val)) {
value = val;
return true;
}
return false;
}
public String getValue() {
return value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment