求高手讲解:
我想通过使用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中switch-case结构的使用方式,特别是针对客户端传递的状态值进行判断处理的方法。
454

被折叠的 条评论
为什么被折叠?



