NewsCacheKey.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.goafanti.common.enums;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. public enum NewsCacheKey {
  5. NEWS_LIST_CACHE_KEY("news_list_cache_key", "策源地新闻列表缓存"),
  6. NEWS_PORTAL_LIST_CACHE_KEY("news_portal_list_cache_key", "新闻列表页面缓存"),
  7. NEWS_INDEX_LIST_CACHE_KEY("news_index_list_cache_key", "首页新闻列表缓存"),
  8. OTHER("", "未知参数");
  9. private String code;
  10. private String desc;
  11. private static Map<String, NewsCacheKey> status = new HashMap<String, NewsCacheKey>();
  12. private NewsCacheKey(String code, String desc) {
  13. this.code = code;
  14. this.desc = desc;
  15. }
  16. static {
  17. for (NewsCacheKey value : NewsCacheKey.values()) {
  18. status.put(value.getCode(), value);
  19. }
  20. }
  21. public static NewsCacheKey getField(String code) {
  22. if (containsType(code)) {
  23. return status.get(code);
  24. }
  25. return OTHER;
  26. }
  27. public static String getFieldDesc(String code) {
  28. return getField(code).getDesc();
  29. }
  30. public static boolean containsType(String code) {
  31. return status.containsKey(code);
  32. }
  33. public String getCode() {
  34. return code;
  35. }
  36. public String getDesc() {
  37. return desc;
  38. }
  39. }