Mercurial > hg > RemoteEditor > Eclipse
changeset 164:5c458f1a7679
*** empty log message ***
author | tkaito |
---|---|
date | Thu, 28 Aug 2008 22:18:28 +0900 |
parents | 34f770c7fd86 |
children | c33846dbb47b |
files | src/pathfinder/mergetest/test/RepCommandOptimizeTest.java |
diffstat | 1 files changed, 90 insertions(+), 67 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pathfinder/mergetest/test/RepCommandOptimizeTest.java Thu Aug 28 22:13:08 2008 +0900 +++ b/src/pathfinder/mergetest/test/RepCommandOptimizeTest.java Thu Aug 28 22:18:28 2008 +0900 @@ -1,6 +1,7 @@ package pathfinder.mergetest.test; import java.util.LinkedList; +import java.util.List; import pathfinder.mergetest.Text; @@ -15,16 +16,18 @@ static String[] test1 = { Integer.toString(REP.REPCMD_INSERT),"TEST0","3","1", Integer.toString(REP.REPCMD_INSERT),"TEST1","3","2", - Integer.toString(REP.REPCMD_INSERT),"TEST2","3","3" + Integer.toString(REP.REPCMD_DELETE),"TEST2","3","3", + Integer.toString(REP.REPCMD_DELETE),"TEST0","3","4", + Integer.toString(REP.REPCMD_INSERT),"TEST1","3","5", + Integer.toString(REP.REPCMD_INSERT),"TEST2","2","6", + Integer.toString(REP.REPCMD_INSERT),"TEST0","1","7", + Integer.toString(REP.REPCMD_DELETE),"TEST1","3","8" + }; - //String[] test2 = new String[test1.length]; + static LinkedList<REPCommand> cmdlist = new LinkedList<REPCommand>(); - static LinkedList<REPCommand> cmdlist = new LinkedList<REPCommand>(); - Text text = new Text(); - - //REPコマンドの生成 void makeCommand(String[] str){ int seq = 0; try{ @@ -40,30 +43,26 @@ e.printStackTrace(); } } - //生成したコマンドのリストを表示 - void printCmdList(){ - System.out.println("---------- CmdList ----------"); - for(REPCommand r: cmdlist){ - System.out.println(r.toString()); - } - } - - void edit(){ - for(REPCommand r : cmdlist){ - text.edit(r); + + LinkedList<REPCommand> optimize(LinkedList<REPCommand> inp){ + LinkedList<REPCommand> output = new LinkedList<REPCommand>(); + LinkedList<REPCommand> input = new LinkedList<REPCommand>(); + /*for(int i = 0; i < inp.size(); i++){ + output.add(inp.get(i)); + }*/ + output = reverse(inp); + input = reverse(inp); + for(int i = 0; i < input.size(); i++){ + REPCommand r = input.get(i); + switch(r.cmd){ + case REP.REPCMD_INSERT: + break; + case REP.REPCMD_DELETE: + optimizedAddDelete(output,r,i); + break; + } } - } - - void printText(){ - System.out.println("------------ Text -----------"); - text.printAllText(); - } - LinkedList<REPCommand> optimize(LinkedList<REPCommand> input){ - LinkedList<REPCommand> output = new LinkedList<REPCommand>(); - for(REPCommand r : input){ - optimizedAdd(output,r); - } - + //return input; return reverse(output); } @@ -74,53 +73,77 @@ } return reverse; } + private void optimizedAddDelete(LinkedList<REPCommand> output, REPCommand r, int ln) { + int lineno = r.lineno; + for(int i = ln; i < output.size(); i++){ + REPCommand s = output.get(i); + switch(s.cmd){ + case REP.REPCMD_INSERT: + if(s.lineno < lineno){ + s.lineno ++; + + if(s.lineno == lineno){ + output.remove(s); + i = output.size(); + } + } + break; + case REP.REPCMD_DELETE: + /*if(s.lineno == lineno){ + input.remove(s); + }*/ + break; + } + } + } + void printCmdList(LinkedList<REPCommand> before, LinkedList<REPCommand> after){ + System.out.println("---------- CmdList1 ----------"); + for(REPCommand r: before){ + System.out.println(r.toString()); + } + System.out.println("---------- CmdList2 ----------"); + for(REPCommand s: after){ + System.out.println(s.toString()); + } + } - private void optimizedAdd(LinkedList<REPCommand> output, REPCommand r) { - switch(r.cmd){ - case REP.REPCMD_INSERT: - optimizedAddInsert(output,r);break; - case REP.REPCMD_DELETE: - optimizedAddDelete(output,r);break; + Text text1 = new Text(); + Text text2 = new Text(); + + void edit(LinkedList<REPCommand> before, LinkedList<REPCommand> after){ + for(REPCommand r : before){ + text1.edit(r); + } + for(REPCommand s : after){ + text2.edit(s); + } + } + + void printText(){ + System.out.println("------------ Text1 -----------"); + text1.printAllText(); + System.out.println("------------ Text2 -----------"); + text2.printAllText(); + } + + void checkText(){ + System.out.println("----------- Check -----------"); + if(!text1.equals(text2)){ + System.out.println("It isn't equal."); + }else{ + System.out.println("Equal."); } } - private void optimizedAddDelete(LinkedList<REPCommand> output, REPCommand r) { - for(REPCommand s : output){ - switch(r.cmd){ - case REP.REPCMD_INSERT: - break; - case REP.REPCMD_DELETE: - break; - } - } - - } - private void optimizedAddInsert(LinkedList<REPCommand> output, REPCommand r) { - int lineno = r.lineno; - for(int i = 0; i < output.size(); i++){ - REPCommand s = output.get(i); - switch(s.cmd){ - case REP.REPCMD_INSERT: - break; - case REP.REPCMD_DELETE: - if(s.lineno == lineno){ - output.remove(s); - } - break; - } - } - } + public static void main(String[] s){ RepCommandOptimizeTest rco = new RepCommandOptimizeTest(); rco.makeCommand(test1); java.util.Collections.shuffle(cmdlist); - rco.printCmdList(); - rco.edit(); + rco.printCmdList(cmdlist, rco.optimize(cmdlist)); + rco.edit(cmdlist, rco.optimize(cmdlist)); rco.printText(); - //java.util.Collections.shuffle(cmdlist); - for ( int i = 0; i < 10; ++i ) { - System.out.println(cmdlist.get(i)); - } + rco.checkText(); } }