Arin Turpin 6 years ago
parent
commit
b3bef27205
4 changed files with 5465 additions and 0 deletions
  1. 12
    0
      pom.xml
  2. 35
    0
      src/main/java/HamletParser.java
  3. 35
    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>

+ 35
- 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.util.Scanner;
3
 import java.util.Scanner;
4
+import java.util.regex.Matcher;
5
+import java.util.regex.Pattern;
4
 
6
 
5
 /**
7
 /**
6
  * Created by thook on 10/7/15.
8
  * Created by thook on 10/7/15.
36
         return hamletData;
38
         return hamletData;
37
     }
39
     }
38
 
40
 
41
+    public void setHamletData(String hamletData) {
42
+        this.hamletData = hamletData;
43
+    }
44
+
45
+    public void changeHamlet(){
46
+        Pattern hamlet = Pattern.compile("^Hamlet");
47
+        Matcher matches = hamlet.matcher(hamletData);
48
+//        for(hamlet : hamletData){
49
+//            matches.replaceAll("Leon");
50
+//        }
51
+        matches.replaceAll("Leon");
52
+    }
53
+
54
+    public void changeHamlet2(){
55
+        Pattern hamlet2 = Pattern.compile("^HAMLET");
56
+        Matcher matches = hamlet2.matcher(hamletData);
57
+        matches.replaceAll("LEON");
58
+
59
+    }
60
+
61
+    public void changeHoratio(){
62
+        Pattern horatio = Pattern.compile("^Horatio");
63
+        Matcher matches = horatio.matcher(hamletData);
64
+        matches.replaceAll("Tariq");
65
+
66
+    }
67
+
68
+    public void changeHoratio2(){
69
+        Pattern horatio2 = Pattern.compile("^HORATIO");
70
+        Matcher matches = horatio2.matcher(hamletData);
71
+        matches.replaceAll("TARIQ");
72
+
73
+    }
39
 }
74
 }

+ 35
- 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.ArrayList;
6
+import java.util.regex.Matcher;
7
+import java.util.regex.Pattern;
8
+
4
 import static org.junit.Assert.*;
9
 import static org.junit.Assert.*;
5
 
10
 
6
 public class HamletParserTest {
11
 public class HamletParserTest {
7
     private String hamletText;
12
     private String hamletText;
8
     private HamletParser hamletParser;
13
     private HamletParser hamletParser;
14
+   // HamletParser hamletParserr = new HamletParser();
9
 
15
 
10
     @Before
16
     @Before
11
     public void setUp() {
17
     public void setUp() {
15
 
21
 
16
     @Test
22
     @Test
17
     public void testChangeHamletToLeon() {
23
     public void testChangeHamletToLeon() {
24
+        ArrayList<Matcher> x = new ArrayList<>();
25
+        int counter = 0;
26
+        hamletParser.changeHamlet();
27
+        hamletParser.changeHamlet2();
28
+        Pattern hamlet = Pattern.compile("^Hamlet|HAMLET");
29
+        Matcher matches = hamlet.matcher(hamletText);
30
+        x.add(matches);
31
+        x.isEmpty();
32
+        Assert.assertTrue(x.isEmpty() == false);
18
     }
33
     }
19
 
34
 
20
     @Test
35
     @Test
21
     public void testChangeHoratioToTariq() {
36
     public void testChangeHoratioToTariq() {
37
+        ArrayList<Matcher> x = new ArrayList<Matcher>();
38
+        int counter = 0;
39
+        hamletParser.changeHoratio();
40
+        hamletParser.changeHoratio2();
41
+        Pattern hamlet = Pattern.compile("^Horatio|HORATIO");
42
+        Matcher matches = hamlet.matcher(hamletText);
43
+        x.add(matches);
44
+        x.isEmpty();
45
+//        if(matches.find()){
46
+//            counter++;
47
+//        }
48
+
49
+
50
+//        if(hamletText.contains(hamlet.split("")){
51
+//
52
+//        }
53
+        Assert.assertTrue(x.isEmpty() == false);
22
     }
54
     }
23
 
55
 
24
     @Test
56
     @Test
25
     public void testFindHoratio() {
57
     public void testFindHoratio() {
58
+        Assert.assertTrue(hamletText.contains("Horatio") == true);
59
+
26
     }
60
     }
27
 
61
 
28
     @Test
62
     @Test
29
     public void testFindHamlet() {
63
     public void testFindHamlet() {
64
+        Assert.assertTrue(hamletText.contains("Hamlet") == true);
30
     }
65
     }
31
 }
66
 }

+ 5383
- 0
target/classes/hamlet.txt
File diff suppressed because it is too large
View File