急!!! Java 枚举 Enum --Swith..Case怎样操作枚举 求解?

求高手讲解:

我想通过使用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;
			}


这根本就没有使用枚举呀....求高手讲讲,非常感谢!!!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值