Explorar el Código

Merge 0448d83582642c586e9d34e72d47a3c2ab1a99a8 into 99c0c83b2f011a8e58c86fca53df6bfa67c86565

bell7692 hace 6 años
padre
commit
8ccbf28dfc
Ninguna cuenta está vinculada al correo electrónico del colaborador
Se han modificado 4 ficheros con 5494 adiciones y 2 borrados
  1. 12
    0
      pom.xml
  2. 67
    0
      src/main/java/HamletParser.java
  3. 32
    2
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Ver fichero

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

+ 67
- 0
src/main/java/HamletParser.java Ver fichero

@@ -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.
@@ -8,9 +10,12 @@ import java.util.Scanner;
8 10
 public class HamletParser {
9 11
 
10 12
     private String hamletData;
13
+    private Pattern pattern;
14
+    private Matcher matcher;
11 15
 
12 16
     public HamletParser(){
13 17
         this.hamletData = loadFile();
18
+
14 19
     }
15 20
 
16 21
     private String loadFile(){
@@ -36,4 +41,66 @@ public class HamletParser {
36 41
         return hamletData;
37 42
     }
38 43
 
44
+
45
+    public void changeHoratioToTariq(){
46
+
47
+        String horatio = "(Horatio|HORATIO)";
48
+
49
+        pattern = Pattern.compile(horatio);
50
+
51
+        matcher = pattern.matcher(hamletData);
52
+        hamletData = matcher.replaceAll("Tariq");
53
+
54
+    }
55
+
56
+
57
+    public void changeHamletToLeon() {
58
+        String hamlet = "(Hamlet| HAMLET)";
59
+
60
+        pattern = Pattern.compile(hamlet);
61
+        matcher = pattern.matcher(hamletData);
62
+
63
+        hamletData = matcher.replaceAll("Leon");
64
+
65
+    }
66
+        public String printOut(){
67
+        System.out.println(this.hamletData);
68
+        return this.hamletData;
69
+    }
70
+
71
+
72
+    public static void main(String[] args) {
73
+        HamletParser hamletParser = new HamletParser();
74
+        hamletParser.changeHamletToLeon();
75
+        hamletParser.printOut();
76
+    }
77
+
78
+    public boolean findHoratio() {
79
+        String horatio = "(Horatio|HORATIO)";
80
+
81
+        pattern = Pattern.compile(horatio);
82
+
83
+        matcher = pattern.matcher(hamletData);
84
+
85
+        if(hamletData.contains("(Horatio|HORATIO)")){
86
+            return true;
87
+        }
88
+        return false;
89
+
90
+    }
91
+
92
+
93
+    public boolean findHamlet() {
94
+        String hamlet = "(Hamlet| HAMLET)";
95
+
96
+        pattern = Pattern.compile(hamlet);
97
+        matcher = pattern.matcher(hamletData);
98
+
99
+        if (hamletData.contains("(Hamlet| HAMLET)")) {
100
+            return true;
101
+        }
102
+        return false;
103
+
104
+    }
105
+
39 106
 }

+ 32
- 2
src/test/java/HamletParserTest.java Ver fichero

@@ -1,3 +1,4 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
@@ -11,21 +12,50 @@ public class HamletParserTest {
11 12
     public void setUp() {
12 13
         this.hamletParser = new HamletParser();
13 14
         this.hamletText = hamletParser.getHamletData();
15
+
14 16
     }
15 17
 
16 18
     @Test
17 19
     public void testChangeHamletToLeon() {
20
+        hamletParser.changeHamletToLeon();
21
+
22
+        boolean expected = false;
23
+        boolean actual = hamletParser.findHamlet();
24
+
25
+        Assert.assertEquals(actual, expected);
26
+
18 27
     }
19 28
 
20 29
     @Test
21 30
     public void testChangeHoratioToTariq() {
31
+        hamletParser.changeHoratioToTariq();
32
+
33
+        boolean expected = false;
34
+        boolean actual = hamletParser.findHoratio();
35
+
36
+        Assert.assertEquals(actual, expected);
37
+
22 38
     }
23 39
 
24 40
     @Test
25
-    public void testFindHoratio() {
41
+    public void testFindHamlet() {
42
+        hamletParser.changeHamletToLeon();
43
+
44
+        boolean expected = false;
45
+        boolean actual = hamletParser.findHamlet();
46
+
47
+        Assert.assertEquals(actual, expected);
26 48
     }
27 49
 
28 50
     @Test
29
-    public void testFindHamlet() {
51
+    public void testFindHoratio() {
52
+        hamletParser.changeHoratioToTariq();
53
+
54
+        boolean expected = false;
55
+        boolean actual = hamletParser.findHamlet();
56
+
57
+        Assert.assertEquals(actual, expected);
30 58
     }
59
+
60
+
31 61
 }

+ 5383
- 0
target/classes/hamlet.txt
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero