comparison src/pathfinder/mergetest/test/RepCommandOptimizeTest.java @ 171:c61a52e12161

This program is being inspected.
author tkaito
date Fri, 29 Aug 2008 22:21:49 +0900
parents 86894c5e5fef
children d234a9d2a172
comparison
equal deleted inserted replaced
170:86894c5e5fef 171:c61a52e12161
20 Integer.toString(REP.REPCMD_DELETE),"?","3","6", 20 Integer.toString(REP.REPCMD_DELETE),"?","3","6",
21 Integer.toString(REP.REPCMD_INSERT),"B","3","7", 21 Integer.toString(REP.REPCMD_INSERT),"B","3","7",
22 Integer.toString(REP.REPCMD_DELETE),"?","1","8" 22 Integer.toString(REP.REPCMD_DELETE),"?","1","8"
23 23
24 }; 24 };
25 static String[] test2 = {
26 Integer.toString(REP.REPCMD_INSERT),"C","2","1",
27 Integer.toString(REP.REPCMD_INSERT),"B","3","2",
28 Integer.toString(REP.REPCMD_INSERT),"d","2","3",
29 Integer.toString(REP.REPCMD_INSERT),"B","3","4",
30 Integer.toString(REP.REPCMD_DELETE),"A","3","5",
31 Integer.toString(REP.REPCMD_DELETE),"A","1","6",
32 Integer.toString(REP.REPCMD_INSERT),"d","3","7",
33 Integer.toString(REP.REPCMD_DELETE),"d","1","8"
34
35 };
25 36
26 static private String[] text1d = { 37 static private String[] text1d = {
27 "aaa", "bbb", "ccc", "ddd", "eee", 38 "aaa", "bbb", "ccc", "ddd", "eee",
28 "fff", "ggg", "hhh", "iii", "jjj", 39 "fff", "ggg", "hhh", "iii", "jjj",
29 "kkk", "lll", "mmm", "nnn", "ooo", 40 "kkk", "lll", "mmm", "nnn", "ooo",
55 }catch(Exception e){ 66 }catch(Exception e){
56 e.printStackTrace(); 67 e.printStackTrace();
57 } 68 }
58 } 69 }
59 70
60 LinkedList<REPCommand> optimize(LinkedList<REPCommand> input){ 71 LinkedList<REPCommand> optimize(LinkedList<REPCommand> inp){
61 LinkedList<REPCommand> output = new LinkedList<REPCommand>(); 72 LinkedList<REPCommand> output = new LinkedList<REPCommand>();
62 output = reverse(input); 73 output = reverse(inp);
74
63 for(int i = 0; i < output.size(); i++){ 75 for(int i = 0; i < output.size(); i++){
64 REPCommand r = output.get(i); 76 REPCommand r = output.get(i);
65 switch(r.cmd){ 77 switch(r.cmd){
66 case REP.REPCMD_INSERT: 78 case REP.REPCMD_INSERT:
67 break; 79 break;
114 int i = 0; 126 int i = 0;
115 for(REPCommand o : opt){ 127 for(REPCommand o : opt){
116 if(ln < o.lineno) i++; 128 if(ln < o.lineno) i++;
117 } 129 }
118 if(i == opt.size()){ 130 if(i == opt.size()){
119 for(int j = 0; j < opt.size(); j++){ 131 for(REPCommand c : opt){
120 REPCommand c = opt.get(j);
121 c.lineno -= 1; 132 c.lineno -= 1;
122 } 133 }
123 } 134 }
124 } 135 }
125 136
126 void printCmdList(LinkedList<REPCommand> before, LinkedList<REPCommand> after){ 137 void printCmdList(LinkedList<REPCommand> before){
127 System.out.println("---------- CmdList1 ----------"); 138 System.out.println("---------- CmdList ----------");
128 for(REPCommand r: before){ 139 for(REPCommand r: before){
129 System.out.println(r.toString()); 140 System.out.println(r.toString());
130 } 141 }
131 System.out.println("---------- CmdList2 ----------"); 142 /*System.out.println("---------- CmdList2 ----------");
132 for(REPCommand s: after){ 143 for(REPCommand s: after){
133 System.out.println(s.toString()); 144 System.out.println(s.toString());
134 } 145 }*/
135 } 146 }
136 147
137 Text text1 = new Text(text1d); 148 static Text text1 = new Text(text1d);
138 Text text2 = new Text(text2d); 149 static Text text2 = new Text(text2d);
139 150
140 void edit(LinkedList<REPCommand> before, LinkedList<REPCommand> after){ 151 void edit(LinkedList<REPCommand> before, Text txt){
141 for(REPCommand r : before){ 152 for(REPCommand r : before){
142 text1.edit(r); 153 txt.edit(r);
143 } 154 }
144 for(REPCommand s : after){ 155 /*for(REPCommand s : after){
145 text2.edit(s); 156 text2.edit(s);
146 } 157 }*/
147 } 158 }
148 159
149 void printText(){ 160 void printText(){
150 System.out.println("------------ Text1 -----------"); 161 System.out.println("------------ Text1 -----------");
151 text1.printAllText(); 162 text1.printAllText();
164 } 175 }
165 176
166 public static void main(String[] s){ 177 public static void main(String[] s){
167 178
168 RepCommandOptimizeTest rco = new RepCommandOptimizeTest(); 179 RepCommandOptimizeTest rco = new RepCommandOptimizeTest();
169 rco.makeCommand(test1); 180 rco.makeCommand(test2);
170 //java.util.Collections.shuffle(cmdlist); 181 java.util.Collections.shuffle(cmdlist);
171 rco.printCmdList(cmdlist, rco.optimize(cmdlist)); 182 rco.printCmdList(cmdlist);
172 rco.edit(cmdlist, rco.optimize(cmdlist)); 183 rco.edit(cmdlist,text1);
184 rco.printCmdList(rco.optimize(cmdlist));
185 rco.edit(rco.optimize(cmdlist),text2);
173 rco.printText(); 186 rco.printText();
174 rco.checkText(); 187 rco.checkText();
175 } 188 }
176 } 189 }