소스 검색

othello was better

Shivam Patel 6 년 전
부모
커밋
f14bf06bd6
4개의 변경된 파일5486개의 추가작업 그리고 0개의 파일을 삭제
  1. 12
    0
      pom.xml
  2. 60
    0
      src/main/java/HamletParser.java
  3. 31
    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>

+ 60
- 0
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.*;
4
 
5
 
5
 /**
6
 /**
6
  * Created by thook on 10/7/15.
7
  * Created by thook on 10/7/15.
33
     }
34
     }
34
 
35
 
35
     public String getHamletData(){
36
     public String getHamletData(){
37
+
38
+
39
+        return hamletData;
40
+    }
41
+    //Pattern p.compile(hamletData)
42
+    //Matcher m = p.matcher(input);
43
+    //String output = m.replaceAll(hamlets with leon);
44
+
45
+    public int findName(String input) {
46
+        int count = 0;
47
+        Pattern p = Pattern.compile(input);
48
+        Matcher m = p.matcher(hamletData.toLowerCase());
49
+
50
+        while(m.find()){
51
+            count++;
52
+        }
53
+        return count;
54
+    }
55
+
56
+    public String changeLeon(String input) {
57
+        Pattern p = Pattern.compile(input);
58
+        Matcher m = p.matcher(hamletData.toLowerCase());
59
+        hamletData = m.replaceAll("leon");
60
+
36
         return hamletData;
61
         return hamletData;
62
+
63
+
37
     }
64
     }
38
 
65
 
66
+    public static void main(String[] args) {
67
+        HamletParser h = new HamletParser();
68
+    }
69
+
70
+    public String changeTariq(String input) {
71
+        String s = "tArIq";
72
+
73
+        Pattern p = Pattern.compile(input);
74
+        Matcher m = p.matcher(hamletData.toLowerCase());
75
+        hamletData = m.replaceAll(s.toLowerCase());
76
+
77
+        return hamletData;
78
+
79
+
80
+    }
39
 }
81
 }
82
+
83
+
84
+   /* int max = findName(input);
85
+    final String ham = "hamlet";
86
+    final String hor = "horatio";
87
+        while(max != 0) {
88
+
89
+                switch (hamletData) {
90
+                case ham:
91
+                output = "Leon";
92
+                break;
93
+                case hor:
94
+                output = "Tariq";
95
+                break;
96
+                }
97
+                max--;
98
+                }
99
+                return output;*/

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

15
 
15
 
16
     @Test
16
     @Test
17
     public void testChangeHamletToLeon() {
17
     public void testChangeHamletToLeon() {
18
+        String expected = hamletParser.changeLeon("hamlet");
19
+        String str = "hamlet";
20
+
21
+
22
+        String actual = hamletParser.changeLeon(str);
23
+
24
+        assertEquals(expected,actual);
25
+
18
     }
26
     }
19
 
27
 
20
     @Test
28
     @Test
21
     public void testChangeHoratioToTariq() {
29
     public void testChangeHoratioToTariq() {
30
+        String expected = hamletParser.changeTariq("horatio");
31
+
32
+        String str = "horatio";
33
+
34
+        String actual = hamletParser.changeTariq(str);
35
+
36
+        assertEquals(expected,actual);
37
+
22
     }
38
     }
23
 
39
 
24
     @Test
40
     @Test
25
     public void testFindHoratio() {
41
     public void testFindHoratio() {
42
+        String str = "horatio";
43
+        int expected = 158;
44
+        int actual = hamletParser.findName(str);
45
+
46
+        assertEquals(expected,actual);
47
+
26
     }
48
     }
27
 
49
 
28
     @Test
50
     @Test
29
     public void testFindHamlet() {
51
     public void testFindHamlet() {
52
+        String str = "hamlet";
53
+        int expected = 472; //because of chameleon
54
+        int actual = hamletParser.findName(str);
55
+
56
+        assertEquals(expected,actual);
57
+
30
     }
58
     }
59
+
60
+
61
+
31
 }
62
 }

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