comparison rep/Editor.java @ 224:6b0dd92b8e45

add optimizer to Editor
author kent
date Sun, 31 Aug 2008 13:28:34 +0900
parents 4d9b32666ed2
children 6c2f54265471
comparison
equal deleted inserted replaced
223:3680d8357429 224:6b0dd92b8e45
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.LinkedList; 4 import java.util.LinkedList;
5 import java.util.List; 5 import java.util.List;
6 6
7 import rep.channel.REPSocketChannel; 7 import rep.channel.REPSocketChannel;
8 import rep.optimizers.*;
8 import rep.translater.TranslaterImp1; 9 import rep.translater.TranslaterImp1;
9 10
10 public class Editor { 11 public class Editor {
11 private int eid; 12 private int eid;
12 private REPSocketChannel<REPCommand> myChannel; 13 private REPSocketChannel<REPCommand> myChannel;
13 private String host; 14 private String host;
14 private String file; 15 private String file;
15 private TranslaterImp1 translater; 16 private TranslaterImp1 translater;
16 private List<REPCommand> sentList; 17 private List<REPCommand> sentList;
17 private List<REPCommand> sentMergedList; 18 private List<REPCommand> sentMergedList;
19 private REPCommandOptimizer optimizer;
18 20
19 public Editor(){ 21 public Editor(){
22 this(true);
23 }
24 public Editor(boolean doOptimize){
20 setHostAndPort(myChannel); 25 setHostAndPort(myChannel);
21 translater = new TranslaterImp1(eid); 26 translater = new TranslaterImp1(eid);
22 sentList = new LinkedList<REPCommand>(); 27 sentList = new LinkedList<REPCommand>();
28
29 if (doOptimize) optimizer = new DeleteInsertOptimizer(); //タカノがつくったおぷてぃまいざ
30 else optimizer = new NullOptimizer(); //なにもしないけどOptimizer.
31
23 } 32 }
24 33
25 public Editor(int editorNo, REPSocketChannel<REPCommand> channel){ 34 public Editor(int editorNo, REPSocketChannel<REPCommand> channel){
26 this.eid = editorNo; 35 this.eid = editorNo;
27 this.myChannel = channel; 36 this.myChannel = channel;
35 setHostAndPort(myChannel); 44 setHostAndPort(myChannel);
36 translater = new TranslaterImp1(eid); 45 translater = new TranslaterImp1(eid);
37 sentList = new LinkedList<REPCommand>(); 46 sentList = new LinkedList<REPCommand>();
38 } 47 }
39 48
40 public LinkedList<REPCommand> translate(REPCommand command){ 49 public List<REPCommand> translate(REPCommand command){
41 LinkedList<REPCommand> list = new LinkedList<REPCommand>(); 50 List<REPCommand> list = new LinkedList<REPCommand>();
42 if(command.eid == eid){ 51 if(command.eid == eid){
43 if(checkReturnedCommand(command)){ 52 if(checkReturnedCommand(command)){
44 //エディタからのコマンドが元のエディタに戻ってきた 53 //エディタからのコマンドが元のエディタに戻ってきた
45 //マージして送信 54 //マージして送信
46 ArrayList<REPCommand> cmds = translater.catchOwnCommand(command); 55 ArrayList<REPCommand> cmds = translater.catchOwnCommand(command);
57 } 66 }
58 }else if(eid == REP.MERGE_EID){ 67 }else if(eid == REP.MERGE_EID){
59 //マージコマンドが返ってきた 68 //マージコマンドが返ってきた
60 if(translater.checkMergeConflict(command)){ 69 if(translater.checkMergeConflict(command)){
61 //マージ中にエディタからの割り込みがあった場合 70 //マージ中にエディタからの割り込みがあった場合
62 LinkedList<REPCommand> mergeAgainList = translater.getMergeAgain(); 71 List<REPCommand> mergeAgainList = translater.getMergeAgain();
63 //optimizer 72
73 mergeAgainList = optimizer.optimize(mergeAgainList);
64 for(REPCommand againCommand: mergeAgainList){ 74 for(REPCommand againCommand: mergeAgainList){
65 myChannel.write(againCommand); 75 myChannel.write(againCommand);
66 } 76 }
67 } 77 }
68 }else{ 78 }else{