Ver código fonte

othello was better

Shivam Patel 6 anos atrás
pai
commit
f14bf06bd6
4 arquivos alterados com 5486 adições e 0 exclusões
  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 Ver arquivo

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

+ 60
- 0
src/main/java/HamletParser.java Ver arquivo

@@ -1,6 +1,7 @@
1 1
 import java.io.File;
2 2
 import java.io.IOException;
3 3
 import java.util.Scanner;
4
+import java.util.regex.*;
4 5
 
5 6
 /**
6 7
  * Created by thook on 10/7/15.
@@ -33,7 +34,66 @@ public class HamletParser {
33 34
     }
34 35
 
35 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 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 Ver arquivo

@@ -15,17 +15,48 @@ public class HamletParserTest {
15 15
 
16 16
     @Test
17 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 28
     @Test
21 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 40
     @Test
25 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 50
     @Test
29 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
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo