Procházet zdrojové kódy

done but will be making more tests

Whitney Martinez před 6 roky
rodič
revize
70c4168ffc

+ 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>

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

@@ -1,6 +1,10 @@
1 1
 import java.io.File;
2 2
 import java.io.IOException;
3
+import java.nio.file.Files;
4
+import java.nio.file.Paths;
3 5
 import java.util.Scanner;
6
+import java.util.regex.Matcher;
7
+import java.util.regex.Pattern;
4 8
 
5 9
 /**
6 10
  * Created by thook on 10/7/15.
@@ -33,7 +37,61 @@ public class HamletParser {
33 37
     }
34 38
 
35 39
     public String getHamletData(){
40
+
36 41
         return hamletData;
37 42
     }
38 43
 
44
+    public void changeFromHamletToLeon() {
45
+
46
+        String patternString1 = ("HAMLET");
47
+
48
+
49
+        System.out.println(Pattern.compile(patternString1,Pattern.
50
+                CASE_INSENSITIVE).matcher(hamletData).replaceAll("LEON"));
51
+
52
+
53
+    }
54
+    public void changeFromHoratioToTariq(){
55
+
56
+        String patternString2 = ("HORATIO");
57
+
58
+
59
+        System.out.println(Pattern.compile(patternString2,Pattern.
60
+                CASE_INSENSITIVE).matcher(hamletData).replaceAll("TARIQ"));
61
+
62
+
63
+    }
64
+
65
+
66
+    public int findHamlet(){
67
+        String patternHam = ("HAMLET");
68
+        Pattern pattern = Pattern.compile(patternHam,Pattern.CASE_INSENSITIVE);
69
+        Matcher matcher = pattern.matcher(hamletData);
70
+        int counter = 0;
71
+
72
+        while (matcher.find()){
73
+            counter++;
74
+
75
+        }
76
+        System.out.println(counter);
77
+       return counter;
78
+    }
79
+    public int findHoratio(){
80
+        //Trying both methods out
81
+        String REGEX_FIND_WORD="(?i).*?\\b%s\\b.*?";
82
+
83
+        String patternHam = ("HORATIO");
84
+        String regex = String.format(REGEX_FIND_WORD, Pattern.quote(patternHam));
85
+        Pattern pattern = Pattern.compile(regex);
86
+        Matcher matcher = pattern.matcher(hamletData);
87
+        int counter = 0;
88
+
89
+        while (matcher.find()){
90
+            counter++;
91
+
92
+        }
93
+        System.out.println(counter);
94
+        return counter;
95
+    }
96
+
39 97
 }

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

@@ -1,6 +1,10 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
5
+import java.util.regex.Matcher;
6
+import java.util.regex.Pattern;
7
+
4 8
 import static org.junit.Assert.*;
5 9
 
6 10
 public class HamletParserTest {
@@ -15,17 +19,54 @@ public class HamletParserTest {
15 19
 
16 20
     @Test
17 21
     public void testChangeHamletToLeon() {
22
+        //Given: Objective, Change Hamlet to Leon
23
+
24
+        hamletParser.changeFromHamletToLeon();
25
+        //When
26
+
27
+        System.out.println(hamletText);
28
+
29
+        //Then
30
+
31
+
32
+
18 33
     }
19 34
 
20 35
     @Test
21 36
     public void testChangeHoratioToTariq() {
37
+        //Given: Objective, Change Hamlet to Leon
38
+
39
+        hamletParser.changeFromHoratioToTariq();
40
+        //When
41
+
42
+        System.out.println(hamletText);
43
+
44
+        //Then
22 45
     }
23 46
 
24 47
     @Test
25 48
     public void testFindHoratio() {
49
+
50
+        //Given
51
+
52
+        //When
53
+        hamletParser.findHoratio();
54
+
55
+        //Then
56
+
57
+        Assert.assertEquals(158,hamletParser.findHoratio());
26 58
     }
27 59
 
28 60
     @Test
29 61
     public void testFindHamlet() {
62
+
63
+        //Given
64
+
65
+        //When
66
+         hamletParser.findHamlet();
67
+
68
+        //Then
69
+
70
+       Assert.assertEquals(472,hamletParser.findHamlet());
30 71
     }
31 72
 }

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