|
@@ -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.
|
|
@@ -23,8 +25,6 @@ public class HamletParser {
|
23
|
25
|
String line = scanner.nextLine();
|
24
|
26
|
result.append(line).append("\n");
|
25
|
27
|
}
|
26
|
|
-
|
27
|
|
- scanner.close();
|
28
|
28
|
}catch(IOException e){
|
29
|
29
|
e.printStackTrace();
|
30
|
30
|
}
|
|
@@ -36,4 +36,33 @@ public class HamletParser {
|
36
|
36
|
return hamletData;
|
37
|
37
|
}
|
38
|
38
|
|
|
39
|
+ private Matcher matchingwords(String regex){
|
|
40
|
+ Pattern pattern = Pattern.compile(regex);
|
|
41
|
+ Matcher matcher = pattern.matcher(this.hamletData.toLowerCase());
|
|
42
|
+ return matcher;
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ public void changeHamletToLeon() {
|
|
46
|
+ if(findHamlet()) {
|
|
47
|
+ Matcher matcher = matchingwords("Hamlet");
|
|
48
|
+ matcher.replaceAll("Leon");
|
|
49
|
+ }
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ public void changeHoratioToTariq() {
|
|
53
|
+ if(findHamlet()) {
|
|
54
|
+ Matcher matcher = matchingwords("Horatio");
|
|
55
|
+ matcher.replaceAll("Tariq");
|
|
56
|
+ }
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ public boolean findHoratio() {
|
|
60
|
+ Matcher matcher = matchingwords("horatio");
|
|
61
|
+ return matcher.find();
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ public boolean findHamlet() {
|
|
65
|
+ Matcher matcher = matchingwords("hamlet");
|
|
66
|
+ return matcher.find();
|
|
67
|
+ }
|
39
|
68
|
}
|