Procházet zdrojové kódy

Merge 0448d83582642c586e9d34e72d47a3c2ab1a99a8 into 99c0c83b2f011a8e58c86fca53df6bfa67c86565

bell7692 před 6 roky
rodič
revize
8ccbf28dfc
No account linked to committer's email
4 změnil soubory, kde provedl 5494 přidání a 2 odebrání
  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 Zobrazit soubor

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>

+ 67
- 0
src/main/java/HamletParser.java Zobrazit soubor

1
 import java.io.File;
1
 import java.io.File;
2
 import java.io.IOException;
2
 import java.io.IOException;
3
 import java.util.Scanner;
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
  * Created by thook on 10/7/15.
8
 public class HamletParser {
10
 public class HamletParser {
9
 
11
 
10
     private String hamletData;
12
     private String hamletData;
13
+    private Pattern pattern;
14
+    private Matcher matcher;
11
 
15
 
12
     public HamletParser(){
16
     public HamletParser(){
13
         this.hamletData = loadFile();
17
         this.hamletData = loadFile();
18
+
14
     }
19
     }
15
 
20
 
16
     private String loadFile(){
21
     private String loadFile(){
36
         return hamletData;
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 Zobrazit soubor

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
 
11
     public void setUp() {
12
     public void setUp() {
12
         this.hamletParser = new HamletParser();
13
         this.hamletParser = new HamletParser();
13
         this.hamletText = hamletParser.getHamletData();
14
         this.hamletText = hamletParser.getHamletData();
15
+
14
     }
16
     }
15
 
17
 
16
     @Test
18
     @Test
17
     public void testChangeHamletToLeon() {
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
     @Test
29
     @Test
21
     public void testChangeHoratioToTariq() {
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
     @Test
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
     @Test
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
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor