16
|
1 package alice.test.dpp.codesegment;
|
|
2
|
|
3 import alice.codesegment.CodeSegment;
|
|
4 import alice.datasegment.CommandType;
|
|
5 import alice.datasegment.Receiver;
|
|
6 import alice.test.dpp.model.Fork;
|
|
7 import alice.test.dpp.model.Philosophy;
|
|
8
|
|
9 public class TakeLeftForkCodeSegment extends CodeSegment {
|
|
10
|
|
11 Receiver arg1 = ids.create(CommandType.TAKE);
|
|
12 Receiver arg2 = ids.create(CommandType.TAKE);
|
|
13
|
|
14 public TakeLeftForkCodeSegment(String pName, String forkName) {
|
|
15 arg1.setKey(pName);
|
|
16 arg2.setKey(forkName);
|
|
17 }
|
|
18
|
|
19 @Override
|
|
20 public void run() {
|
|
21 Philosophy phil = arg1.asClass(Philosophy.class);
|
|
22 Fork fork = arg2.asClass(Fork.class);
|
|
23 if (fork.getFork(phil.getName())) {
|
|
24 phil.setState(Philosophy.State.EAT);
|
|
25 new EatCodeSegment(phil.getName());
|
|
26 } else {
|
17
|
27 new TakeLeftForkCodeSegment(phil.getName(), phil.getLeftFork());
|
16
|
28 }
|
|
29 ods.update("local", phil.getName(), phil);
|
|
30 ods.update("local", fork.getForkName(), fork);
|
|
31 }
|
|
32 }
|