Browse Source

complete?

Seth 6 years ago
parent
commit
07186ad465
4 changed files with 5430 additions and 0 deletions
  1. 5
    0
      pom.xml
  2. 26
    0
      src/main/java/HamletParser.java
  3. 16
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 5
- 0
pom.xml View File

8
     <artifactId>regex</artifactId>
8
     <artifactId>regex</artifactId>
9
     <version>1.0-SNAPSHOT</version>
9
     <version>1.0-SNAPSHOT</version>
10
 
10
 
11
+    <properties>
12
+        <maven.compiler.source>1.8</maven.compiler.source>
13
+        <maven.compiler.target>1.8</maven.compiler.target>
14
+    </properties>
15
+
11
     <dependencies>
16
     <dependencies>
12
         <dependency>
17
         <dependency>
13
             <groupId>junit</groupId>
18
             <groupId>junit</groupId>

+ 26
- 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 boolean findHoratio() {
42
+        Pattern pattern = Pattern.compile(("Horatio"));
43
+        Matcher matcher = pattern.matcher(hamletData);
44
+        return matcher.find();
45
+    }
46
+
47
+    public void changeHorationToTariq() {
48
+        Pattern pattern = Pattern.compile(("Horatio"));
49
+        Matcher matcher = pattern.matcher(hamletData);
50
+        hamletData = matcher.replaceAll("Tariq");
51
+    }
52
+
53
+    public boolean findHamlet() {
54
+        Pattern pattern = Pattern.compile(("Hamlet"));
55
+        Matcher matcher = pattern.matcher(hamletData);
56
+        return matcher.find();
57
+    }
58
+
59
+    public void changeHamlettToLeon() {
60
+        Pattern pattern = Pattern.compile("Hamlet");
61
+        Matcher matcher = pattern.matcher(hamletData);
62
+        hamletData = matcher.replaceAll("Leon");
63
+    }
64
+
39
 }
65
 }

+ 16
- 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
 
15
 
16
 
16
     @Test
17
     @Test
17
     public void testChangeHamletToLeon() {
18
     public void testChangeHamletToLeon() {
19
+        hamletParser.changeHamlettToLeon();
20
+       boolean actual = hamletParser.findHamlet();
21
+
22
+
23
+        Assert.assertFalse(actual);
18
     }
24
     }
19
 
25
 
20
     @Test
26
     @Test
21
     public void testChangeHoratioToTariq() {
27
     public void testChangeHoratioToTariq() {
28
+        hamletParser.changeHorationToTariq();
29
+        boolean actual = hamletParser.findHoratio();
30
+
31
+        Assert.assertFalse(actual);
22
     }
32
     }
23
 
33
 
24
     @Test
34
     @Test
25
     public void testFindHoratio() {
35
     public void testFindHoratio() {
36
+        boolean actual = hamletParser.findHoratio();
37
+
38
+        Assert.assertTrue(actual);
26
     }
39
     }
27
 
40
 
28
     @Test
41
     @Test
29
     public void testFindHamlet() {
42
     public void testFindHamlet() {
43
+        boolean actual = hamletParser.findHamlet();
44
+
45
+        Assert.assertTrue(actual);
30
     }
46
     }
31
 }
47
 }

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