JaseG256 6 년 전
부모
커밋
877b50e89a
4개의 변경된 파일5440개의 추가작업 그리고 2개의 파일을 삭제
  1. 12
    0
      pom.xml
  2. 26
    2
      src/main/java/HamletParser.java
  3. 19
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml 파일 보기

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

+ 26
- 2
src/main/java/HamletParser.java 파일 보기

@@ -1,6 +1,9 @@
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;
6
+
4 7
 
5 8
 /**
6 9
  * Created by thook on 10/7/15.
@@ -8,6 +11,8 @@ import java.util.Scanner;
8 11
 public class HamletParser {
9 12
 
10 13
     private String hamletData;
14
+    private Pattern pattern;
15
+    private Matcher matcher;
11 16
 
12 17
     public HamletParser(){
13 18
         this.hamletData = loadFile();
@@ -32,8 +37,27 @@ public class HamletParser {
32 37
         return result.toString();
33 38
     }
34 39
 
35
-    public String getHamletData(){
36
-        return hamletData;
40
+    public boolean findHoratio() {
41
+        pattern = Pattern.compile("Horatio");
42
+        matcher = pattern.matcher(hamletData);
43
+        return matcher.find();
44
+    }
45
+
46
+    public String changeHoratioToTariq() {
47
+        return (findHoratio()) ? matcher.replaceAll("Tariq") : null;
48
+    }
49
+
50
+    public boolean findHamlet() {
51
+        pattern = Pattern.compile("Hamlet");
52
+        matcher = pattern.matcher(hamletData);
53
+        return matcher.find();
37 54
     }
38 55
 
56
+    public String changeHamletToLeon() {
57
+        return (findHamlet()) ? matcher.replaceAll("Leon") : null;
58
+    }
59
+
60
+
61
+    public String getHamletData(){ return hamletData; }
62
+
39 63
 }

+ 19
- 0
src/test/java/HamletParserTest.java 파일 보기

@@ -1,6 +1,9 @@
1 1
 import org.junit.Before;
2 2
 import org.junit.Test;
3 3
 
4
+import java.util.regex.Matcher;
5
+import java.util.regex.Pattern;
6
+
4 7
 import static org.junit.Assert.*;
5 8
 
6 9
 public class HamletParserTest {
@@ -15,17 +18,33 @@ public class HamletParserTest {
15 18
 
16 19
     @Test
17 20
     public void testChangeHamletToLeon() {
21
+        String expected = hamletParser.changeHamletToLeon();
22
+        assertTrue(hamletParser.getHamletData().contains("Hamlet"));
23
+        assertTrue(expected.contains("Leon"));
24
+        assertFalse(expected.contains("Hamlet"));
18 25
     }
19 26
 
20 27
     @Test
21 28
     public void testChangeHoratioToTariq() {
29
+        String expected = hamletParser.changeHoratioToTariq();
30
+        assertTrue(expected.contains("Tariq"));
31
+        assertTrue(hamletParser.getHamletData().contains("Horatio"));
32
+        assertFalse(expected.contains("Horatio"));
22 33
     }
23 34
 
24 35
     @Test
25 36
     public void testFindHoratio() {
37
+        Pattern pattern = Pattern.compile("Horatio");
38
+        boolean expected = hamletParser.getHamletData().contains("Horatio");
39
+        boolean actual = hamletParser.findHoratio();
40
+        assertEquals(expected, actual);
26 41
     }
27 42
 
28 43
     @Test
29 44
     public void testFindHamlet() {
45
+        Pattern pattern = Pattern.compile("Hamlet");
46
+        boolean expected = hamletParser.getHamletData().contains("Hamlet");
47
+        boolean actual = hamletParser.findHamlet();
48
+        assertEquals(expected, actual);
30 49
     }
31 50
 }

+ 5383
- 0
target/classes/hamlet.txt
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기