Browse Source

done but will be making more tests

Whitney Martinez 6 years ago
parent
commit
70c4168ffc
4 changed files with 5494 additions and 0 deletions
  1. 12
    0
      pom.xml
  2. 58
    0
      src/main/java/HamletParser.java
  3. 41
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml View File

7
     <groupId>com.zipcodewilmington</groupId>
7
     <groupId>com.zipcodewilmington</groupId>
8
     <artifactId>regex</artifactId>
8
     <artifactId>regex</artifactId>
9
     <version>1.0-SNAPSHOT</version>
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
     <dependencies>
23
     <dependencies>
12
         <dependency>
24
         <dependency>

+ 58
- 0
src/main/java/HamletParser.java View File

1
 import java.io.File;
1
 import java.io.File;
2
 import java.io.IOException;
2
 import java.io.IOException;
3
+import java.nio.file.Files;
4
+import java.nio.file.Paths;
3
 import java.util.Scanner;
5
 import java.util.Scanner;
6
+import java.util.regex.Matcher;
7
+import java.util.regex.Pattern;
4
 
8
 
5
 /**
9
 /**
6
  * Created by thook on 10/7/15.
10
  * Created by thook on 10/7/15.
33
     }
37
     }
34
 
38
 
35
     public String getHamletData(){
39
     public String getHamletData(){
40
+
36
         return hamletData;
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 View File

1
+import org.junit.Assert;
1
 import org.junit.Before;
2
 import org.junit.Before;
2
 import org.junit.Test;
3
 import org.junit.Test;
3
 
4
 
5
+import java.util.regex.Matcher;
6
+import java.util.regex.Pattern;
7
+
4
 import static org.junit.Assert.*;
8
 import static org.junit.Assert.*;
5
 
9
 
6
 public class HamletParserTest {
10
 public class HamletParserTest {
15
 
19
 
16
     @Test
20
     @Test
17
     public void testChangeHamletToLeon() {
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
     @Test
35
     @Test
21
     public void testChangeHoratioToTariq() {
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
     @Test
47
     @Test
25
     public void testFindHoratio() {
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
     @Test
60
     @Test
29
     public void testFindHamlet() {
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
File diff suppressed because it is too large
View File