annotate src/pathfinder/mergetest/EditorObject.java @ 152:09ad66f62f4a before_REP_meeting_on_080822

*** empty log message ***
author pin
date Fri, 22 Aug 2008 15:48:52 +0900
parents
children 1a2269c820df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
152
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
1 package pathfinder.mergetest;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
2
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
3 import java.util.ArrayList;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
4 import java.util.List;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
5
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
6 import remoteeditor.command.REPCommand;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
7 import sample.merge.TranslaterImp1;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
8
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
9 public class EditorObject<P> {
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
10
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
11 int eid;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
12 private ChannelSimulator<P> channel;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
13 private TranslaterImp1 translater;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
14 private List<REPCommand> sentList;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
15
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
16 public EditorObject(int i, ChannelSimulator<P> cs) {
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
17 // TODO Auto-generated constructor stub
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
18 eid = i;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
19 channel = cs;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
20 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
21
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
22 public EditorObject(int i, ChannelSimulator<P> cs, TranslaterImp1 imp1) {
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
23 // TODO Auto-generated constructor stub
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
24 eid = i;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
25 channel = cs;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
26 translater = imp1;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
27 sentList = new ArrayList<REPCommand>();
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
28 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
29
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
30 public ChannelSimulator<P> getChannel() {
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
31 // TODO Auto-generated method stub
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
32 return channel;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
33 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
34
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
35 public int getEID() {
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
36 // TODO Auto-generated method stub
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
37 return eid;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
38 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
39
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
40 public REPCommand receive(REPCommand command) {
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
41 // TODO Auto-generated method stub
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
42
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
43 if(command.eid == eid){
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
44 if(checkReturnCommand(command)){
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
45 REPCommand[] cmds = translater.catchOwnCommand(command);
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
46 sendMergedCommand(cmds);
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
47 return null;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
48 }else{
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
49 sentList.add(command);
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
50 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
51 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
52
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
53 return command;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
54 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
55
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
56 private boolean checkReturnCommand(REPCommand command) {
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
57 // TODO Auto-generated method stub
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
58
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
59 if(sentList.size() > 0){
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
60 if(sentList.get(0).seq == command.seq){
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
61 return true;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
62 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
63 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
64
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
65 return false;
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
66 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
67
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
68 private void sendMergedCommand(REPCommand[] cmds) {
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
69 // TODO Auto-generated method stub
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
70 for(int i = 0; i < cmds.length; i++){
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
71 channel.write((P) cmds[i]);
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
72 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
73 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
74
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
75 public void send(REPCommand command) {
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
76 // TODO Auto-generated method stub
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
77 if(command !=null){
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
78 channel.write((P) command);
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
79 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
80 }
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
81
09ad66f62f4a *** empty log message ***
pin
parents:
diff changeset
82 }