Pārlūkot izejas kodu

completely done

Tommy Rogers 6 gadus atpakaļ
vecāks
revīzija
8d01e6ca72

+ 3
- 3
src/main/java/HamletParser.java Parādīt failu

@@ -38,15 +38,15 @@ public class HamletParser {
38 38
         return hamletData;
39 39
     }
40 40
 
41
-    public String changeHamletToLeon(String search, String replace){
42
-        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
41
+    public String changeWord(String search, String replace){
42
+        Pattern patt = Pattern.compile("^" +search + "", Pattern.CASE_INSENSITIVE);
43 43
         Matcher m = patt.matcher(hamletData);
44 44
         return m.replaceAll(replace);
45 45
     }
46 46
 
47 47
     public int findWord(CharSequence hamletData ,String search) {
48 48
         int count = 0;
49
-        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
49
+        Pattern patt = Pattern.compile("^" +search + "", Pattern.CASE_INSENSITIVE);
50 50
         Matcher m = patt.matcher(hamletData);
51 51
      while (m.find())
52 52
             count++;

+ 2
- 2
src/test/java/HamletParserTest.java Parādīt failu

@@ -15,7 +15,7 @@ public class HamletParserTest {
15 15
 
16 16
     @Test
17 17
     public void testChangeHamletToLeon() {
18
-        String leon = hamletParser.changeHamletToLeon("Hamlet", "Leon");
18
+        String leon = hamletParser.changeWord("Hamlet", "Leon");
19 19
 
20 20
         int expected = hamletParser.findWord(hamletText , "Hamlet");
21 21
         int actual = hamletParser.findWord(leon , "Leon");
@@ -27,7 +27,7 @@ public class HamletParserTest {
27 27
 
28 28
     @Test
29 29
     public void testChangeHoratioToTariq() {
30
-        String leon = hamletParser.changeHamletToLeon("Horatio", "Tariq");
30
+        String leon = hamletParser.changeWord("Horatio", "Tariq");
31 31
 
32 32
         int expected = hamletParser.findWord(hamletText , "Horatio");
33 33
         int actual = hamletParser.findWord(leon , "Tariq");