TimePeriodEnum.java 1018 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.xjrsoft.common.enums;
  2. /**
  3. * 课表时段
  4. */
  5. public enum TimePeriodEnum {
  6. /**
  7. * 上午
  8. */
  9. MORNING(1, "上午"),
  10. /**
  11. * 下午
  12. */
  13. AFTERNOON(2, "下午"),
  14. /**
  15. * 晚上
  16. */
  17. NIGHT(3, "晚上");
  18. final int code;
  19. final String value;
  20. public int getCode() {
  21. return this.code;
  22. }
  23. public String getValue() {
  24. return this.value;
  25. }
  26. TimePeriodEnum(final int code, final String message) {
  27. this.code = code;
  28. this.value = message;
  29. }
  30. public static int getCode(String value) {
  31. for (TimePeriodEnum c : TimePeriodEnum.values()) {
  32. if (c.getValue().equals(value)) {
  33. return c.getCode();
  34. }
  35. }
  36. return 0;
  37. }
  38. public static String getValue(int code) {
  39. for (TimePeriodEnum c : TimePeriodEnum.values()) {
  40. if (c.getCode() == code) {
  41. return c.getValue();
  42. }
  43. }
  44. return "";
  45. }
  46. }