annotate src/sample/merge/Translate.java @ 28:d01cc686b54f

*** empty log message ***
author pin
date Mon, 18 Dec 2006 19:47:03 +0900
parents b5493a5932ac
children 96306e8dc217
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
1 package sample.merge;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
2
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
3 import java.util.List;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
4 import remoteeditor.network.REP;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
5
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
6 public class Translate {
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
7 List <Rep_Cmd> userList;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
8 List <Rep_Cmd> tokenList;
28
d01cc686b54f *** empty log message ***
pin
parents: 26
diff changeset
9 private boolean REP_IGNORE = true;
21
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
10 public Translate(List<Rep_Cmd> userList, List<Rep_Cmd> tokenList){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
11 this.userList = userList;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
12 this.tokenList = tokenList;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
13 merge();
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
14 }
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
15
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
16
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
17 void merge(){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
18 Rep_Cmd h_pricmd;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
19 Rep_Cmd l_pricmd;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
20 // Iterator userListIterator = userList.iterator();
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
21 // while(userListIterator.hasNext()){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
22 for(Rep_Cmd userCmd:userList){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
23 //Iterator tokenListIterator = tokenList.iterator();
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
24 //Rep_Cmd userCmd = (Rep_Cmd)userListIterator.next();
28
d01cc686b54f *** empty log message ***
pin
parents: 26
diff changeset
25 if(userCmd.stat) continue; /* 削除される(予定)のREPコマンドの比較は無視 */
21
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
26 //while(tokenListIterator.hasNext()){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
27 for(Rep_Cmd tokenCmd:tokenList){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
28 // Rep_Cmd tokenCmd =(Rep_Cmd)tokenListIterator.next();
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
29 if(tokenCmd.stat == REP_IGNORE) continue; /* 削除される(予定)のREPコマンドの比較は無視 */
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
30 if(userCmd.stat == REP_IGNORE) break;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
31 if(userCmd.lineno < tokenCmd.lineno) { /* UsersLineNumber < TokensLineNumber */
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
32 if(userCmd.cmd == REP.REP_INSERT_CMD){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
33 tokenCmd.lineno++;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
34 }else if(userCmd.cmd == REP.REP_DELETE_CMD){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
35 tokenCmd.lineno--;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
36 }
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
37 }else if(userCmd.lineno > tokenCmd.lineno){ /* UsersLineNumber > TokensLineNumber */
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
38 if(tokenCmd.cmd == REP.REP_INSERT_CMD){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
39 userCmd.lineno++;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
40 }else if(tokenCmd.cmd == REP.REP_DELETE_CMD){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
41 userCmd.lineno--;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
42 }
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
43 }else if(userCmd.lineno == tokenCmd.lineno){ /* UsersLineNumber == TokensLineNumber */
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
44 /*
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
45 * 行番号が重なるとREPコマンドの競合が起こるので、
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
46 * どちらかが譲らないといけない。
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
47 * uid が小さい方を優先(h_pricmdに)し、
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
48 * uid が大きい方(l_pricmd)を変更する。
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
49 */
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
50 if(userCmd.eid < tokenCmd.eid){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
51 h_pricmd = userCmd;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
52 l_pricmd = tokenCmd;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
53 }else {
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
54 h_pricmd = tokenCmd;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
55 l_pricmd = userCmd;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
56 }
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
57 if(h_pricmd.cmd == REP.REP_INSERT_CMD){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
58 l_pricmd.lineno++;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
59 }else if(l_pricmd.cmd == REP.REP_REPLACE_CMD){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
60 if(l_pricmd.cmd == REP.REP_INSERT_CMD){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
61 /* h_pricmd が優先され,l_pricmd は削除(無視に)する */
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
62 l_pricmd.stat = REP_IGNORE;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
63 }else if(l_pricmd.cmd == REP.REP_DELETE_CMD){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
64 /*
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
65 * l_pricmd 側ではすでにdeleteされているので、
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
66 * h_pricmd を REP_REPLACE_CMD -> REP_INSERT_CMD へ変更。
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
67 */
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
68 h_pricmd.cmd = REP.REP_INSERT_CMD;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
69 l_pricmd.stat = REP_IGNORE;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
70 }
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
71 }else if(h_pricmd.cmd == REP.REP_DELETE_CMD){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
72 if (l_pricmd.cmd == REP.REP_INSERT_CMD) {
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
73 h_pricmd.lineno++;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
74 } else if(l_pricmd.cmd == REP.REP_REPLACE_CMD){
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
75 /*
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
76 * h_pricmd 側ではすでにdeleteされているので、
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
77 * l_pricmd 側を REP_REPLACE_CMD -> REP_INSERT_CMD へ変更。
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
78 */
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
79 l_pricmd.cmd = REP.REP_INSERT_CMD;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
80 h_pricmd.stat= REP_IGNORE;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
81 } else { /* l_pricmd->cmd == REP_DELETE_LINE_CMD */
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
82 /*
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
83 * 相手と削除する行が重なるので、
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
84 * 両方のコマンドを無視にする。
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
85 * 相手先ではすでにこの行は削除されている。
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
86 */
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
87 h_pricmd.stat = REP_IGNORE;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
88 l_pricmd.stat = REP_IGNORE;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
89 break;
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
90 }
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
91 }
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
92 }
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
93 }
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
94 }
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
95 }
8b58e6bb09c1 *** empty log message ***
pin
parents:
diff changeset
96 }