zoukankan      html  css  js  c++  java
  • 枚举类型 (币种例子)

    获取枚举的list 使用 RateTypeEnum.values() 

    public enum RateTypeEnum {
      CNY(0, "人民币"), DOLLAR(1, "美元");

      private int type;

      private String desc;

      private RateTypeEnum(int type, String desc) {
        this.type = type;
        this.desc = desc;
      }

      public static String getDescByType(int ratetype) {
        for (RateTypeEnum rateTypeEnum : RateTypeEnum.values()) {
          int type = rateTypeEnum.gettype();
          if (type == ratetype) {
            return rateTypeEnum.getdesc();
          }
        }
        return null;
      }

      public static boolean exist(String desc) {
        for (RateTypeEnum rateTypeEnum : RateTypeEnum.values()) {
          if (rateTypeEnum.getdesc().equals(desc.trim())) {
            return true;
          }
        }
        return false;
      }

      public static int getTypeByDesc(String desc) {
        for (RateTypeEnum rateTypeEnum : RateTypeEnum.values()) {
          if (rateTypeEnum.getdesc().equals(desc.trim())) {
            return rateTypeEnum.gettype();
          }
        }
        return -1;
      }

      public int gettype() {
        return type;
      }

      public void settype(int type) {
        this.type = type;
      }

      public String getdesc() {
        return desc;
      }

      public void setdesc(String desc) {
        this.desc = desc;
      }

    }

  • 相关阅读:
    c语言寒假大作战02
    C语言寒假大作战01
    C语言I作业12
    C语言I博客作业11
    C语言I博客作业10
    C语言ll作业01
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
  • 原文地址:https://www.cnblogs.com/huangyin/p/5888626.html
Copyright © 2011-2022 走看看