Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum SomeType {
- TYPE_A("A", "Type A Description"),
- TYPE_B("B", "Type B Description"),
- TYPE_C("C", "Type C Description");
- private String key;
- private String label;
- private static Map<String, ReportType> keyMap = new HashMap<String, ReportType>();
- static {
- for(ReportType type : ReportType.values()) {
- keyMap.put(type.getKey(), type);
- }
- }
- private ReportType(String _key, String _label) {
- this.key = _key;
- this.label = _label;
- }
- public String getKey() {
- return this.key;
- }
- public String getLabel() {
- return this.label;
- }
- public static List<ReportType> getValueList() {
- return Arrays.asList(ReportType.values());
- }
- public static ReportType getByKey(String _key) {
- ReportType result = keyMap.get(_key);
- if(result == null) {
- throw new IllegalArgumentException("Invalid key: " + _key);
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement