Mercurial > hg > Members > tatsuki > Alice
annotate src/alice/test/topology/aquarium/AutoIncrement.java @ 277:ba4eea27d70d
Refactor to change attribute of threshold value to const class field.
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Oct 2013 01:55:21 +0900 |
parents | ccce30f84380 |
children | 04c769f00be1 |
rev | line source |
---|---|
134 | 1 package alice.test.topology.aquarium; |
111 | 2 |
3 import alice.codesegment.CodeSegment; | |
4 import alice.datasegment.CommandType; | |
5 import alice.datasegment.Receiver; | |
6 | |
7 public class AutoIncrement extends CodeSegment { | |
8 | |
138 | 9 private Receiver position = ids.create(CommandType.PEEK); |
10 private Receiver number = ids.create(CommandType.PEEK); | |
277
ba4eea27d70d
Refactor to change attribute of threshold value to const class field.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
11 private static final float MIN = -1.3f; |
119 | 12 |
133 | 13 public AutoIncrement(String key,int index){ |
217 | 14 this.number.setKey("maxsize"); |
15 this.position.setKey(key, index); | |
119 | 16 } |
111 | 17 |
18 @Override | |
132 | 19 public void run() { |
259 | 20 float max = this.number.asInteger()*2-1+0.3f; |
217 | 21 FishPoint fp = this.position.asClass(FishPoint.class); |
132 | 22 if (fp.getX()+0.01>max){ |
277
ba4eea27d70d
Refactor to change attribute of threshold value to const class field.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
23 fp.setXYZ(MIN, fp.getY(), fp.getZ()); |
ba4eea27d70d
Refactor to change attribute of threshold value to const class field.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
24 } else if (fp.getX() + 0.01 < MIN){ |
143 | 25 fp.setXYZ(max, fp.getY(), fp.getZ()); |
115 | 26 } |
27 else { | |
143 | 28 fp.setXYZ(fp.getX()+0.01f, fp.getY(), fp.getZ()); |
115 | 29 } |
30 | |
217 | 31 ods.update(position.key, fp); |
132 | 32 synchronized(this){ |
33 try { | |
34 // TODO | |
35 // Waiting should be done in Alice kernel | |
36 // ids.create(CommandType.WAIT); | |
37 | |
143 | 38 wait(20); |
132 | 39 } catch (InterruptedException e) { |
40 e.printStackTrace(); | |
41 } | |
42 } | |
115 | 43 |
214 | 44 new AutoIncrement(this.position.key, this.position.index); |
111 | 45 } |
46 | |
47 } |