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
     <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>7</source>
17
+                    <target>7</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10
 
22
 
11
     <dependencies>
23
     <dependencies>
12
         <dependency>
24
         <dependency>

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

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;
6
+
4
 
7
 
5
 /**
8
 /**
6
  * Created by thook on 10/7/15.
9
  * Created by thook on 10/7/15.
8
 public class HamletParser {
11
 public class HamletParser {
9
 
12
 
10
     private String hamletData;
13
     private String hamletData;
14
+    private Pattern pattern;
15
+    private Matcher matcher;
11
 
16
 
12
     public HamletParser(){
17
     public HamletParser(){
13
         this.hamletData = loadFile();
18
         this.hamletData = loadFile();
32
         return result.toString();
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
 import org.junit.Before;
1
 import org.junit.Before;
2
 import org.junit.Test;
2
 import org.junit.Test;
3
 
3
 
4
+import java.util.regex.Matcher;
5
+import java.util.regex.Pattern;
6
+
4
 import static org.junit.Assert.*;
7
 import static org.junit.Assert.*;
5
 
8
 
6
 public class HamletParserTest {
9
 public class HamletParserTest {
15
 
18
 
16
     @Test
19
     @Test
17
     public void testChangeHamletToLeon() {
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
     @Test
27
     @Test
21
     public void testChangeHoratioToTariq() {
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
     @Test
35
     @Test
25
     public void testFindHoratio() {
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
     @Test
43
     @Test
29
     public void testFindHamlet() {
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
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기