Mercurial > hg > RemoteEditor > REPSessionManager
diff rep/translator/Translate.java @ 324:e235998427a6 before-merge-fix
try to fix merger
author | kono |
---|---|
date | Sat, 11 Oct 2008 16:31:03 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/translator/Translate.java Sat Oct 11 16:31:03 2008 +0900 @@ -0,0 +1,149 @@ +package rep.translator; + +import java.util.List; + +import rep.REPCommand; +import rep.REP; + +public class Translate { + List <REPCommand> userList; + List <REPCommand> tokenList; + private boolean REP_IGNORE = true; + public int myeid; + + public Translate(){ + + } + + //public Translate(List<REPCommand> userList, List<REPCommand> tokenList){ + // this.userList = userList; + // this.tokenList = tokenList; + //merge(); + //} + + + + public Translate(List<REPCommand> userCmdList, List<REPCommand> tokenCmdList) { + this.userList = userCmdList; + this.tokenList = tokenCmdList; + } + + public void addUserList(REPCommand usercmd){ + userList.add(usercmd); + } + public void addTokenList(REPCommand tokencmd){ + if(tokencmd.eid == myeid){ + tokenList.clear(); + userList.remove(0); + }else{ + tokenList.add(tokencmd); + } + } + + void merge(){ + REPCommand h_pricmd; + REPCommand l_pricmd; +// Iterator userListIterator = userList.iterator(); +// while(userListIterator.hasNext()){ + for(REPCommand userCmd:userList){ + //Iterator tokenListIterator = tokenList.iterator(); + //Rep_Cmd userCmd = (Rep_Cmd)userListIterator.next(); + if(userCmd.stat) continue; /* �폜�����(�\��)��REP�R�}���h�̔�r�͖��� */ + //while(tokenListIterator.hasNext()){ + for(REPCommand tokenCmd:tokenList){ +// Rep_Cmd tokenCmd =(Rep_Cmd)tokenListIterator.next(); + if(tokenCmd.eid == myeid) { + if(tokenCmd.seq == userCmd.seq){ + tokenCmd.stat = REP_IGNORE; + userCmd.stat = REP_IGNORE; + } + } + if(tokenCmd.stat == REP_IGNORE) continue; /* �폜�����(�\��)��REP�R�}���h�̔�r�͖��� */ + if(userCmd.stat == REP_IGNORE) break; + if(userCmd.lineno < tokenCmd.lineno) { /* UsersLineNumber < TokensLineNumber */ + if(userCmd.cmd == REP.REPCMD_INSERT){ + tokenCmd.lineno++; + }else if(userCmd.cmd == REP.REPCMD_DELETE){ + tokenCmd.lineno--; + } + }else if(userCmd.lineno > tokenCmd.lineno){ /* UsersLineNumber > TokensLineNumber */ + if(tokenCmd.cmd == REP.REPCMD_INSERT){ + userCmd.lineno++; + }else if(tokenCmd.cmd == REP.REPCMD_DELETE){ + userCmd.lineno--; + } + }else if(userCmd.lineno == tokenCmd.lineno){ /* UsersLineNumber == TokensLineNumber */ + /* + * �s�ԍ����d�Ȃ��REP�R�}���h�̋������N����̂ŁA + * �ǂ��炩�����Ȃ��Ƃ����Ȃ��B + * uid �����������D��(h_pricmd��)���A + * uid ���傫����(l_pricmd)��ύX����B + */ + if(userCmd.eid < tokenCmd.eid){ + h_pricmd = userCmd; + l_pricmd = tokenCmd; + }else { + h_pricmd = tokenCmd; + l_pricmd = userCmd; + } + if(h_pricmd.cmd == REP.REPCMD_INSERT){ + l_pricmd.lineno++; + }else if(l_pricmd.cmd == REP.REPCMD_REPLACE){ + if(l_pricmd.cmd == REP.REPCMD_INSERT){ + /* h_pricmd ���D�悳��,l_pricmd �͍폜(������)���� */ + l_pricmd.stat = REP_IGNORE; + }else if(l_pricmd.cmd == REP.REPCMD_DELETE){ + /* + * l_pricmd ���ł͂��ł�delete����Ă���̂ŁA + * h_pricmd �� REP_REPLACE_CMD -> REP_INSERT_CMD �֕ύX�B + */ + h_pricmd.cmd = REP.REPCMD_INSERT; + l_pricmd.stat = REP_IGNORE; + } + }else if(h_pricmd.cmd == REP.REPCMD_DELETE){ + if (l_pricmd.cmd == REP.REPCMD_INSERT) { + h_pricmd.lineno++; + } else if(l_pricmd.cmd == REP.REPCMD_REPLACE){ + /* + * h_pricmd ���ł͂��ł�delete����Ă���̂ŁA + * l_pricmd ���� REP_REPLACE_CMD -> REP_INSERT_CMD �֕ύX�B + */ + l_pricmd.cmd = REP.REPCMD_INSERT; + h_pricmd.stat= REP_IGNORE; + } else { /* l_pricmd->cmd == REP_DELETE_LINE_CMD */ + /* + * ����ƍ폜����s���d�Ȃ�̂ŁA + * ����̃R�}���h���ɂ���B + * �����ł͂��łɂ��̍s�͍폜����Ă���B + */ + h_pricmd.stat = REP_IGNORE; + l_pricmd.stat = REP_IGNORE; + break; + } + } + } + } + } +// Iterator userListIterator = userList.iterator(); +// while(userListIterator.hasNext()){ +// //Iterator tokenListIterator = tokenList.iterator(); +// REPCommand userCmd = (REPCommand)userListIterator.next(); +// if(userCmd.stat == REP_IGNORE){ +// userListIterator.remove(); +// } +// } +// +// Iterator tokenListIterator = tokenList.iterator(); +// while(tokenListIterator.hasNext()){ +// REPCommand tokenCmd = (REPCommand)tokenListIterator.next(); +// if(tokenCmd.stat == REP_IGNORE){ +// tokenListIterator.remove(); +// } +// } + } + + public void setMyEID(int myeid2) { + // TODO Auto-generated method stub + myeid = myeid2; + } +}