jpsp91 před 6 roky
rodič
revize
8f10ea4db0

+ 12
- 0
pom.xml Zobrazit soubor

@@ -7,6 +7,18 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>regex</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>7</source>
17
+                    <target>7</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>

+ 70
- 0
src/main/java/HamletParser.java Zobrazit soubor

@@ -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.
@@ -32,8 +34,76 @@ public class HamletParser {
32 34
         return result.toString();
33 35
     }
34 36
 
37
+
38
+
35 39
     public String getHamletData(){
36 40
         return hamletData;
37 41
     }
38 42
 
43
+
44
+
45
+
46
+
47
+    public String changedHamletToLeon(){
48
+
49
+
50
+        String replaceHamlet = "";
51
+
52
+        replaceHamlet = hamletData.replaceAll("(?i)Hamlet", "Leon");
53
+
54
+
55
+        return replaceHamlet;
56
+    }
57
+
58
+
59
+
60
+
61
+
62
+    public String changeHoratioToTariq(){
63
+
64
+        String replacedHoratio = "";
65
+
66
+        replacedHoratio = hamletData.replaceAll("(?i)Horatio", "Tariq");
67
+
68
+        return replacedHoratio;
69
+    }
70
+
71
+
72
+
73
+
74
+
75
+    public int findHamletOccurances(){
76
+
77
+        Pattern pattern = Pattern.compile("(?i)Hamlet");
78
+        Matcher matcher = pattern.matcher(hamletData);
79
+
80
+        int counter = 0;
81
+
82
+        while(matcher.find()){
83
+            counter++;
84
+        }
85
+
86
+        return counter;
87
+    }
88
+
89
+
90
+
91
+    public int findHoratioOccurances(){
92
+
93
+        Pattern pattern = Pattern.compile("(?i)Horatio");
94
+        Matcher matcher = pattern.matcher(hamletData);
95
+
96
+        int counter = 0;
97
+
98
+        while(matcher.find()){
99
+            counter++;
100
+        }
101
+
102
+        return counter;
103
+    }
104
+
105
+
106
+
107
+
108
+
39 109
 }

+ 36
- 0
src/test/java/HamletParserTest.java Zobrazit soubor

@@ -15,17 +15,53 @@ public class HamletParserTest {
15 15
 
16 16
     @Test
17 17
     public void testChangeHamletToLeon() {
18
+        //when
19
+
20
+
21
+        //expected
22
+
23
+
24
+        //actual
25
+
26
+
18 27
     }
19 28
 
20 29
     @Test
21 30
     public void testChangeHoratioToTariq() {
31
+        //when
32
+
33
+
34
+        //expected
35
+
36
+
37
+        //actual
38
+
39
+
22 40
     }
23 41
 
24 42
     @Test
25 43
     public void testFindHoratio() {
44
+        //when
45
+
46
+
47
+        //expected
48
+
49
+
50
+        //actual
51
+
52
+
26 53
     }
27 54
 
28 55
     @Test
29 56
     public void testFindHamlet() {
57
+        //when
58
+
59
+
60
+        //expected
61
+
62
+
63
+        //actual
64
+
65
+
30 66
     }
31 67
 }

+ 5383
- 0
target/classes/hamlet.txt
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor