|
@@ -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.
|
|
@@ -8,6 +10,8 @@ import java.util.Scanner;
|
8
|
10
|
public class HamletParser {
|
9
|
11
|
|
10
|
12
|
private String hamletData;
|
|
13
|
+ private Pattern hamlet = Pattern.compile("hamlet", Pattern.CASE_INSENSITIVE);
|
|
14
|
+ private Pattern horatio = Pattern.compile("horatio", Pattern.CASE_INSENSITIVE);
|
11
|
15
|
|
12
|
16
|
public HamletParser(){
|
13
|
17
|
this.hamletData = loadFile();
|
|
@@ -36,4 +40,50 @@ public class HamletParser {
|
36
|
40
|
return hamletData;
|
37
|
41
|
}
|
38
|
42
|
|
39
|
|
-}
|
|
43
|
+ public String changeHamletToLeonLower(String text) {
|
|
44
|
+ Pattern pttrn = Pattern.compile("Hamlet");
|
|
45
|
+ Matcher mtchr = pttrn.matcher(text);
|
|
46
|
+ return mtchr.replaceAll("Leon");
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ public String changeHamletToLeonUpper(String text) {
|
|
50
|
+ Pattern pttrn = Pattern.compile("HAMLET");
|
|
51
|
+ Matcher mtchr = pttrn.matcher(text);
|
|
52
|
+ return mtchr.replaceAll("LEON");
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ public String changeHoratioToTariqLower(String text) {
|
|
56
|
+ Pattern pttrn = Pattern.compile("Horatio");
|
|
57
|
+ Matcher mtchr = pttrn.matcher(text);
|
|
58
|
+ return mtchr.replaceAll("Tariq");
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ public String changeHoratioToTariqUpper(String text) {
|
|
62
|
+ Pattern pttrn = Pattern.compile("HORATIO");
|
|
63
|
+ Matcher mtchr = pttrn.matcher(text);
|
|
64
|
+ return mtchr.replaceAll("TARIQ");
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ public boolean findHamlet(String text) {
|
|
68
|
+ Matcher mtchr = hamlet.matcher(text);
|
|
69
|
+ return mtchr.find();
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ public boolean findHoratio(String text) {
|
|
73
|
+ Matcher mtchr = horatio.matcher(text);
|
|
74
|
+ return mtchr.find();
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+ private void replaceAndPrint() {
|
|
78
|
+ hamletData = changeHoratioToTariqUpper(hamletData);
|
|
79
|
+ hamletData = changeHoratioToTariqLower(hamletData);
|
|
80
|
+ hamletData = changeHamletToLeonUpper(hamletData);
|
|
81
|
+ hamletData = changeHamletToLeonLower(hamletData);
|
|
82
|
+ System.out.println(hamletData);
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ public static void main(String[] args) {
|
|
86
|
+ HamletParser hp = new HamletParser();
|
|
87
|
+ hp.replaceAndPrint();
|
|
88
|
+ }
|
|
89
|
+}
|