Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. public enum SomeType {
  2.  
  3. TYPE_A("A", "Type A Description"),
  4. TYPE_B("B", "Type B Description"),
  5. TYPE_C("C", "Type C Description");
  6.  
  7. private String key;
  8. private String label;
  9.  
  10. private static Map<String, ReportType> keyMap = new HashMap<String, ReportType>();
  11.  
  12. static {
  13. for(ReportType type : ReportType.values()) {
  14. keyMap.put(type.getKey(), type);
  15. }
  16. }
  17.  
  18. private ReportType(String _key, String _label) {
  19. this.key = _key;
  20. this.label = _label;
  21.  
  22. }
  23.  
  24. public String getKey() {
  25. return this.key;
  26. }
  27.  
  28. public String getLabel() {
  29. return this.label;
  30. }
  31.  
  32. public static List<ReportType> getValueList() {
  33. return Arrays.asList(ReportType.values());
  34. }
  35.  
  36. public static ReportType getByKey(String _key) {
  37. ReportType result = keyMap.get(_key);
  38.  
  39. if(result == null) {
  40. throw new IllegalArgumentException("Invalid key: " + _key);
  41. }
  42.  
  43. return result;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement