|
@@ -1,6 +1,12 @@
|
1
|
1
|
import java.io.File;
|
2
|
2
|
import java.io.IOException;
|
|
3
|
+import java.nio.file.Files;
|
|
4
|
+import java.util.List;
|
3
|
5
|
import java.util.Scanner;
|
|
6
|
+import java.util.regex.Matcher;
|
|
7
|
+import java.util.regex.Pattern;
|
|
8
|
+import java.util.stream.Collectors;
|
|
9
|
+import java.util.stream.Stream;
|
4
|
10
|
|
5
|
11
|
/**
|
6
|
12
|
* Created by thook on 10/7/15.
|
|
@@ -9,6 +15,7 @@ public class HamletParser {
|
9
|
15
|
|
10
|
16
|
private String hamletData;
|
11
|
17
|
|
|
18
|
+
|
12
|
19
|
public HamletParser(){
|
13
|
20
|
this.hamletData = loadFile();
|
14
|
21
|
}
|
|
@@ -22,13 +29,13 @@ public class HamletParser {
|
22
|
29
|
while(scanner.hasNextLine()){
|
23
|
30
|
String line = scanner.nextLine();
|
24
|
31
|
result.append(line).append("\n");
|
25
|
|
- }
|
26
|
32
|
|
|
33
|
+ }
|
27
|
34
|
scanner.close();
|
28
|
35
|
}catch(IOException e){
|
29
|
36
|
e.printStackTrace();
|
30
|
37
|
}
|
31
|
|
-
|
|
38
|
+ System.out.println(result.toString());
|
32
|
39
|
return result.toString();
|
33
|
40
|
}
|
34
|
41
|
|
|
@@ -36,4 +43,27 @@ public class HamletParser {
|
36
|
43
|
return hamletData;
|
37
|
44
|
}
|
38
|
45
|
|
|
46
|
+ public void replaceHamlet(){
|
|
47
|
+ Pattern pattern = Pattern.compile("Hamlet", Pattern.CASE_INSENSITIVE);
|
|
48
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
49
|
+ hamletData = matcher.replaceAll("Leon");
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ public void replaceHoratio(){
|
|
53
|
+ Pattern pattern = Pattern.compile("Horatio", Pattern.CASE_INSENSITIVE);
|
|
54
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
55
|
+ hamletData = matcher.replaceAll("Tariq");
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ public boolean findHamlet() {
|
|
59
|
+ Pattern pattern = Pattern.compile("Hamlet",Pattern.CASE_INSENSITIVE);
|
|
60
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
61
|
+ return matcher.find();
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ public boolean findHoratio() {
|
|
65
|
+ Pattern pattern = Pattern.compile("Horatio",Pattern.CASE_INSENSITIVE);
|
|
66
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
67
|
+ return matcher.find();
|
|
68
|
+ }
|
39
|
69
|
}
|