annotate src/alice/test/topology/fishmodel/alpha/AutoIncrement.java @ 126:669dba7cbb69 working

Use singleton
author sugi
date Fri, 03 Aug 2012 19:14:46 +0900
parents f84e1684c6be
children 1044a79ce4ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
1 package alice.test.topology.fishmodel.alpha;
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
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
9 public Receiver position = ids.create(CommandType.PEEK);
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
10 String key;
119
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
11 float max = 3.3f;
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
12 float min = -1.3f;
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
13
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
14
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
15 public AutoIncrement(String key,int index){
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
16
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
17 this.key = key;
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
18 this.position.setKey("local", key);
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
19
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
20 }
119
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
21
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
22 public void Init(){
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
23 this.ods = null;
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
24 this.position = null;
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
25
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
26 }
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
27
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
28 @Override
115
9845b74063ec share max number
sugi
parents: 114
diff changeset
29 public synchronized void run() {
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
30 FishPoint FP = this.position.asClass(FishPoint.class);
115
9845b74063ec share max number
sugi
parents: 114
diff changeset
31
119
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
32 if (FP.getX()+0.01>max){
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
33 FP.setXY(min, FP.getY());
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
34 } else if (FP.getX()+0.01< min){
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
35 FP.setXY(max, FP.getY());
115
9845b74063ec share max number
sugi
parents: 114
diff changeset
36 }
9845b74063ec share max number
sugi
parents: 114
diff changeset
37 else {
9845b74063ec share max number
sugi
parents: 114
diff changeset
38 FP.setXY(FP.getX()+0.01f, FP.getY());
9845b74063ec share max number
sugi
parents: 114
diff changeset
39 }
9845b74063ec share max number
sugi
parents: 114
diff changeset
40
9845b74063ec share max number
sugi
parents: 114
diff changeset
41
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
42 ods.update("local", key, FP);
119
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
43 /*
115
9845b74063ec share max number
sugi
parents: 114
diff changeset
44 try {
126
669dba7cbb69 Use singleton
sugi
parents: 119
diff changeset
45 wait(100);
115
9845b74063ec share max number
sugi
parents: 114
diff changeset
46 } catch (InterruptedException e) {
9845b74063ec share max number
sugi
parents: 114
diff changeset
47 // TODO Auto-generated catch block
9845b74063ec share max number
sugi
parents: 114
diff changeset
48 e.printStackTrace();
9845b74063ec share max number
sugi
parents: 114
diff changeset
49 }
119
f84e1684c6be put NULL in CS
sugi
parents: 116
diff changeset
50 */
111
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
51 new AutoIncrement(this.key,this.position.index);
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
52 }
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
53
ba64a9d76e70 Add AutoIncrement
sugi
parents:
diff changeset
54 }