首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

enum施用一例

2013-08-16 
enum使用一例/** * User: renjunjie * Date: 13-6-25 下午4:43 * Function: */public class AppContants {

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好像只能在一个类里面

热点排行