IsValidEnum.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * Copyright
  3. * All right reserved.
  4. * 项目名称:
  5. * 创建日期:2022/3/7
  6. */
  7. package org.springblade.enums;
  8. /***
  9. * Date:2022/3/7
  10. * Title:是否有效枚举类
  11. * Description:对本文件的详细描述,原则上不能少于30字
  12. * @author admin
  13. * @mender:(文件的修改者,文件创建者之外的人)
  14. * @version 1.0
  15. * Remark:认为有必要的其他信息
  16. */
  17. public enum IsValidEnum {
  18. /** 无效 */
  19. VALID_1(1, "无效"),
  20. /** 有效 */
  21. VALID_2(2, "有效");
  22. private int code;
  23. private String name;
  24. private IsValidEnum(int code, String name) {
  25. this.code = code;
  26. this.name = name;
  27. }
  28. /**
  29. * Function:根据code来获取对应的name
  30. * Author: Admin
  31. * Date:2021/6/26
  32. * @param code
  33. * @return java.lang.String
  34. * @throws Exception
  35. */
  36. public static String getName(int code) {
  37. for (IsValidEnum type : IsValidEnum.values()) {
  38. if (type.code == code) {
  39. return type.name;
  40. }
  41. }
  42. return "";
  43. }
  44. /**
  45. * Function:根据code来获取对应的枚举常量
  46. * Author: Admin
  47. * Date:2021/6/26
  48. * @param code
  49. * @return com.zhgzjg.web.enums.IsValid
  50. * @throws Exception
  51. */
  52. public static IsValidEnum getEnumByCode(int code) {
  53. for (IsValidEnum type : IsValidEnum.values()) {
  54. if (type.code == code) {
  55. return type;
  56. }
  57. }
  58. return null;
  59. }
  60. /**
  61. * Function:根据name来获取对应的枚举常量
  62. * Author: Admin
  63. * Date:2021/6/26
  64. * @param name
  65. * @return com.zhgzjg.web.enums.DeleteFlag
  66. * @throws Exception
  67. */
  68. public static IsValidEnum getEnumByName(String name) {
  69. for (IsValidEnum type : IsValidEnum.values()) {
  70. if (type.name.equals(name)) {
  71. return type;
  72. }
  73. }
  74. return null;
  75. }
  76. public Integer getCode() {
  77. return code;
  78. }
  79. public void setCode(int code) {
  80. this.code = code;
  81. }
  82. public String getName() {
  83. return name;
  84. }
  85. public void setName(String name) {
  86. this.name = name;
  87. }
  88. }