-
-
Save busti/6b66b68eac241dfdcfa4180bbe8f2dfc to your computer and use it in GitHub Desktop.
Crappy runtime Enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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