|
@@ -107,4 +107,92 @@ public class ItemParser {
|
107
|
107
|
}
|
108
|
108
|
return completeList;
|
109
|
109
|
}
|
110
|
|
-}
|
|
110
|
+
|
|
111
|
+ public String printFinalList() throws Exception {
|
|
112
|
+ completeList = getCompleteList();
|
|
113
|
+ StringBuilder listBuilder = new StringBuilder();
|
|
114
|
+
|
|
115
|
+ for(Map.Entry<String,ArrayList<Item>>groceryItems:completeList.entrySet()){
|
|
116
|
+ listBuilder.append("\nname: ");
|
|
117
|
+ listBuilder.append(String.format("%8s",captitalizeFirstLetter(groceryItems.getKey())));
|
|
118
|
+ listBuilder.append("\t\t\t\tseen: "+getOccurencesOfItems(groceryItems.getValue())+" times\n");
|
|
119
|
+ listBuilder.append("==============="+"\t\t\t\t===============\n");
|
|
120
|
+ String priceReport = generatePriceReport(groceryItems);
|
|
121
|
+ listBuilder.append(priceReport);
|
|
122
|
+ listBuilder.append("---------------"+"\t\t\t\t---------------\n");
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ listBuilder.append("\nErrors\t\t\t\t\t\tseen: "+exceptionCounter+" times\n");
|
|
126
|
+
|
|
127
|
+ return listBuilder.toString();
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ public int getOccurencesOfItems(ArrayList list) {
|
|
131
|
+ return list.size();
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ public int getOccurencesOfPrices(ArrayList<Item> list, Double price) {
|
|
135
|
+ int priceCounter = 0;
|
|
136
|
+ for (int i = 0; i < list.size(); i++) {
|
|
137
|
+ if (list.get(i).getPrice().equals(price) ) {
|
|
138
|
+ priceCounter++;
|
|
139
|
+ }
|
|
140
|
+ }
|
|
141
|
+ return priceCounter;
|
|
142
|
+ }
|
|
143
|
+
|
|
144
|
+ public String generatePriceReport(Map.Entry<String, ArrayList<Item>> input) {
|
|
145
|
+ String priceReport = "";
|
|
146
|
+ ArrayList<Double> nonDupPrices = getUniquePrices(input);
|
|
147
|
+ for(int i=0;i<nonDupPrices.size();i++){
|
|
148
|
+ priceReport+="Price";
|
|
149
|
+ priceReport+=(String.format("%10s",nonDupPrices.get(i)));
|
|
150
|
+ priceReport+=("\t\t\t\tseen: "+ getOccurencesOfPrices(input.getValue(),nonDupPrices.get(i))+
|
|
151
|
+ " times\n");
|
|
152
|
+ }
|
|
153
|
+ return priceReport;
|
|
154
|
+
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ public ArrayList<Double> getUniquePrices(Map.Entry<String, ArrayList<Item>> input) {
|
|
158
|
+ ArrayList<Double> uniquePrices = new ArrayList<>();
|
|
159
|
+ for (int i=0;i<input.getValue().size();i++) {
|
|
160
|
+ if (!uniquePrices.contains(input.getValue().get(i).getPrice())) {
|
|
161
|
+ uniquePrices.add(input.getValue().get(i).getPrice());
|
|
162
|
+ }
|
|
163
|
+ }
|
|
164
|
+ return uniquePrices;
|
|
165
|
+ }
|
|
166
|
+
|
|
167
|
+ public String captitalizeFirstLetter(String input) {
|
|
168
|
+ return input.substring(0, 1).toUpperCase() + input.substring(1).toLowerCase();
|
|
169
|
+ }
|
|
170
|
+
|
|
171
|
+ }
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+// public int counts() throws Exception {
|
|
175
|
+// String input = getCompleteList().toString();
|
|
176
|
+// String[] inputs = input.split("([\\W\\s+])");
|
|
177
|
+// Map<String, Integer> listCounter = new HashMap<String, Integer>();
|
|
178
|
+// for (String searchWord : inputs) {
|
|
179
|
+// if (listCounter.containsKey(searchWord)) {
|
|
180
|
+// listCounter.put(searchWord, listCounter.get(searchWord) + 1);
|
|
181
|
+// } else {
|
|
182
|
+// listCounter.put(searchWord, 1);
|
|
183
|
+// }
|
|
184
|
+// }
|
|
185
|
+// return listCounter.get();
|
|
186
|
+// }
|
|
187
|
+// public String printList() throws Exception{
|
|
188
|
+// ItemParser itemParser = new ItemParser();
|
|
189
|
+// StringBuilder finalList = new StringBuilder();
|
|
190
|
+// HashMap<String, ArrayList<Item>> testMap = itemParser.getCompleteList();
|
|
191
|
+// for (String key : testMap.keySet()) {
|
|
192
|
+// for (int i = 0; i < testMap.get(key).size(); i++) {
|
|
193
|
+// finalList.append(("name: "+ key + " seen:"+testMap.get(key).size()+"\n" + testMap.get(key).get(i).getPrice()));
|
|
194
|
+// }
|
|
195
|
+// }
|
|
196
|
+// return finalList.toString();
|
|
197
|
+// }
|
|
198
|
+
|