MatchSourceEnum.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.diagbot.enums;
  2. import com.diagbot.core.KeyedNamed;
  3. import lombok.Setter;
  4. /**
  5. * @Description:
  6. * @Author:zhaops
  7. * @time: 2021/6/15 13:20
  8. */
  9. public enum MatchSourceEnum implements KeyedNamed {
  10. StandWord(1, "标准词"),
  11. SynonymsWord(2, "同义词"),
  12. Code(3,"编码"),
  13. History(4,"历史数据"),
  14. SimilarWord(5,"相似词"),
  15. Approval(6,"国药准字");
  16. @Setter
  17. private int key;
  18. @Setter
  19. private String name;
  20. MatchSourceEnum(int key, String name) {
  21. this.key = key;
  22. this.name = name;
  23. }
  24. public static MatchSourceEnum getEnum(int key) {
  25. for (MatchSourceEnum item : MatchSourceEnum.values()) {
  26. if (item.key == key) {
  27. return item;
  28. }
  29. }
  30. return null;
  31. }
  32. public static MatchSourceEnum getEnum(String name) {
  33. for (MatchSourceEnum item : MatchSourceEnum.values()) {
  34. if (item.name.equals(name)) {
  35. return item;
  36. }
  37. }
  38. return null;
  39. }
  40. public static String getName(int key) {
  41. MatchSourceEnum item = getEnum(key);
  42. return item != null ? item.name : null;
  43. }
  44. public static Integer getKey(String name) {
  45. MatchSourceEnum item = getEnum(name);
  46. return item != null ? item.key : null;
  47. }
  48. @Override
  49. public int getKey() {
  50. return key;
  51. }
  52. @Override
  53. public String getName() {
  54. return name;
  55. }
  56. }