view src/pathfinder/mergetest/Text.java @ 154:6a3c982bd72a

*** empty log message ***
author pin
date Sun, 24 Aug 2008 13:43:50 +0900
parents 6326e5ea4595
children
line wrap: on
line source

package pathfinder.mergetest;

import java.util.Arrays;
import java.util.LinkedList;

import remoteeditor.command.REPCommand;
import remoteeditor.network.REP;

public class Text {

	LinkedList<String> strList;

	public Text(String[] _strings){
		strList = new LinkedList<String>(Arrays.asList(_strings));
	}

	public String insert(int i, String str){
		assert 0<i && i<strList.size();
		strList.add(i, str);
		return null;
	}
	public String delete(int i){
		assert 0<i && i<strList.size();
		return strList.remove(i);
	}
	public String replace(int i, String str){
		assert 0<i && i<strList.size();
		String replaced = strList.get(i);
		strList.set(i, str);
		return replaced;
	}
	public String get(int i){
		assert 0<i && i<strList.size();
		return strList.get(i);
	}
	public String edit(REPCommand cmd){
		if (cmd.cmd==REP.REPCMD_INSERT)        return insert(cmd.lineno, cmd.string);
		else if (cmd.cmd==REP.REPCMD_REPLACE)  return replace(cmd.lineno, cmd.string);
		else if (cmd.cmd==REP.REPCMD_DELETE)   return delete(cmd.lineno);
		//else assert false;
		return null;
	}

	public int size(){
		return strList.size();
	}
	public void printAllText(){
		for( String str: strList){
			System.out.println(str);
		}
	}
	public boolean equals(Text _target){
		return strList.equals(_target.strList);
	}
}