1
0

MetaEnum.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package org.dbsyncer.parser.enums;
  2. import org.dbsyncer.parser.ParserException;
  3. /**
  4. * 驱动状态枚举
  5. *
  6. * @author AE86
  7. * @version 1.0.0
  8. * @date 2020/04/21 16:19
  9. */
  10. public enum MetaEnum {
  11. /**
  12. * 未运行
  13. */
  14. READY(0, "未运行"),
  15. /**
  16. * 运行中
  17. */
  18. RUNNING(1, "运行中"),
  19. /**
  20. * 停止中
  21. */
  22. STOPPING(2, "停止中");
  23. private int code;
  24. private String message;
  25. MetaEnum(int code, String message) {
  26. this.code = code;
  27. this.message = message;
  28. }
  29. public static MetaEnum getMetaEnum(int code) throws ParserException {
  30. for (MetaEnum e : MetaEnum.values()) {
  31. if (code == e.getCode()) {
  32. return e;
  33. }
  34. }
  35. throw new ParserException(String.format("Meta code \"%s\" does not exist.", code));
  36. }
  37. public int getCode() {
  38. return code;
  39. }
  40. public void setCode(int code) {
  41. this.code = code;
  42. }
  43. public String getMessage() {
  44. return message;
  45. }
  46. public void setMessage(String message) {
  47. this.message = message;
  48. }
  49. }