枚举类型的数据存入到map中
原文来自http://fokman.iteye.com/blog/1568905
- public enum IdeasCMD {
- RESERVED(0), PING(1), PING_ACK(2), KEY_EXCHANGE(3), KEY_EXCHANGE_ACK(4), CONNECT(5), CONNECT_ACK(6), DISCONNECT(7), KEEP_ALIVE(
- 8), KEEP_ALIVE_ACK(9) ;
- private final int value;
- /**
- * enum lookup map
- */
- private static final Map<Integer, IdeasCMD> lookup = new HashMap<Integer, IdeasCMD>();
- static {
- for (IdeasCMD s : EnumSet.allOf(IdeasCMD.class)) {
- lookup.put(s.getValue(), s);
- }
- }
- IdeasCMD(int value) {
- this.value = value;
- }
- public int getValue() {
- return value;
- }
- public static IdeasCMD lookup(int value) {
- return lookup.get(value);
- }
- }
public enum IdeasCMD { RESERVED(0), PING(1), PING_ACK(2), KEY_EXCHANGE(3), KEY_EXCHANGE_ACK(4), CONNECT(5), CONNECT_ACK(6), DISCONNECT(7), KEEP_ALIVE( 8), KEEP_ALIVE_ACK(9) ;private final int value; /** * enum lookup map */ private static final Map<Integer, IdeasCMD> lookup = new HashMap<Integer, IdeasCMD>(); static { for (IdeasCMD s : EnumSet.allOf(IdeasCMD.class)) { lookup.put(s.getValue(), s); } } IdeasCMD(int value) { this.value = value; } public int getValue() { return value; } public static IdeasCMD lookup(int value) { return lookup.get(value); }
}