226
|
1 package test;
|
|
2
|
|
3 import java.util.Arrays;
|
|
4 import java.util.LinkedList;
|
|
5 import java.util.List;
|
|
6
|
|
7 import rep.REPCommand;
|
|
8 import rep.REP;
|
|
9
|
|
10 public class Text {
|
|
11
|
|
12 List<String> strList;
|
|
13
|
|
14 public Text(String[] _strings){
|
|
15 strList = new LinkedList<String>(Arrays.asList(_strings));
|
|
16 }
|
|
17 public Text(List<String> _strings){
|
|
18 strList = new LinkedList<String>(_strings);
|
|
19 }
|
|
20
|
|
21 public String insert(int i, String str){
|
|
22 assert 0<i && i<strList.size();
|
|
23 strList.add(i, str);
|
|
24 return null;
|
|
25 }
|
|
26 public String delete(int i){
|
|
27 assert 0<i && i<strList.size();
|
|
28 return strList.remove(i);
|
|
29 }
|
|
30 public String replace(int i, String str){
|
|
31 assert 0<i && i<strList.size();
|
|
32 String replaced = strList.get(i);
|
|
33 strList.set(i, str);
|
|
34 return replaced;
|
|
35 }
|
|
36 public String get(int i){
|
|
37 assert 0<i && i<strList.size();
|
|
38 return strList.get(i);
|
|
39 }
|
|
40 public String edit(REPCommand cmd){
|
|
41 if (cmd.cmd==REP.REPCMD_INSERT) return insert(cmd.lineno, cmd.string);
|
|
42 else if (cmd.cmd==REP.REPCMD_REPLACE) return replace(cmd.lineno, cmd.string);
|
|
43 else if (cmd.cmd==REP.REPCMD_DELETE) return delete(cmd.lineno);
|
|
44 //else assert false;
|
|
45 return null;
|
|
46 }
|
|
47 public void edit(List<REPCommand> cmdlist){
|
|
48 for (REPCommand cmd: cmdlist){
|
|
49 edit(cmd);
|
|
50 }
|
|
51 }
|
|
52
|
|
53 public int size(){
|
|
54 return strList.size();
|
|
55 }
|
|
56 public void printAllText(){
|
|
57 for( String str: strList){
|
|
58 System.out.println(str);
|
|
59 }
|
|
60 }
|
|
61 public boolean equals(Text _target){
|
|
62 return strList.equals(_target.strList);
|
|
63 }
|
|
64 }
|