Jessica Campbell 6 년 전
부모
커밋
05cee676ab
4개의 변경된 파일5436개의 추가작업 그리고 1개의 파일을 삭제
  1. 12
    0
      pom.xml
  2. 20
    1
      src/main/java/HamletParser.java
  3. 21
    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>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>

+ 20
- 1
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;
4
 
6
 
5
 /**
7
 /**
6
  * Created by thook on 10/7/15.
8
  * Created by thook on 10/7/15.
10
     private String hamletData;
12
     private String hamletData;
11
 
13
 
12
     public HamletParser(){
14
     public HamletParser(){
15
+
13
         this.hamletData = loadFile();
16
         this.hamletData = loadFile();
14
     }
17
     }
15
 
18
 
23
                 String line = scanner.nextLine();
26
                 String line = scanner.nextLine();
24
                 result.append(line).append("\n");
27
                 result.append(line).append("\n");
25
             }
28
             }
26
-
27
             scanner.close();
29
             scanner.close();
28
         }catch(IOException e){
30
         }catch(IOException e){
29
             e.printStackTrace();
31
             e.printStackTrace();
36
         return hamletData;
38
         return hamletData;
37
     }
39
     }
38
 
40
 
41
+    public void horatioToTariq(){
42
+        Pattern pattern = Pattern.compile("(H)(oratio|ORATIO)");
43
+        Matcher matcher = pattern.matcher(this.hamletData);
44
+        hamletData = matcher.replaceAll("Tariq");
45
+        }
46
+    public void hamletToLeon(){
47
+        Pattern pattern = Pattern.compile("(H)(amlet|AMLET)");
48
+        Matcher matcher = pattern.matcher(this.hamletData);
49
+        hamletData = matcher.replaceAll("Leon");
50
+        }
51
+
52
+    public static void main(String[] args) {
53
+        HamletParser hamletParser = new HamletParser();
54
+        hamletParser.hamletToLeon();
55
+        hamletParser.horatioToTariq();
56
+        System.out.println(hamletParser.getHamletData());
57
+    }
39
 }
58
 }

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

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
 
15
 
16
 
16
     @Test
17
     @Test
17
     public void testChangeHamletToLeon() {
18
     public void testChangeHamletToLeon() {
19
+        HamletParser hamletParser = new HamletParser();
20
+        String beforeAnyChangesMade = hamletParser.getHamletData();
21
+        hamletParser.hamletToLeon();
22
+        String afterChangesMade = hamletParser.getHamletData();
23
+        Assert.assertNotEquals(beforeAnyChangesMade, afterChangesMade);
18
     }
24
     }
19
 
25
 
20
     @Test
26
     @Test
21
     public void testChangeHoratioToTariq() {
27
     public void testChangeHoratioToTariq() {
28
+        HamletParser hamletParser = new HamletParser();
29
+        String beforeAnyChangesMade = hamletParser.getHamletData();
30
+        hamletParser.horatioToTariq();
31
+        String afterChangesMade = hamletParser.getHamletData();
32
+        Assert.assertNotEquals(beforeAnyChangesMade, afterChangesMade);
22
     }
33
     }
23
 
34
 
24
     @Test
35
     @Test
25
     public void testFindHoratio() {
36
     public void testFindHoratio() {
37
+        HamletParser hamletParser = new HamletParser();
38
+        String beforeAnyChangesMade = "Hello Horatio hello HORATIO";
39
+        hamletParser.horatioToTariq();
40
+        String actual = "Hello Tariq hello Tariq";
41
+        Assert.assertNotEquals(beforeAnyChangesMade, actual);
26
     }
42
     }
27
 
43
 
28
     @Test
44
     @Test
29
     public void testFindHamlet() {
45
     public void testFindHamlet() {
46
+        HamletParser hamletParser = new HamletParser();
47
+        String beforeAnyChangesMade = "Hello Hamlet hello HAMLET";
48
+        hamletParser.horatioToTariq();
49
+        String actual = "Hello Leon hello Leon";
50
+        Assert.assertNotEquals(beforeAnyChangesMade, actual);
30
     }
51
     }
31
 }
52
 }

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