enum使用一例


/**
 * User: renjunjie
 * Date: 13-6-25 下午4:43
 * Function:
 */
public class AppContants {
    //政府机构
    //public static final Integer ORG_GOVERN = 1;
    //节能公司
    //public static final Integer ORG_ENERGY = 2;
    //耗能单位
    //public static final Integer ORG_UNIT = 3;

    public static enum ORG_TYPE { ORG_GOVERN("1"), ORG_ENERGY("2"), ORG_UNIT("3");

        private String value;
        private ORG_TYPE(String value){
            this.value = value;
        }
        private String getValue(){
            return value;
        }
        public static ORG_TYPE getByName(String name){
            for(ORG_TYPE prop : values()){
                if(prop.getValue().equals(name)){
                    return prop;
                }
            }
            throw new IllegalArgumentException(name + " is not a valid PropName");
        }
    };

    
    public static final String ZR_NAME = "zr";

    public static final Integer NODE_TYPE_DEVICE = 1;
    public static final Integer NODE_TYPE_GOVERN = 2;
    public static final Integer NODE_TYPE_ENERGY = 3;
    public static final Integer NODE_TYPE_UNIT = 4;

    /**
     * 通过组织机构类型获取树形机构节点类型
     * @param orgType
     * @return
     * @throws com.rixing.energysaving.exception.ServiceException
     */
    public static int getNodeTypeOfOrgType(String orgType) throws ServiceException {
        int result = -1;

        ORG_TYPE t = ORG_TYPE.getByName(orgType);
        switch (t) {
            case ORG_GOVERN :
                result = AppContants.NODE_TYPE_GOVERN;
                break;
            case ORG_ENERGY:
                result = AppContants.NODE_TYPE_ENERGY;
                break;
            case ORG_UNIT :
                result = AppContants.NODE_TYPE_UNIT;
                break;
        }
        if(result == -1) {
            throw new ServiceException("组织机构类型orgtype错误");
        }


        return result;
    }


}

 java switch使用enum好像只能在一个类里面

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值