|
@@ -2,6 +2,10 @@ package io.zipcoder;
|
2
|
2
|
|
3
|
3
|
import java.util.ArrayList;
|
4
|
4
|
import java.util.Arrays;
|
|
5
|
+import java.util.Map;
|
|
6
|
+import java.util.Scanner;
|
|
7
|
+import java.util.regex.Matcher;
|
|
8
|
+import java.util.regex.Pattern;
|
5
|
9
|
|
6
|
10
|
public class ItemParser {
|
7
|
11
|
|
|
@@ -13,7 +17,14 @@ public class ItemParser {
|
13
|
17
|
}
|
14
|
18
|
|
15
|
19
|
public Item parseStringIntoItem(String rawItem) throws ItemParseException{
|
16
|
|
- return null;
|
|
20
|
+
|
|
21
|
+ String name = nameFinder(rawItem);
|
|
22
|
+ Double price = Double.parseDouble(priceFinder(rawItem));
|
|
23
|
+ String type = "food";
|
|
24
|
+ String expiration = expFinder(rawItem);
|
|
25
|
+ return new Item(name, price, type, expiration);
|
|
26
|
+
|
|
27
|
+
|
17
|
28
|
}
|
18
|
29
|
|
19
|
30
|
public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem){
|
|
@@ -26,6 +37,50 @@ public class ItemParser {
|
26
|
37
|
return new ArrayList<String>(Arrays.asList(inputString.split(stringPattern)));
|
27
|
38
|
}
|
28
|
39
|
|
|
40
|
+ public String nameFinder (String rawNames) throws Exception {
|
|
41
|
+ StringBuilder found = new StringBuilder();
|
|
42
|
+
|
|
43
|
+ String itemSearch = rawNames;
|
|
44
|
+ Pattern foodNames = Pattern.compile("\\w+(?=\\Wprice)", Pattern.CASE_INSENSITIVE);
|
|
45
|
+ Matcher m = foodNames.matcher(itemSearch);
|
|
46
|
+ int lastMatchPos = 0;
|
|
47
|
+ while (m.find())
|
|
48
|
+ {
|
|
49
|
+ found.append(m.group()+"\n");
|
|
50
|
+ lastMatchPos = m.end();
|
|
51
|
+ }
|
|
52
|
+ return found.toString();
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ public String priceFinder (String rawPrices) throws Exception {
|
|
56
|
+ StringBuilder found = new StringBuilder();
|
|
57
|
+
|
|
58
|
+ String itemSearch = rawPrices;
|
|
59
|
+ Pattern foodNames = Pattern.compile("\\d+\\.\\d\\d", Pattern.CASE_INSENSITIVE);
|
|
60
|
+ Matcher m = foodNames.matcher(itemSearch);
|
|
61
|
+ int lastMatchPos = 0;
|
|
62
|
+ while (m.find())
|
|
63
|
+ {
|
|
64
|
+ found.append(m.group()+"\n");
|
|
65
|
+ lastMatchPos = m.end();
|
|
66
|
+ }
|
|
67
|
+ return found.toString();
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ public String expFinder (String rawExp) throws Exception {
|
|
71
|
+ StringBuilder found = new StringBuilder();
|
|
72
|
+
|
|
73
|
+ String itemSearch = rawExp;
|
|
74
|
+ Pattern foodNames = Pattern.compile("\\d{1,2}\\/\\d\\d\\/\\d{4}", Pattern.CASE_INSENSITIVE);
|
|
75
|
+ Matcher m = foodNames.matcher(itemSearch);
|
|
76
|
+ int lastMatchPos = 0;
|
|
77
|
+ while (m.find())
|
|
78
|
+ {
|
|
79
|
+ found.append(m.group()+"\n");
|
|
80
|
+ lastMatchPos = m.end();
|
|
81
|
+ }
|
|
82
|
+ return found.toString();
|
|
83
|
+ }
|
29
|
84
|
|
30
|
85
|
|
31
|
86
|
}
|