Kthomas 6 years ago
parent
commit
0125dc4faa
4 changed files with 5422 additions and 2 deletions
  1. 12
    0
      pom.xml
  2. 22
    2
      src/main/java/HamletParser.java
  3. 5
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml View File

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

+ 22
- 2
src/main/java/HamletParser.java View File

@@ -1,10 +1,24 @@
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
- * Created by thook on 10/7/15.
8
+ * @TODO
9
+ * @1. Go through the hamlet file , use Regular expressions (Regex)
10
+ * Replace all instances of the string "Hamlet" with "Leon"
11
+ * Replace all instances of the string "Horatio" with "Tariq"
12
+ * Breakdown all the logic to complete this process
13
+ * Must use Pattern && Matcher to replace the words ^Hint: replaceAll();^
7 14
  */
15
+//     LOGIC
16
+// ==============
17
+// Iterate through the file
18
+// Use regular expressions/ Pattern & Matcher to target specific strings or matches of characters
19
+// in this case "Hamlet" & "Horatio"
20
+// After I've locked on to all targeted strings/characters then replace them,
21
+// Maybe replace them using the replaceAll(); function
8 22
 public class HamletParser {
9 23
 
10 24
     private String hamletData;
@@ -32,8 +46,14 @@ public class HamletParser {
32 46
         return result.toString();
33 47
     }
34 48
 
49
+    public String nameSwapper(String match, String newMatch, String nameInput){
50
+        Pattern namePattern = Pattern.compile(match); //instance class of pattern compressed version of Regex
51
+        Matcher nameMatch = namePattern.matcher(nameInput); //use my pattern object to make an instance of matcher, which will then parse my nameinput
52
+        return nameMatch.replaceAll(newMatch);
53
+    }
54
+
35 55
     public String getHamletData(){
36 56
         return hamletData;
37 57
     }
38 58
 
39
-}
59
+}

+ 5
- 0
src/test/java/HamletParserTest.java View File

@@ -1,6 +1,10 @@
1
+import jdk.nashorn.internal.runtime.regexp.joni.Regex;
2
+import org.junit.Assert;
1 3
 import org.junit.Before;
2 4
 import org.junit.Test;
3 5
 
6
+import java.util.regex.Pattern;
7
+
4 8
 import static org.junit.Assert.*;
5 9
 
6 10
 public class HamletParserTest {
@@ -15,6 +19,7 @@ public class HamletParserTest {
15 19
 
16 20
     @Test
17 21
     public void testChangeHamletToLeon() {
22
+
18 23
     }
19 24
 
20 25
     @Test

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