Mercurial > hg > Members > nobuyasu > Alice > DPPAlice
changeset 6:b59c04a332a1
add PutForkCodeSegment
author | one |
---|---|
date | Sun, 25 Nov 2012 17:22:45 +0900 |
parents | 2db314b1a970 |
children | f7af6388adbb |
files | src/alice/test/dpp/codesegment/EatCodeSegment.java src/alice/test/dpp/codesegment/PutForkCodeSegment.java src/alice/test/dpp/codesegment/TakeForkCodeSegment.java |
diffstat | 3 files changed, 34 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/test/dpp/codesegment/EatCodeSegment.java Sun Nov 25 17:08:21 2012 +0900 +++ b/src/alice/test/dpp/codesegment/EatCodeSegment.java Sun Nov 25 17:22:45 2012 +0900 @@ -12,7 +12,8 @@ @Override public void run() { - + System.out.println(phil.getName() + " is eating."); + new PutForkCodeSegment(phil); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/dpp/codesegment/PutForkCodeSegment.java Sun Nov 25 17:22:45 2012 +0900 @@ -0,0 +1,31 @@ +package alice.test.dpp.codesegment; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.test.dpp.model.Fork; +import alice.test.dpp.model.Philosophy; + +public class PutForkCodeSegment extends CodeSegment { + + Philosophy phil; + Receiver arg1 = ids.create(CommandType.TAKE); + Receiver arg2 = ids.create(CommandType.TAKE); + + public PutForkCodeSegment(Philosophy p) { + phil = p; + arg1.setKey(phil.getLeftFork()); + arg2.setKey(phil.getRightFork()); + } + + @Override + public void run() { + System.out.println(phil +" put fork."); + Fork leftFork = arg1.asClass(Fork.class); + Fork rightFork = arg2.asClass(Fork.class); + leftFork.onTheTable(phil); + rightFork.onTheTable(phil); + new ThinkCodeSegment(phil); + } + +}
--- a/src/alice/test/dpp/codesegment/TakeForkCodeSegment.java Sun Nov 25 17:08:21 2012 +0900 +++ b/src/alice/test/dpp/codesegment/TakeForkCodeSegment.java Sun Nov 25 17:22:45 2012 +0900 @@ -28,6 +28,7 @@ } else { leftFork.onTheTable(phil); rightFork.onTheTable(phil); + new TakeForkCodeSegment(phil); } ods.update("local", leftFork.getForkName(), leftFork); ods.update("local", rightFork.getForkName(), rightFork);