Mercurial > hg > Members > tatsuki > Alice
comparison src/main/java/alice/datasegment/CommandType.java @ 345:8f71c3e6f11d
Change directory structure Maven standard
author | sugi |
---|---|
date | Wed, 16 Apr 2014 18:26:07 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
344:9f97ec18f8c5 | 345:8f71c3e6f11d |
---|---|
1 package alice.datasegment; | |
2 | |
3 import java.util.HashMap; | |
4 | |
5 public enum CommandType { | |
6 PUT, | |
7 UPDATE, // remove a DataSegment value and put | |
8 PEEK, | |
9 TAKE, | |
10 REMOVE, | |
11 REPLY, | |
12 CLOSE, | |
13 FINISH, | |
14 PING, | |
15 RESPONSE; | |
16 | |
17 public int id; | |
18 public static HashMap<Integer, CommandType> hash = new HashMap<Integer, CommandType>(); | |
19 private static int lastId = 0; | |
20 | |
21 private CommandType(int id) { | |
22 this.id = id; | |
23 setLastId(id); | |
24 } | |
25 | |
26 private CommandType() { | |
27 this.id = incrementLastId(); | |
28 } | |
29 | |
30 private void setLastId(int id) { | |
31 lastId =id; | |
32 } | |
33 | |
34 private int incrementLastId() { | |
35 return ++lastId; | |
36 } | |
37 | |
38 public static CommandType getCommandTypeFromId(int id) { | |
39 return hash.get(id); | |
40 } | |
41 | |
42 static { | |
43 for (CommandType type : CommandType.values()) { | |
44 hash.put(type.id, type); | |
45 } | |
46 } | |
47 | |
48 } |