|
@@ -2,20 +2,44 @@ package io.zipcoder;
|
2
|
2
|
|
3
|
3
|
import java.util.ArrayList;
|
4
|
4
|
import java.util.Arrays;
|
|
5
|
+import java.util.List;
|
5
|
6
|
|
6
|
7
|
public class ItemParser {
|
7
|
|
-
|
|
8
|
+ private String omit = "^[a-zA-Z0-9]+:";
|
|
9
|
+ private String spacer = "[;#^@!%*]";
|
|
10
|
+ private Item item;
|
8
|
11
|
|
9
|
12
|
public ArrayList<String> parseRawDataIntoStringArray(String rawData){
|
10
|
13
|
String stringPattern = "##";
|
11
|
14
|
ArrayList<String> response = splitStringWithRegexPattern(stringPattern , rawData);
|
|
15
|
+
|
12
|
16
|
return response;
|
13
|
17
|
}
|
14
|
18
|
|
15
|
19
|
public Item parseStringIntoItem(String rawItem) throws ItemParseException{
|
16
|
|
- return null;
|
|
20
|
+ Item item;
|
|
21
|
+ int error = 0;
|
|
22
|
+ String[] splitItem = rawItem.split(spacer);
|
|
23
|
+ try {
|
|
24
|
+ String name = splitItem[0].toLowerCase().replaceAll(omit, "").replaceAll("0", "o");
|
|
25
|
+ Double price = Double.parseDouble(splitItem[1].replaceAll(omit, ""));
|
|
26
|
+ String type = splitItem[2].toLowerCase().replaceAll(omit, "");
|
|
27
|
+ String expiration = splitItem[3].toLowerCase().replaceAll(omit, "");
|
|
28
|
+
|
|
29
|
+ if (name.isEmpty() || price == null || type.isEmpty()|| expiration.isEmpty())
|
|
30
|
+ throw new Exception();
|
|
31
|
+ error++;
|
|
32
|
+ item = new Item(name, price, type, expiration);
|
|
33
|
+ } catch (Exception e) {
|
|
34
|
+
|
|
35
|
+ throw new ItemParseException();
|
|
36
|
+ }
|
|
37
|
+ System.out.println(item);
|
|
38
|
+ System.out.println(error);
|
|
39
|
+ return item;
|
17
|
40
|
}
|
18
|
41
|
|
|
42
|
+
|
19
|
43
|
public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem){
|
20
|
44
|
String stringPattern = "[;|^]";
|
21
|
45
|
ArrayList<String> response = splitStringWithRegexPattern(stringPattern , rawItem);
|
|
@@ -23,9 +47,13 @@ public class ItemParser {
|
23
|
47
|
}
|
24
|
48
|
|
25
|
49
|
private ArrayList<String> splitStringWithRegexPattern(String stringPattern, String inputString){
|
|
50
|
+ //System.out.println(new ArrayList<String>(Arrays.asList(inputString.split(stringPattern))));
|
26
|
51
|
return new ArrayList<String>(Arrays.asList(inputString.split(stringPattern)));
|
27
|
|
- }
|
28
|
52
|
|
|
53
|
+ }
|
29
|
54
|
|
30
|
55
|
|
|
56
|
+ public List <String> parseRawDataIntoStringArray() {
|
|
57
|
+ return null;
|
|
58
|
+ }
|
31
|
59
|
}
|