package com.hiredmyway.enums;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
public class TestEnum {
protected Map<String, Object> session;
protected Map<String, Object> request;
protected HttpServletResponse response;
protected ServletContext context;
protected Object result;
public enum State {
ON,OFF
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TestEnum t = new TestEnum();
String ex = KindEnum.STATE.getKindName();
// 获得常量值,及0-N索引号,CODE值
for (StateEnum em :StateEnum.values()){
System.out.print(em+":"+em.ordinal()+", "+em.getCode()+"!");
}
System.out.println("/r/n");//回车换行符
// EnumSet.range(StateEnum.DEFAULT, StateEnum.COLORADO) 从开始想要的值到你结束的值
for (StateEnum e : EnumSet.range(StateEnum.DEFAULT, StateEnum.COLORADO)) {
System.out.print(e+":"+e.ordinal()+", ");
System.out.println("/r/n");
}
//常量值
EnumSet<State> stateSet = EnumSet.allOf(State.class);
for (State s: stateSet) {
System.out.println(s);
}
System.out.println("---ok---");
EnumMap<State, String> stateMap = new EnumMap<State, String>(State.class);
stateMap.put(State.OFF, "Is OFF");
stateMap.put(State.ON,"Is ON");
Iterator it =stateMap.keySet().iterator();
// 获得ON,OFF
while (it.hasNext()) {
State st =(State)it.next();
String str =st.name();
//获得ON,OFF 对应得VALUES值
System.out.println(stateMap.get(st));
}
System.out.println("---ok1---");
Iterator<Entry<State,String>> it1 = stateMap.entrySet().iterator();
while (it1.hasNext()) {
Entry<State, String> st = (Entry)it1.next();
String str =st.getValue();
//获得ON,OFF 对应得VALUES值
System.out.println(str);
}
System.out.println("---ok2---");
for (State s: State.values()) {
//获得ON,OFF 和 对应得VALUES值
System.out.println("State:"+s.name()+":"+stateMap.get(s));
}
}
// public String execute() throws Exception {
// //SysCache.getInstance().getEnum(kind);
// List <Enums> select_data = prepareCache().getEnum(KindEnum.EXPERIENCE.getKindName());
//
// StringBuffer select_txt = new StringBuffer();
//
// for (Enums enums : select_data) {
//
// select_txt.append("<option value='"+enums.getCode()+"'>"+enums.getCodeDesc()+"</option>");
//
// }
// // TODO Auto-generated method stub
// return null;
// }
}