annotate src/alice/test/dpp/datasegment/Fork.java @ 26:80023cb92594 draft

add some CodeSegment. ForkStateTake, CheckForkOwnerCodeSegment, TakeForkManager
author one
date Tue, 11 Dec 2012 16:07:41 +0900
parents edd9ced13896
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
dbc5c8e8e9c2 rename frome model to datasegment
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 15
diff changeset
1 package alice.test.dpp.datasegment;
3
6b3f0f87a36b add alice.test.dpp.model
one
parents:
diff changeset
2
7
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
3 import org.msgpack.annotation.Message;
12
bfaaebb50a2e modified Fork.java
one
parents: 10
diff changeset
4 import org.msgpack.annotation.MessagePackOrdinalEnum;
7
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
5
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
6 @Message
3
6b3f0f87a36b add alice.test.dpp.model
one
parents:
diff changeset
7 public class Fork {
6b3f0f87a36b add alice.test.dpp.model
one
parents:
diff changeset
8
12
bfaaebb50a2e modified Fork.java
one
parents: 10
diff changeset
9
bfaaebb50a2e modified Fork.java
one
parents: 10
diff changeset
10 private String forkName;
4
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
11 private String owner;
7
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
12 private State state;
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
13
10
60539f5d514e modified Fork.TABLE
one
parents: 9
diff changeset
14 private final String TABLE = "TABLE";
12
bfaaebb50a2e modified Fork.java
one
parents: 10
diff changeset
15
bfaaebb50a2e modified Fork.java
one
parents: 10
diff changeset
16 @MessagePackOrdinalEnum
7
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
17 public enum State {
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
18 ON_THE_TABLE,
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
19 IN_THE_HAND;
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
20 }
9
247105822f8e modified Fork.java
one
parents: 7
diff changeset
21
12
bfaaebb50a2e modified Fork.java
one
parents: 10
diff changeset
22 public Fork() {}
3
6b3f0f87a36b add alice.test.dpp.model
one
parents:
diff changeset
23
4
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
24 public Fork(String n) {
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
25 forkName = n;
10
60539f5d514e modified Fork.TABLE
one
parents: 9
diff changeset
26 owner = TABLE;
7
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
27 state = State.ON_THE_TABLE;
4
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
28 }
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
29
7
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
30 public State getState() {
4
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
31 return state;
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
32 }
12
bfaaebb50a2e modified Fork.java
one
parents: 10
diff changeset
33
4
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
34 public String getForkName() {
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
35 return forkName;
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
36 }
12
bfaaebb50a2e modified Fork.java
one
parents: 10
diff changeset
37
24
edd9ced13896 change method name from getFork to takeFork
one
parents: 19
diff changeset
38 public boolean takeFork(String pName) {
15
7e91e919a7de modified
one
parents: 14
diff changeset
39 if (state == State.ON_THE_TABLE) {
7
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
40 state = State.IN_THE_HAND;
14
33727db069c2 add ScheduleCodeSegment. modified CodeSegment
one
parents: 12
diff changeset
41 owner = pName;
4
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
42 return true;
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
43 } else {
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
44 return false;
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
45 }
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
46 }
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
47
14
33727db069c2 add ScheduleCodeSegment. modified CodeSegment
one
parents: 12
diff changeset
48 public boolean onTheTable(String pName) {
33727db069c2 add ScheduleCodeSegment. modified CodeSegment
one
parents: 12
diff changeset
49 if (owner.equals(pName)) {
7
f7af6388adbb modified Fork.java
one
parents: 4
diff changeset
50 state = State.ON_THE_TABLE;
10
60539f5d514e modified Fork.TABLE
one
parents: 9
diff changeset
51 owner = TABLE;
4
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
52 return true;
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
53 } else {
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
54 return false;
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
55 }
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
56 }
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
57
26
80023cb92594 add some CodeSegment. ForkStateTake, CheckForkOwnerCodeSegment, TakeForkManager
one
parents: 24
diff changeset
58 public boolean ownerEquals(String s) {
80023cb92594 add some CodeSegment. ForkStateTake, CheckForkOwnerCodeSegment, TakeForkManager
one
parents: 24
diff changeset
59 return owner.equals(s);
80023cb92594 add some CodeSegment. ForkStateTake, CheckForkOwnerCodeSegment, TakeForkManager
one
parents: 24
diff changeset
60 }
80023cb92594 add some CodeSegment. ForkStateTake, CheckForkOwnerCodeSegment, TakeForkManager
one
parents: 24
diff changeset
61
4
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
62 public String getOwner() {
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
63 return owner;
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
64 }
2794091a7058 modified CodeSegment
one
parents: 3
diff changeset
65
3
6b3f0f87a36b add alice.test.dpp.model
one
parents:
diff changeset
66
6b3f0f87a36b add alice.test.dpp.model
one
parents:
diff changeset
67 }