Arin Turpin 6 anos atrás
pai
commit
b3bef27205
4 arquivos alterados com 5465 adições e 0 exclusões
  1. 12
    0
      pom.xml
  2. 35
    0
      src/main/java/HamletParser.java
  3. 35
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Ver arquivo

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

+ 35
- 0
src/main/java/HamletParser.java Ver arquivo

@@ -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,37 @@ public class HamletParser {
36 38
         return hamletData;
37 39
     }
38 40
 
41
+    public void setHamletData(String hamletData) {
42
+        this.hamletData = hamletData;
43
+    }
44
+
45
+    public void changeHamlet(){
46
+        Pattern hamlet = Pattern.compile("^Hamlet");
47
+        Matcher matches = hamlet.matcher(hamletData);
48
+//        for(hamlet : hamletData){
49
+//            matches.replaceAll("Leon");
50
+//        }
51
+        matches.replaceAll("Leon");
52
+    }
53
+
54
+    public void changeHamlet2(){
55
+        Pattern hamlet2 = Pattern.compile("^HAMLET");
56
+        Matcher matches = hamlet2.matcher(hamletData);
57
+        matches.replaceAll("LEON");
58
+
59
+    }
60
+
61
+    public void changeHoratio(){
62
+        Pattern horatio = Pattern.compile("^Horatio");
63
+        Matcher matches = horatio.matcher(hamletData);
64
+        matches.replaceAll("Tariq");
65
+
66
+    }
67
+
68
+    public void changeHoratio2(){
69
+        Pattern horatio2 = Pattern.compile("^HORATIO");
70
+        Matcher matches = horatio2.matcher(hamletData);
71
+        matches.replaceAll("TARIQ");
72
+
73
+    }
39 74
 }

+ 35
- 0
src/test/java/HamletParserTest.java Ver arquivo

@@ -1,11 +1,17 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
5
+import java.util.ArrayList;
6
+import java.util.regex.Matcher;
7
+import java.util.regex.Pattern;
8
+
4 9
 import static org.junit.Assert.*;
5 10
 
6 11
 public class HamletParserTest {
7 12
     private String hamletText;
8 13
     private HamletParser hamletParser;
14
+   // HamletParser hamletParserr = new HamletParser();
9 15
 
10 16
     @Before
11 17
     public void setUp() {
@@ -15,17 +21,46 @@ public class HamletParserTest {
15 21
 
16 22
     @Test
17 23
     public void testChangeHamletToLeon() {
24
+        ArrayList<Matcher> x = new ArrayList<>();
25
+        int counter = 0;
26
+        hamletParser.changeHamlet();
27
+        hamletParser.changeHamlet2();
28
+        Pattern hamlet = Pattern.compile("^Hamlet|HAMLET");
29
+        Matcher matches = hamlet.matcher(hamletText);
30
+        x.add(matches);
31
+        x.isEmpty();
32
+        Assert.assertTrue(x.isEmpty() == false);
18 33
     }
19 34
 
20 35
     @Test
21 36
     public void testChangeHoratioToTariq() {
37
+        ArrayList<Matcher> x = new ArrayList<Matcher>();
38
+        int counter = 0;
39
+        hamletParser.changeHoratio();
40
+        hamletParser.changeHoratio2();
41
+        Pattern hamlet = Pattern.compile("^Horatio|HORATIO");
42
+        Matcher matches = hamlet.matcher(hamletText);
43
+        x.add(matches);
44
+        x.isEmpty();
45
+//        if(matches.find()){
46
+//            counter++;
47
+//        }
48
+
49
+
50
+//        if(hamletText.contains(hamlet.split("")){
51
+//
52
+//        }
53
+        Assert.assertTrue(x.isEmpty() == false);
22 54
     }
23 55
 
24 56
     @Test
25 57
     public void testFindHoratio() {
58
+        Assert.assertTrue(hamletText.contains("Horatio") == true);
59
+
26 60
     }
27 61
 
28 62
     @Test
29 63
     public void testFindHamlet() {
64
+        Assert.assertTrue(hamletText.contains("Hamlet") == true);
30 65
     }
31 66
 }

+ 5383
- 0
target/classes/hamlet.txt
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo