Pārlūkot izejas kodu

Merge f5e1b64c3511f5fa7d91697341159f7daf350dfd into 99c0c83b2f011a8e58c86fca53df6bfa67c86565

Keith Brinker 6 gadus atpakaļ
vecāks
revīzija
dedd5fb2c4
Revīzijas autora e-pasts nav piesaistīts nevienam kontam
4 mainītis faili ar 5490 papildinājumiem un 1 dzēšanām
  1. 12
    0
      pom.xml
  2. 70
    1
      src/main/java/HamletParser.java
  3. 25
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Parādīt failu

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

+ 70
- 1
src/main/java/HamletParser.java Parādīt failu

@@ -1,13 +1,19 @@
1
+import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;
2
+
1 3
 import java.io.File;
2 4
 import java.io.IOException;
3 5
 import java.util.Scanner;
6
+import java.util.regex.Matcher;
7
+import java.util.regex.Pattern;
4 8
 
5 9
 /**
6 10
  * Created by thook on 10/7/15.
7 11
  */
8 12
 public class HamletParser {
9 13
 
14
+    private HamletParser hamletParser;
10 15
     private String hamletData;
16
+    private String inputText;
11 17
 
12 18
     public HamletParser(){
13 19
         this.hamletData = loadFile();
@@ -32,8 +38,71 @@ public class HamletParser {
32 38
         return result.toString();
33 39
     }
34 40
 
41
+    public boolean findHoratio(String inputText){
42
+        if (inputText.contains("HORATIO") || inputText.contains("Horatio"));
43
+        return true;
44
+    }
45
+
46
+    public boolean findHamlet(String inputText){
47
+        if (inputText.contains("HAMLET") || inputText.contains("Hamlet"));
48
+        return true;
49
+    }
50
+
51
+    public String changeHoratioToTariq(String inputText){
52
+
53
+        String str = inputText;
54
+        Pattern p = Pattern.compile("\\bHoratio\\b");
55
+        Matcher m = p.matcher(str);
56
+        String capital = m.replaceAll("Tariq");
57
+
58
+        String lower = capital;
59
+        Pattern p2 = Pattern.compile("\\bHORATIO\\b");
60
+        Matcher m2 = p2.matcher(lower);
61
+        String result = m2.replaceAll("TARIQ");
62
+        return result;
63
+    }
64
+
65
+    public String changeHamletToLeon(String inputText){
66
+
67
+        String str = inputText;
68
+        Pattern p = Pattern.compile("\\bHamlet\\b");
69
+        Matcher m = p.matcher(str);
70
+        String capital = m.replaceAll("Leon");
71
+
72
+        String lower = capital;
73
+        Pattern p2 = Pattern.compile("\\bHAMLET\\b");
74
+        Matcher m2 = p2.matcher(lower);
75
+        String result = m2.replaceAll("LEON");
76
+        return result;
77
+    }
78
+
79
+    public String changeBothNames(String inputText){
80
+        String str = inputText;
81
+        Pattern p = Pattern.compile("\\bHoratio\\b");
82
+        Matcher m = p.matcher(str);
83
+        String capital = m.replaceAll("Tariq");
84
+
85
+        String lower = capital;
86
+        Pattern p2 = Pattern.compile("\\bHORATIO\\b");
87
+        Matcher m2 = p2.matcher(lower);
88
+        String resultOne = m2.replaceAll("TARIQ");
89
+
90
+        String hamBoy = resultOne;
91
+        Pattern p3 = Pattern.compile("\\bHamlet\\b");
92
+        Matcher m3 = p3.matcher(hamBoy);
93
+        String ham1 = m3.replaceAll("Leon");
94
+
95
+        String ham2 = ham1;
96
+        Pattern p4 = Pattern.compile("\\bHAMLET\\b");
97
+        Matcher m4 = p4.matcher(ham2);
98
+        String result = m4.replaceAll("LEON");
99
+        return result;
100
+
101
+    }
102
+
35 103
     public String getHamletData(){
36 104
         return hamletData;
37 105
     }
38 106
 
39
-}
107
+
108
+    }

+ 25
- 0
src/test/java/HamletParserTest.java Parādīt failu

@@ -1,6 +1,10 @@
1
+import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
5
+import java.util.regex.Matcher;
6
+import java.util.regex.Pattern;
7
+
4 8
 import static org.junit.Assert.*;
5 9
 
6 10
 public class HamletParserTest {
@@ -15,17 +19,38 @@ public class HamletParserTest {
15 19
 
16 20
     @Test
17 21
     public void testChangeHamletToLeon() {
22
+        String expected = "Leon";
23
+        String actual = hamletParser.changeHamletToLeon("Hamlet");
24
+        assertEquals(expected, actual);
18 25
     }
19 26
 
27
+
20 28
     @Test
21 29
     public void testChangeHoratioToTariq() {
30
+        String expected = "Tariq";
31
+       String actual = hamletParser.changeHoratioToTariq("Horatio");
32
+        assertEquals(expected, actual);
22 33
     }
23 34
 
24 35
     @Test
25 36
     public void testFindHoratio() {
37
+        boolean expected = true;
38
+        boolean actual = hamletParser.findHoratio("This is a string with the name Horatio in it");
39
+        assertEquals(expected, actual);
26 40
     }
27 41
 
28 42
     @Test
29 43
     public void testFindHamlet() {
44
+        boolean expected = true;
45
+        boolean actual = hamletParser.findHamlet("This is a string with the name Hamlet in it");
46
+        assertEquals(expected, actual);
47
+    }
48
+
49
+    @Test
50
+    public void testChangedBothNames(){
51
+        String expected = "Tariq and Leon are friends";
52
+        String actual = hamletParser.changeBothNames("Horatio and Hamlet are friends");
53
+        assertEquals(expected, actual);
54
+
30 55
     }
31 56
 }

+ 5383
- 0
target/classes/hamlet.txt
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu