|
@@ -1,6 +1,8 @@
|
1
|
1
|
import java.io.File;
|
2
|
2
|
import java.io.IOException;
|
3
|
3
|
import java.util.Scanner;
|
|
4
|
+import java.util.regex.Matcher;
|
|
5
|
+import java.util.regex.Pattern;
|
4
|
6
|
|
5
|
7
|
/**
|
6
|
8
|
* Created by thook on 10/7/15.
|
|
@@ -36,4 +38,31 @@ public class HamletParser {
|
36
|
38
|
return hamletData;
|
37
|
39
|
}
|
38
|
40
|
|
|
41
|
+ protected String replaceAllWith(String replace, String in, String with) {
|
|
42
|
+
|
|
43
|
+ Pattern pattern = Pattern.compile(replace, Pattern.CASE_INSENSITIVE);
|
|
44
|
+ Matcher matcher = pattern.matcher(in);
|
|
45
|
+
|
|
46
|
+ return matcher.replaceAll(with);
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ protected String replaceAllHamletWithLeon() {
|
|
50
|
+ return replaceAllHamletWithLeon(hamletData);
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ protected String replaceAllHamletWithLeon(String input) {
|
|
54
|
+ return replaceAllWith("Hamlet", input, "Leon");
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ protected String replaceAllHoratioWithTariq() {
|
|
58
|
+ return replaceAllHoratioWithTariq(hamletData);
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ protected String replaceAllHoratioWithTariq(String input) {
|
|
62
|
+ return replaceAllWith("Horatio", input, "Tariq");
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ protected String replaceBoth() {
|
|
66
|
+ return replaceAllHamletWithLeon(replaceAllHoratioWithTariq());
|
|
67
|
+ }
|
39
|
68
|
}
|