Jessica Campbell 6 år sedan
förälder
incheckning
05cee676ab
4 ändrade filer med 5436 tillägg och 1 borttagningar
  1. 12
    0
      pom.xml
  2. 20
    1
      src/main/java/HamletParser.java
  3. 21
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Visa fil

@@ -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>1.7</source>
17
+                    <target>1.7</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>

+ 20
- 1
src/main/java/HamletParser.java Visa fil

@@ -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.
@@ -10,6 +12,7 @@ public class HamletParser {
10 12
     private String hamletData;
11 13
 
12 14
     public HamletParser(){
15
+
13 16
         this.hamletData = loadFile();
14 17
     }
15 18
 
@@ -23,7 +26,6 @@ public class HamletParser {
23 26
                 String line = scanner.nextLine();
24 27
                 result.append(line).append("\n");
25 28
             }
26
-
27 29
             scanner.close();
28 30
         }catch(IOException e){
29 31
             e.printStackTrace();
@@ -36,4 +38,21 @@ public class HamletParser {
36 38
         return hamletData;
37 39
     }
38 40
 
41
+    public void horatioToTariq(){
42
+        Pattern pattern = Pattern.compile("(H)(oratio|ORATIO)");
43
+        Matcher matcher = pattern.matcher(this.hamletData);
44
+        hamletData = matcher.replaceAll("Tariq");
45
+        }
46
+    public void hamletToLeon(){
47
+        Pattern pattern = Pattern.compile("(H)(amlet|AMLET)");
48
+        Matcher matcher = pattern.matcher(this.hamletData);
49
+        hamletData = matcher.replaceAll("Leon");
50
+        }
51
+
52
+    public static void main(String[] args) {
53
+        HamletParser hamletParser = new HamletParser();
54
+        hamletParser.hamletToLeon();
55
+        hamletParser.horatioToTariq();
56
+        System.out.println(hamletParser.getHamletData());
57
+    }
39 58
 }

+ 21
- 0
src/test/java/HamletParserTest.java Visa fil

@@ -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,37 @@ public class HamletParserTest {
15 16
 
16 17
     @Test
17 18
     public void testChangeHamletToLeon() {
19
+        HamletParser hamletParser = new HamletParser();
20
+        String beforeAnyChangesMade = hamletParser.getHamletData();
21
+        hamletParser.hamletToLeon();
22
+        String afterChangesMade = hamletParser.getHamletData();
23
+        Assert.assertNotEquals(beforeAnyChangesMade, afterChangesMade);
18 24
     }
19 25
 
20 26
     @Test
21 27
     public void testChangeHoratioToTariq() {
28
+        HamletParser hamletParser = new HamletParser();
29
+        String beforeAnyChangesMade = hamletParser.getHamletData();
30
+        hamletParser.horatioToTariq();
31
+        String afterChangesMade = hamletParser.getHamletData();
32
+        Assert.assertNotEquals(beforeAnyChangesMade, afterChangesMade);
22 33
     }
23 34
 
24 35
     @Test
25 36
     public void testFindHoratio() {
37
+        HamletParser hamletParser = new HamletParser();
38
+        String beforeAnyChangesMade = "Hello Horatio hello HORATIO";
39
+        hamletParser.horatioToTariq();
40
+        String actual = "Hello Tariq hello Tariq";
41
+        Assert.assertNotEquals(beforeAnyChangesMade, actual);
26 42
     }
27 43
 
28 44
     @Test
29 45
     public void testFindHamlet() {
46
+        HamletParser hamletParser = new HamletParser();
47
+        String beforeAnyChangesMade = "Hello Hamlet hello HAMLET";
48
+        hamletParser.horatioToTariq();
49
+        String actual = "Hello Leon hello Leon";
50
+        Assert.assertNotEquals(beforeAnyChangesMade, actual);
30 51
     }
31 52
 }

+ 5383
- 0
target/classes/hamlet.txt
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil