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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
53aff28cde6b change package
sugi
parents: 133
diff changeset
1 package alice.test.topology.aquarium;
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
2
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
3 import alice.codesegment.CodeSegment;
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
4 import alice.datasegment.CommandType;
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
5 import alice.datasegment.Receiver;
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
6
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
7 public class AutoIncrement extends CodeSegment {
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
8
138
87f1a30a8c82 change range automatic
sugi
parents: 134
diff changeset
9 private Receiver position = ids.create(CommandType.PEEK);
87f1a30a8c82 change range automatic
sugi
parents: 134
diff changeset
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
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
12
133
26b4b18c51fa minor change
sugi
parents: 132
diff changeset
13 public AutoIncrement(String key,int index){
217
b5c642ba998e change as** method and remove "local" key in TEST
sugi
parents: 216
diff changeset
14 this.number.setKey("maxsize");
b5c642ba998e change as** method and remove "local" key in TEST
sugi
parents: 216
diff changeset
15 this.position.setKey(key, index);
119
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
16 }
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
17
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
18 @Override
132
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
19 public void run() {
259
ccce30f84380 use "_CLIST" Key
sugi
parents: 217
diff changeset
20 float max = this.number.asInteger()*2-1+0.3f;
217
b5c642ba998e change as** method and remove "local" key in TEST
sugi
parents: 216
diff changeset
21 FishPoint fp = this.position.asClass(FishPoint.class);
132
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
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
0651fb36a369 demo for Open Source Conference
sugi
parents: 139
diff changeset
25 fp.setXYZ(max, fp.getY(), fp.getZ());
115
9845b74063ec share max number
sugi
parents: 114
diff changeset
26 }
9845b74063ec share max number
sugi
parents: 114
diff changeset
27 else {
143
0651fb36a369 demo for Open Source Conference
sugi
parents: 139
diff changeset
28 fp.setXYZ(fp.getX()+0.01f, fp.getY(), fp.getZ());
115
9845b74063ec share max number
sugi
parents: 114
diff changeset
29 }
9845b74063ec share max number
sugi
parents: 114
diff changeset
30
217
b5c642ba998e change as** method and remove "local" key in TEST
sugi
parents: 216
diff changeset
31 ods.update(position.key, fp);
132
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
32 synchronized(this){
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
33 try {
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
34 // TODO
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
35 // Waiting should be done in Alice kernel
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
36 // ids.create(CommandType.WAIT);
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
37
143
0651fb36a369 demo for Open Source Conference
sugi
parents: 139
diff changeset
38 wait(20);
132
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
39 } catch (InterruptedException e) {
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
40 e.printStackTrace();
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
41 }
1044a79ce4ef delete cs from OutputCodeSegment
sugi
parents: 126
diff changeset
42 }
115
9845b74063ec share max number
sugi
parents: 114
diff changeset
43
214
fec0726bb126 remove error
one
parents: 212
diff changeset
44 new AutoIncrement(this.position.key, this.position.index);
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
45 }
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
46
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
47 }