Bladeren bron

Merge 83d794d5b6375fcc4b3de0a8b3f146af1638711e into 99c0c83b2f011a8e58c86fca53df6bfa67c86565

ktecle 6 jaren geleden
bovenliggende
commit
f1b88ac8ad
Geen account gekoppeld aan de committers e-mail
4 gewijzigde bestanden met toevoegingen van 5479 en 1 verwijderingen
  1. 12
    0
      pom.xml
  2. 51
    0
      src/main/java/HamletParser.java
  3. 33
    1
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Bestand weergeven

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

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

1
+import jdk.nashorn.internal.runtime.regexp.RegExp;
2
+
1
 import java.io.File;
3
 import java.io.File;
2
 import java.io.IOException;
4
 import java.io.IOException;
3
 import java.util.Scanner;
5
 import java.util.Scanner;
6
+import java.util.regex.Matcher;
7
+import java.util.regex.Pattern;
4
 
8
 
5
 /**
9
 /**
6
  * Created by thook on 10/7/15.
10
  * Created by thook on 10/7/15.
8
 public class HamletParser {
12
 public class HamletParser {
9
 
13
 
10
     private String hamletData;
14
     private String hamletData;
15
+    private String hamletDataTemp = hamletData;
11
 
16
 
12
     public HamletParser(){
17
     public HamletParser(){
13
         this.hamletData = loadFile();
18
         this.hamletData = loadFile();
36
         return hamletData;
41
         return hamletData;
37
     }
42
     }
38
 
43
 
44
+    public boolean findHoratio(String hamletDataTemp){
45
+        return hamletDataTemp.contains("Horatio");
46
+
47
+
48
+//        int hamletCount =regexChecker("[Hh][Oo][Ra][Aa][Tt][Ii][Oo]",hamletDataTemp);
49
+//
50
+//        if(hamletCount>0){
51
+//            return true;
52
+//        }
53
+//        return false;
54
+    }
55
+    public boolean findHamlet(String hamletDataTemp){
56
+      return hamletDataTemp.contains("Horatio");
57
+    }
58
+    public String changeHoratioToTariq(String hamletDataTemp){
59
+
60
+        Pattern replaceHoratio1 = Pattern.compile("[H|h][O|o][R|r][A|a][T|t][I|i][O|o]");
61
+        Matcher regexMatcher1 = replaceHoratio1.matcher(hamletDataTemp);
62
+        String replaced1 = regexMatcher1.replaceAll("Tariq");
63
+
64
+        return replaced1;
65
+    }
66
+
67
+    public String changeHamletToLeon(String hamletDataTemp){
68
+
69
+
70
+        Pattern replaceHamlet1 = Pattern.compile("[H|h][A|a][M|m][L|l][E|e][T|t]");
71
+        Matcher regexMatcher1 = replaceHamlet1.matcher(hamletDataTemp);
72
+        String replaced1 = regexMatcher1.replaceAll("Leon");
73
+
74
+        return replaced1;
75
+    }
76
+
77
+    public int regexChecker(String input, String hamletDataTemp){
78
+
79
+        Pattern checkRegex = Pattern.compile(input);
80
+        Matcher regexMatcher = checkRegex.matcher(hamletDataTemp);
81
+
82
+        int count = 0;
83
+        while(regexMatcher.find()){
84
+            count++;
85
+            }
86
+            return count;
87
+        }
88
+
89
+
39
 }
90
 }

+ 33
- 1
src/test/java/HamletParserTest.java Bestand weergeven

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
+        String testHamletText = "HaMlet, HAMLET will be replaced by Hamlet.";
20
+        System.out.println(testHamletText);
21
+        testHamletText=hamletParser.changeHamletToLeon(testHamletText);
22
+
23
+        boolean actual = hamletParser.findHamlet(testHamletText);
24
+        Assert.assertFalse(actual);
25
+
26
+        System.out.println(testHamletText);
27
+
18
     }
28
     }
19
 
29
 
20
     @Test
30
     @Test
21
     public void testChangeHoratioToTariq() {
31
     public void testChangeHoratioToTariq() {
32
+        String testHoratioText = "Horatio will be replaced by Tariq, HoRaTIo HORATIO to Tariq";
33
+        testHoratioText=hamletParser.changeHoratioToTariq(testHoratioText);
34
+
35
+        boolean actual = hamletParser.findHoratio(testHoratioText);
36
+        Assert.assertFalse(actual);
37
+
38
+        System.out.println(testHoratioText);
22
     }
39
     }
23
 
40
 
24
     @Test
41
     @Test
25
-    public void testFindHoratio() {
42
+    public void testFindHoratio1() {
43
+        String test = "Hor, will go Horatio, life is beautiful and HORATIO enjoys it.";
44
+        boolean actual = hamletParser.findHoratio(test);
45
+        Assert.assertTrue(actual);
46
+    }
47
+    @Test
48
+    public void testFindHoratio2(){
49
+
50
+        boolean actual = hamletParser.findHoratio(hamletText);
51
+        Assert.assertTrue(actual);
52
+
26
     }
53
     }
27
 
54
 
28
     @Test
55
     @Test
29
     public void testFindHamlet() {
56
     public void testFindHamlet() {
57
+
58
+        boolean actual = hamletParser.findHamlet(hamletText);
59
+        System.out.println(hamletParser.regexChecker("[Hh][Aa][Mm][Ll][Ee][Tt]",hamletText));
60
+        Assert.assertTrue(actual);
30
     }
61
     }
62
+
31
 }
63
 }

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