Brandon Defrancis 6 jaren geleden
bovenliggende
commit
b32d158113
4 gewijzigde bestanden met toevoegingen van 5444 en 0 verwijderingen
  1. 12
    0
      pom.xml
  2. 36
    0
      src/main/java/HamletParser.java
  3. 13
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Bestand weergeven

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

+ 36
- 0
src/main/java/HamletParser.java Bestand weergeven

@@ -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.
@@ -36,4 +38,38 @@ public class HamletParser {
36 38
         return hamletData;
37 39
     }
38 40
 
41
+    public void hamletToLeon(){
42
+        Pattern pattern = Pattern.compile("Hamlet", Pattern.CASE_INSENSITIVE);
43
+        Matcher matcher = pattern.matcher(hamletData);
44
+        this.hamletData = matcher.replaceAll("Leon");
45
+
46
+    }
47
+
48
+    public void horatioToTariq() {
49
+        Pattern pattern = Pattern.compile("Horatio", Pattern.CASE_INSENSITIVE);
50
+        Matcher matcher = pattern.matcher(hamletData);
51
+        this.hamletData = matcher.replaceAll("Tariq");
52
+    }
53
+
54
+    public boolean findHoratio() {
55
+        final Scanner sc = new Scanner(hamletData);
56
+        while(sc.hasNextLine()){
57
+            final String fileLine = sc.nextLine();
58
+            if (fileLine.contains("Horatio")) {
59
+                return true;
60
+            }
61
+        }
62
+        return false;
63
+    }
64
+
65
+    public boolean findHamlet() {
66
+        final Scanner sc = new Scanner(hamletData);
67
+        while(sc.hasNextLine()){
68
+            final String fileLine = sc.nextLine();
69
+            if (fileLine.contains("Hamlet")) {
70
+                return true;
71
+            }
72
+        }
73
+        return false;
74
+    }
39 75
 }

+ 13
- 0
src/test/java/HamletParserTest.java Bestand weergeven

@@ -1,3 +1,4 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
@@ -15,17 +16,29 @@ public class HamletParserTest {
15 16
 
16 17
     @Test
17 18
     public void testChangeHamletToLeon() {
19
+        //boolean leon = hamletParser.hamletToLeon();
20
+        hamletParser.hamletToLeon();
21
+        Assert.assertFalse(hamletParser.findHamlet());
18 22
     }
19 23
 
20 24
     @Test
21 25
     public void testChangeHoratioToTariq() {
26
+        hamletParser.horatioToTariq();
27
+        Assert.assertFalse(hamletParser.findHoratio());
28
+
22 29
     }
23 30
 
24 31
     @Test
25 32
     public void testFindHoratio() {
33
+        boolean hamlet = hamletParser.findHoratio();
34
+
35
+        Assert.assertTrue(hamlet);
26 36
     }
27 37
 
28 38
     @Test
29 39
     public void testFindHamlet() {
40
+        boolean hamlet = hamletParser.findHamlet();
41
+
42
+        Assert.assertTrue(hamlet);
30 43
     }
31 44
 }

+ 5383
- 0
target/classes/hamlet.txt
Diff onderdrukt omdat het te groot bestand
Bestand weergeven