Zavon Malone 5 년 전
부모
커밋
7ee6d42efe
4개의 변경된 파일5483개의 추가작업 그리고 1개의 파일을 삭제
  1. 12
    0
      pom.xml
  2. 49
    1
      src/main/java/HamletParser.java
  3. 39
    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>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>

+ 49
- 1
src/main/java/HamletParser.java 파일 보기

@@ -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.
@@ -24,7 +26,6 @@ public class HamletParser {
24 26
                 result.append(line).append("\n");
25 27
             }
26 28
 
27
-            scanner.close();
28 29
         }catch(IOException e){
29 30
             e.printStackTrace();
30 31
         }
@@ -36,4 +37,51 @@ public class HamletParser {
36 37
         return hamletData;
37 38
     }
38 39
 
40
+    public String changeHamletToLeon(String test) {
41
+        Pattern pattern = Pattern.compile("\\w+(\\W)?");
42
+        Matcher matcher = pattern.matcher(test);
43
+
44
+        String str ="";
45
+
46
+        while(matcher.find()){
47
+            String word = matcher.group();
48
+            if(word.equals("Hamlet ")){
49
+                str+="Leon ";
50
+            }else{
51
+                str+=word;
52
+            }
53
+        }
54
+        return str;
55
+    }
56
+
57
+    public String changeHoratioToTariq(String test) {
58
+        Pattern pattern = Pattern.compile("\\w+(\\W)?");
59
+        Matcher matcher = pattern.matcher(test);
60
+
61
+        String str = "";
62
+
63
+        while(matcher.find()){
64
+            String word = matcher.group();
65
+            if(word.equals("Horatio ")){
66
+                str+="Tariq ";
67
+            }else{
68
+                str+=word;
69
+            }
70
+        }
71
+        return str;
72
+    }
73
+
74
+    public Boolean findHoratio(String name) {
75
+        Pattern pattern =Pattern.compile(name);
76
+        Matcher matcher = pattern.matcher(name);
77
+
78
+        return matcher.find();
79
+    }
80
+
81
+    public Boolean findHamlet(String name) {
82
+        Pattern pattern =Pattern.compile(name);
83
+        Matcher matcher = pattern.matcher(name);
84
+
85
+        return matcher.find();
86
+    }
39 87
 }

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

@@ -1,3 +1,4 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
@@ -15,17 +16,55 @@ public class HamletParserTest {
15 16
 
16 17
     @Test
17 18
     public void testChangeHamletToLeon() {
19
+        //given
20
+        String test = "Hamlet likes coding";
21
+        String expected = "Leon likes coding";
22
+
23
+        //when
24
+        String actual = hamletParser.changeHamletToLeon(test);
25
+
26
+        //then
27
+        Assert.assertEquals(expected, actual);
18 28
     }
19 29
 
20 30
     @Test
21 31
     public void testChangeHoratioToTariq() {
32
+        //given
33
+        String test = "Horatio likes coding";
34
+        String expected = "Tariq likes coding";
35
+
36
+        //when
37
+        String actual = hamletParser.changeHoratioToTariq(test);
38
+
39
+        //then
40
+        Assert.assertEquals(expected, actual);
22 41
     }
23 42
 
24 43
     @Test
25 44
     public void testFindHoratio() {
45
+        //given
46
+        String name = " ";
47
+        String expected = "Horatio";
48
+
49
+        //when
50
+
51
+       Boolean actual = hamletParser.findHoratio(name);
52
+
53
+        //then
54
+        Assert.assertTrue(expected, actual);
26 55
     }
27 56
 
28 57
     @Test
29 58
     public void testFindHamlet() {
59
+        //given
60
+        String name = " ";
61
+        String expected = "Hamlet";
62
+
63
+        //when
64
+
65
+        Boolean actual = hamletParser.findHamlet(name);
66
+
67
+        //then
68
+        Assert.assertTrue(expected, actual);
30 69
     }
31 70
 }

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