|
@@ -1,11 +1,12 @@
|
1
|
1
|
package io.zipcoder;
|
2
|
2
|
|
|
3
|
+import java.lang.reflect.Array;
|
3
|
4
|
import java.util.ArrayList;
|
4
|
5
|
import java.util.Arrays;
|
|
6
|
+import java.util.stream.Stream;
|
5
|
7
|
|
6
|
8
|
public class ItemParser {
|
7
|
9
|
|
8
|
|
-
|
9
|
10
|
public ArrayList<String> parseRawDataIntoStringArray(String rawData){
|
10
|
11
|
String stringPattern = "##";
|
11
|
12
|
ArrayList<String> response = splitStringWithRegexPattern(stringPattern , rawData);
|
|
@@ -13,7 +14,25 @@ public class ItemParser {
|
13
|
14
|
}
|
14
|
15
|
|
15
|
16
|
public Item parseStringIntoItem(String rawItem) throws ItemParseException{
|
16
|
|
- return null;
|
|
17
|
+ ItemParser item = new ItemParser();
|
|
18
|
+
|
|
19
|
+ ArrayList<String> temp2 = item.findKeyValuePairsInRawItemData(rawItem);
|
|
20
|
+ ArrayList<String> temp3 = new ArrayList<>();
|
|
21
|
+
|
|
22
|
+ for (int i = 0; i < temp2.size(); i++){
|
|
23
|
+ String temp = temp2.get(i).substring(temp2.get(i).indexOf(":") + 1);
|
|
24
|
+
|
|
25
|
+ if (temp.contains("##")){
|
|
26
|
+ temp = temp.replaceAll("##", "");
|
|
27
|
+ }
|
|
28
|
+ temp3.add(temp);
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ if (Double.valueOf(temp3.get(1)) == null) {
|
|
32
|
+ throw new ItemParseException();
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ return new Item(temp3.get(0).toLowerCase(), Double.valueOf(temp3.get(1)), temp3.get(2).toLowerCase(), temp3.get(3).toLowerCase());
|
17
|
36
|
}
|
18
|
37
|
|
19
|
38
|
public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem){
|
|
@@ -27,5 +46,4 @@ public class ItemParser {
|
27
|
46
|
}
|
28
|
47
|
|
29
|
48
|
|
30
|
|
-
|
31
|
49
|
}
|