急!!! Java 枚举 Enum --Swith..Case怎样操作枚举 求解?
2011-10-26 16:34
555 查看
求高手讲解:
我想通过使用switch...case来判断客户端传递的值,但不知道怎样使用这个枚举类,该枚举类定义如下:
客户端传递过来的是一个int类型的值:
我这样写的:
这根本就没有使用枚举呀....求高手讲讲,非常感谢!!!
我想通过使用switch...case来判断客户端传递的值,但不知道怎样使用这个枚举类,该枚举类定义如下:
package ts.bca.meta; import java.util.Arrays; import util.enumerate.base.EnumUtil; import util.enumerate.base.IntegerEnumTypeImp; /** * 流程定义中的任务类型枚举类 * * @category * @version $Revision: 1.3 $ Mar 25, 2010 * @date Mar 25, 2010 3:39:44 PM */ public class EmergencyInfoReportStatesEnum extends IntegerEnumTypeImp { /** * serialUID. */ private static final long serialVersionUID = -1L; /** * @deprecated */ public EmergencyInfoReportStatesEnum() { super(); } /** * @param storeValue 存储值. ֵ */ private EmergencyInfoReportStatesEnum(int storeValue) { super(storeValue, EmergencyInfoReportStatesEnum.class.getName() + "." + storeValue, SystemEnumUtil.resource); } /** 空值型. */ public static final EmergencyInfoReportStatesEnum NULL = new EmergencyInfoReportStatesEnum(); /** * 1 报送中 */ final public static EmergencyInfoReportStatesEnum REPORTING = new EmergencyInfoReportStatesEnum(1); /** * 2 已报送 */ final public static EmergencyInfoReportStatesEnum REPORT_END = new EmergencyInfoReportStatesEnum(2); /** * 3 评估中 */ final public static EmergencyInfoReportStatesEnum ASSESS = new EmergencyInfoReportStatesEnum(3); /** * 4 已评估 */ final public static EmergencyInfoReportStatesEnum ASSESS_END = new EmergencyInfoReportStatesEnum(4); /** * 5 已删除 */ final public static EmergencyInfoReportStatesEnum DELETED = new EmergencyInfoReportStatesEnum(5); /** * 6 已关闭 */ final public static EmergencyInfoReportStatesEnum CLOSED = new EmergencyInfoReportStatesEnum(6); private static final EmergencyInfoReportStatesEnum[] ALL = {REPORTING, REPORT_END,ASSESS,ASSESS_END,DELETED,CLOSED}; static { Arrays.sort(ALL); } /** * 取得所有枚举 * * @return */ public static EmergencyInfoReportStatesEnum[] getAll() { return ALL; } /** * 根据键值取得枚举. * * @param code * @return */ public static final EmergencyInfoReportStatesEnum fromIntCode(final int code) { int pos = EnumUtil.search(ALL, code); return (pos >= 0) ? ALL[pos] : null; } }
客户端传递过来的是一个int类型的值:
我这样写的:
int code=event.getStates(); switch(code){ case 5: System.out.println("EventManageServiceImpl: 事件[ID="+eventId+"]已经被其他人删除."); break; default: //执行删除操作 System.out.println("EventManageServiceImpl: 事件[ID="+eventId+"]已经找到,即将被删除..."); event.setStates(5); break; }
这根本就没有使用枚举呀....求高手讲讲,非常感谢!!!
相关文章推荐
- Java枚举enum使用及相关的操作
- java enum(枚举)使用详解 + 总结
- Effective java 第2版 - 笔记(01) 单例(Singleton)的枚举(enum)实现
- Java enum枚举的用法
- java中不太常见的东西(1) - 枚举enum
- Java enum(枚举)使用详解之二
- Java 枚举(enum) 详解7种常见的用法
- java-枚举 enum
- JAVA:初始化及使用enum枚举类型
- java进阶(一):枚举-enum
- Java学习笔记82. 枚举 enum
- JAVA用enum枚举与switch搭配
- java enum(枚举)使用详解 + 总结
- Java中自定义枚举(Enum)项的值及int和Enum的互相转换
- java中的枚举enum
- Java Enum 枚举详解
- Java中自定义枚举(Enum)项的值及int和Enum的互相转换
- 高阶Java枚举类型enum使用详解
- 高阶Java枚举类型enum使用详解
- Java Enum 枚举