Tariq Hook 7 years ago
parent
commit
addf8ab10c

+ 14
- 1
src/main/java/io/zipcoder/ItemParser.java View File

1
 package io.zipcoder;
1
 package io.zipcoder;
2
 
2
 
3
 import java.util.ArrayList;
3
 import java.util.ArrayList;
4
+import java.util.Arrays;
4
 
5
 
5
 public class ItemParser {
6
 public class ItemParser {
6
 
7
 
11
      */
12
      */
12
 
13
 
13
     public ArrayList<String> parseRawDataIntoStringArray(String rawData){
14
     public ArrayList<String> parseRawDataIntoStringArray(String rawData){
14
-        return null;
15
+        String stringPattern = "##";
16
+        ArrayList<String> response = splitStringWithRegexPattern(stringPattern , rawData);
17
+        return response;
15
     }
18
     }
16
 
19
 
17
     public Item parseStringIntoItem(String rawItem) throws ItemParseException{
20
     public Item parseStringIntoItem(String rawItem) throws ItemParseException{
18
         return null;
21
         return null;
19
     }
22
     }
20
 
23
 
24
+    public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem){
25
+        String stringPattern = ";";
26
+        ArrayList<String> response = splitStringWithRegexPattern(stringPattern , rawItem);
27
+        return response;
28
+    }
29
+
30
+    private ArrayList<String> splitStringWithRegexPattern(String stringPattern, String inputString){
31
+        return new ArrayList<String>(Arrays.asList(inputString.split(stringPattern)));
32
+    }
33
+
21
 
34
 
22
 
35
 
23
 }
36
 }

+ 15
- 0
src/test/java/io/zipcoder/ItemParserTest.java View File

12
 
12
 
13
     private String rawSingleItem =    "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##";
13
     private String rawSingleItem =    "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##";
14
 
14
 
15
+    private String rawSingleItemIrregularSeperatorSample = "naMe:MiLK;price:3.23;type:Food^expiration:1/11/2016##";
16
+
15
     private String rawBrokenSingleItem =    "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##";
17
     private String rawBrokenSingleItem =    "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##";
16
 
18
 
17
     private String rawMultipleItems = "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##"
19
     private String rawMultipleItems = "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##"
44
         itemParser.parseStringIntoItem(rawBrokenSingleItem);
46
         itemParser.parseStringIntoItem(rawBrokenSingleItem);
45
     }
47
     }
46
 
48
 
49
+    @Test
50
+    public void findKeyValuePairsInRawItemDataTest(){
51
+        Integer expected = 4;
52
+        Integer actual = itemParser.findKeyValuePairsInRawItemData(rawSingleItem).size();
53
+        assertEquals(expected, actual);
54
+    }
55
+
56
+    @Test
57
+    public void findKeyValuePairsInRawItemDataTestIrregular(){
58
+        Integer expected = 4;
59
+        Integer actual = itemParser.findKeyValuePairsInRawItemData(rawSingleItemIrregularSeperatorSample).size();
60
+        assertEquals(expected, actual);
61
+    }
47
 }
62
 }