用枚举表示应用中简单流程的状态

阅读更多
创建一个表示简单流程状态的枚举类型:

public enum ApplicationStatusEnum {
//	"0" 删除, “1”草稿, “2”待会签, “3”待权签
	STATUS_DEL("0", "del", "草稿"),
	STATUS_DRAFT("1", "draft", "草稿"),
	STATUS_COUSIGN("2", "countersign", "草稿"),
	STATUS_APPROVE("3", "approve", "草稿");//可以继续添加
	private String key;
	private String value;
	private String desc;
	
	private ApplicationStatusEnum(String key, String value, String desc) {
		this.key = key;
		this.value = value;
		this.desc = desc;
	}
	
	public String getKey() {
		return key;
	}
	
	public String getValue() {
		return value;
	}
	
	public String getDesc() {
		return desc;
	}
	
	public static ApplicationStatusEnum getAppStatus(String key) {
		for (ApplicationStatusEnum status : ApplicationStatusEnum.values()) {
			if (status.key.equals(key)) {
				return status;
			}
		}
		return null;
	}
}


在需要的地方进行取值调用:
public class EnumTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(ApplicationStatusEnum.STATUS_APPROVE.getKey());   //输出“3”
		ApplicationStatusEnum statusEnum = ApplicationStatusEnum.getAppStatus("1");
		System.out.println(statusEnum.getKey());//输出“1”
		System.out.println(statusEnum.getValue());//输出“draft”
		System.out.println(statusEnum.getDesc());//输出“草稿”
	}

}

你可能感兴趣的:(enum,状态)