|
@@ -2,28 +2,53 @@ package io.zipcoder;
|
2
|
2
|
|
3
|
3
|
import java.util.ArrayList;
|
4
|
4
|
import java.util.Arrays;
|
|
5
|
+import java.util.HashMap;
|
5
|
6
|
|
6
|
7
|
public class ItemParser {
|
7
|
8
|
|
8
|
9
|
|
9
|
|
- public ArrayList<String> parseRawDataIntoStringArray(String rawData){
|
10
|
|
- String stringPattern = "##";
|
11
|
|
- ArrayList<String> response = splitStringWithRegexPattern(stringPattern , rawData);
|
12
|
|
- return response;
|
|
10
|
+ // 1
|
|
11
|
+ private ArrayList<String> splitStringWithRegexPattern(String stringPattern, String inputString) {
|
|
12
|
+ return new ArrayList<String>(Arrays.asList(inputString.split(stringPattern)));
|
13
|
13
|
}
|
14
|
14
|
|
15
|
|
- public Item parseStringIntoItem(String rawItem) throws ItemParseException{
|
16
|
|
- return null;
|
|
15
|
+ // 2
|
|
16
|
+ public ArrayList<String> parseRawDataIntoStringArray(String rawData) {
|
|
17
|
+ String stringPattern = "##";
|
|
18
|
+ ArrayList<String> response = splitStringWithRegexPattern(stringPattern, rawData);
|
|
19
|
+ return response;
|
17
|
20
|
}
|
18
|
21
|
|
19
|
|
- public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem){
|
20
|
|
- String stringPattern = "[;|^]";
|
21
|
|
- ArrayList<String> response = splitStringWithRegexPattern(stringPattern , rawItem);
|
|
22
|
+ // 3
|
|
23
|
+ public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem) {
|
|
24
|
+ String stringPattern = "[@|^|*|%|!|;]";
|
|
25
|
+ ArrayList<String> response = splitStringWithRegexPattern(stringPattern, rawItem);
|
22
|
26
|
return response;
|
23
|
27
|
}
|
24
|
28
|
|
25
|
|
- private ArrayList<String> splitStringWithRegexPattern(String stringPattern, String inputString){
|
26
|
|
- return new ArrayList<String>(Arrays.asList(inputString.split(stringPattern)));
|
|
29
|
+ // 4
|
|
30
|
+ public Item parseStringIntoItem(String rawItem) throws ItemParseException {
|
|
31
|
+ int count = 0;
|
|
32
|
+ String strPrice = "\\d.\\d\\d";
|
|
33
|
+ Double price = Double.valueOf(strPrice);
|
|
34
|
+ String type = "(T|t)..(E|e)";
|
|
35
|
+ String expiration = "(E|e)........(N|n)";
|
|
36
|
+
|
|
37
|
+ ArrayList<String> temp = parseRawDataIntoStringArray(rawItem);
|
|
38
|
+ // ArrayList<Item> myItem = new ArrayList<Item>();
|
|
39
|
+
|
|
40
|
+ for (int i = 0; i < temp.size(); i++) {
|
|
41
|
+ if (findKeyValuePairsInRawItemData(temp.get(i)).equals(null)) {
|
|
42
|
+ count++;
|
|
43
|
+ throw new ItemParseException();
|
|
44
|
+ }
|
|
45
|
+ else if (findKeyValuePairsInRawItemData(temp.get(i)).size() == 4) {
|
|
46
|
+ for (int j = 0; j < temp.size(); j++) {
|
|
47
|
+
|
|
48
|
+ }
|
|
49
|
+ }
|
|
50
|
+ }
|
|
51
|
+ return null;
|
27
|
52
|
}
|
28
|
53
|
|
29
|
54
|
|