WeightUnit.java 1006 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package com.oqpo.api.enums;
  2. import com.oqpo.api.exception.GlobalException;
  3. import lombok.Getter;
  4. import lombok.Setter;
  5. public enum WeightUnit {
  6. KG("10", "kg"), //
  7. G("20", "g"), //
  8. MG("30", "mg"), //
  9. TON("40", "ton"), //
  10. ;
  11. WeightUnit(String cd, String nm) {
  12. this.cd = cd;
  13. this.name = nm;
  14. }
  15. @Getter
  16. @Setter
  17. private String cd;
  18. @Getter
  19. @Setter
  20. private String name;
  21. public static String getCd(String nname) {
  22. WeightUnit[] values = WeightUnit.values();
  23. for (WeightUnit icd : values) {
  24. if (icd.name.equals(nname)) {
  25. return icd.cd;
  26. }
  27. }
  28. throw new GlobalException(SystemMessageCode.ERR_CODE_NM);
  29. }
  30. public static String getName(String ccd) {
  31. WeightUnit[] values = WeightUnit.values();
  32. for (WeightUnit icd : values) {
  33. if (icd.cd.equals(ccd)) {
  34. return icd.name;
  35. }
  36. }
  37. return ccd;
  38. }
  39. }