BannersStatus.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.goafanti.common.enums;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import org.apache.commons.lang3.StringUtils;
  5. public enum BannersStatus {
  6. HOME( 1,"home"),
  7. OTHER(0, "other");
  8. private BannersStatus(Integer code, String desc) {
  9. this.code = code;
  10. this.desc = desc;
  11. }
  12. private static Map<Integer, BannersStatus> status = new HashMap<Integer, BannersStatus>();
  13. static {
  14. for (BannersStatus value : BannersStatus.values()) {
  15. status.put(value.getCode(), value);
  16. }
  17. }
  18. public static BannersStatus getStatus(Integer code) {
  19. if (containsType(code)) {
  20. return status.get(code);
  21. }
  22. return OTHER;
  23. }
  24. public static BannersStatus getStatus(String code) {
  25. if (StringUtils.isNumeric(code)) {
  26. return getStatus(Integer.parseInt(code));
  27. }
  28. return OTHER;
  29. }
  30. public static boolean containsType(Integer code) {
  31. return status.containsKey(code);
  32. }
  33. private Integer code;
  34. private String desc;
  35. public Integer getCode() {
  36. return code;
  37. }
  38. public String getDesc() {
  39. return desc;
  40. }
  41. }