|
@@ -41,7 +41,7 @@ public class ItemParser {
|
41
|
41
|
return item;
|
42
|
42
|
}
|
43
|
43
|
|
44
|
|
- private String findExpirationDate(String rawItem)throws ItemParseException {
|
|
44
|
+ public String findExpirationDate(String rawItem)throws ItemParseException {
|
45
|
45
|
Pattern checkExpDateRegex = Pattern.compile("\\d\\/\\d+\\/\\d+");
|
46
|
46
|
Matcher regexExpDateMatcher = checkExpDateRegex.matcher(rawItem);
|
47
|
47
|
|
|
@@ -51,7 +51,7 @@ public class ItemParser {
|
51
|
51
|
return null;
|
52
|
52
|
}
|
53
|
53
|
|
54
|
|
- private String findType(String rawItem)throws ItemParseException {
|
|
54
|
+ public String findType(String rawItem)throws ItemParseException {
|
55
|
55
|
Pattern checkTypeRegex = Pattern.compile("(?<=([Tt][Yy][Pp][Ee][^A-Za-z])).*?(?=[^A-Za-z0])");
|
56
|
56
|
Matcher regexTypeMatcher = checkTypeRegex.matcher(rawItem);
|
57
|
57
|
|
|
@@ -96,23 +96,84 @@ public class ItemParser {
|
96
|
96
|
return new ArrayList<String>(Arrays.asList(inputString.split(stringPattern)));
|
97
|
97
|
}
|
98
|
98
|
|
|
99
|
+ public TreeMap<String, ArrayList<Item>> getGroceryMap()throws Exception {
|
|
100
|
+ Main main = new Main();
|
|
101
|
+
|
|
102
|
+ ArrayList<String> items = parseRawDataIntoStringArray(main.readRawDataToString());
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+ for(String s: items){
|
|
106
|
+ try {
|
|
107
|
+ Item newItem = parseStringIntoItem(s);
|
|
108
|
+ if (!groceryMap.containsKey(newItem.getName())){
|
|
109
|
+ ArrayList<Item> myItemArrayList = new ArrayList<Item>();
|
|
110
|
+ myItemArrayList.add(newItem);
|
|
111
|
+ groceryMap.put(newItem.getName(), myItemArrayList);
|
|
112
|
+ } else {
|
|
113
|
+ groceryMap.get(newItem.getName()).add(newItem);
|
|
114
|
+ }
|
|
115
|
+ } catch (ItemParseException e){
|
|
116
|
+ exceptions++;
|
|
117
|
+ }
|
|
118
|
+ }
|
|
119
|
+ return groceryMap;
|
|
120
|
+ }
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+ public String printGroceries() throws Exception{
|
|
124
|
+
|
|
125
|
+ groceryMap = getGroceryMap();
|
|
126
|
+
|
|
127
|
+ StringBuilder sb = new StringBuilder();
|
|
128
|
+
|
|
129
|
+ //how do I print grocery list
|
|
130
|
+
|
|
131
|
+ for(Map.Entry<String, ArrayList<Item>> namesAndItems : groceryMap.entrySet()){
|
|
132
|
+ String makeUpperCase = namesAndItems.getKey().substring(0,1).toUpperCase() + namesAndItems.getKey().substring(1);
|
|
133
|
+
|
|
134
|
+ sb.append("\n" + "name: " + makeUpperCase + "\t\t\t\t" + "seen: " + namesAndItems.getValue().size() + " times");
|
|
135
|
+ sb.append("\n" + "------------------------------------------");
|
|
136
|
+
|
|
137
|
+ ArrayList<Double> getDiffPrices = getDifferentPrices(namesAndItems);
|
|
138
|
+ for (int i = 0; i < getDiffPrices.size(); i++) {
|
|
139
|
+ if (getPriceOccurrences(namesAndItems.getValue(), getDiffPrices.get(i)) == 1) {
|
|
140
|
+ String time = " time";
|
|
141
|
+ } else {
|
|
142
|
+ String time = " times";
|
|
143
|
+ sb.append("\n" + "Price: " + getDiffPrices.get(i) + "\t\t\t\t" + " seen: " + getPriceOccurrences(namesAndItems.getValue(), getDiffPrices.get(i)) + " "+time);
|
|
144
|
+ sb.append("\n" + "==========================================");
|
|
145
|
+ }
|
|
146
|
+ }
|
|
147
|
+
|
|
148
|
+ }
|
|
149
|
+ sb.append("\n\n" + "Errors: " + exceptions + " times\n\n");
|
|
150
|
+ sb.append("\n" + "------------------------------------------");
|
|
151
|
+ return sb.toString();
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+ }
|
|
155
|
+
|
|
156
|
+ private ArrayList<Double> getDifferentPrices(Map.Entry<String, ArrayList<Item>> namesAndItems) {
|
99
|
157
|
|
100
|
|
- public Map<String, ArrayList<Item>> printGroceries(){
|
101
|
158
|
return null;
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+ private boolean getPriceOccurrences(ArrayList<Item> value, Double aDouble) {
|
|
162
|
+ //retrieve the prices
|
102
|
163
|
|
|
164
|
+ return Boolean.parseBoolean(null);
|
103
|
165
|
}
|
104
|
166
|
|
105
|
167
|
|
106
|
168
|
//PseudoCode
|
107
|
169
|
//I need to print the grocery list
|
108
|
|
- //I should be able to add to the grocery list
|
109
|
|
- //I need to be able to return pricesoh
|
110
|
|
- //I need to be able to count the exceptions
|
111
|
|
- //need a replace method for the C00kies
|
112
|
|
- //get key
|
113
|
|
- //get value
|
114
|
|
- //how to handle if the price field is empty
|
115
|
|
- //patterns & matches
|
|
170
|
+ //I need to be able to return prices - done
|
|
171
|
+ //I need to be able to count the exceptions - done
|
|
172
|
+ //need a replace method for the C00kies - done
|
|
173
|
+ //get key - done
|
|
174
|
+ //get value - done
|
|
175
|
+ //how to handle if the price field is empty - done
|
|
176
|
+ //patterns & matches - done
|
116
|
177
|
|
117
|
178
|
|
118
|
179
|
|