diff src/pathfinder/mergetest/EditorObject.java @ 152:09ad66f62f4a before_REP_meeting_on_080822

*** empty log message ***
author pin
date Fri, 22 Aug 2008 15:48:52 +0900
parents
children 1a2269c820df
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pathfinder/mergetest/EditorObject.java	Fri Aug 22 15:48:52 2008 +0900
@@ -0,0 +1,82 @@
+package pathfinder.mergetest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import remoteeditor.command.REPCommand;
+import sample.merge.TranslaterImp1;
+
+public class EditorObject<P> {
+	
+	int eid;
+	private ChannelSimulator<P> channel;
+	private TranslaterImp1 translater;
+	private List<REPCommand> sentList;
+
+	public EditorObject(int i, ChannelSimulator<P> cs) {
+		// TODO Auto-generated constructor stub
+		eid = i;
+		channel = cs;
+	}
+
+	public EditorObject(int i, ChannelSimulator<P> cs, TranslaterImp1 imp1) {
+		// TODO Auto-generated constructor stub
+		eid = i;
+		channel = cs;
+		translater = imp1;
+		sentList = new ArrayList<REPCommand>();
+	}
+
+	public ChannelSimulator<P> getChannel() {
+		// TODO Auto-generated method stub
+		return channel;
+	}
+
+	public int getEID() {
+		// TODO Auto-generated method stub
+		return eid;
+	}
+
+	public REPCommand receive(REPCommand command) {
+		// TODO Auto-generated method stub
+		
+		if(command.eid == eid){
+			if(checkReturnCommand(command)){
+				REPCommand[] cmds = translater.catchOwnCommand(command);
+				sendMergedCommand(cmds);
+				return null;
+			}else{
+				sentList.add(command);
+			}	
+		}
+		
+		return command;
+	}
+
+	private boolean checkReturnCommand(REPCommand command) {
+		// TODO Auto-generated method stub
+		
+		if(sentList.size() > 0){
+			if(sentList.get(0).seq == command.seq){
+				return true;
+			}
+		}
+		
+		return false;
+	}
+
+	private void sendMergedCommand(REPCommand[] cmds) {
+		// TODO Auto-generated method stub
+		for(int i = 0; i < cmds.length; i++){
+			channel.write((P) cmds[i]);
+		}
+	}
+
+	public void send(REPCommand command) {
+		// TODO Auto-generated method stub
+		if(command !=null){
+			channel.write((P) command);
+		}
+	}
+
+}