|
@@ -4,7 +4,7 @@ import org.apache.commons.io.IOUtils;
|
4
|
4
|
|
5
|
5
|
import java.util.ArrayList;
|
6
|
6
|
import java.util.HashMap;
|
7
|
|
-
|
|
7
|
+import java.util.Iterator;
|
8
|
8
|
|
9
|
9
|
|
10
|
10
|
public class Main {
|
|
@@ -30,28 +30,58 @@ public class Main {
|
30
|
30
|
|
31
|
31
|
for (ArrayList<String> aLS: namePriceTypeExpiration)
|
32
|
32
|
try {
|
33
|
|
- Item newItem = hurtLocker.parseStringIntoItem(aLS)
|
|
33
|
+ Item newItem = hurtLocker.parseStringIntoItem(aLS.toString());
|
|
34
|
+ if(!groceryAccountedFor.contains(newItem.getName())) {
|
|
35
|
+ groceryAccountedFor.add(newItem.getName());
|
|
36
|
+ }
|
34
|
37
|
|
35
|
38
|
} catch (ItemParseException e) {
|
36
|
39
|
|
37
|
40
|
}
|
38
|
|
- return result;
|
|
41
|
+ return groceryListFormat();
|
39
|
42
|
}
|
40
|
43
|
|
41
|
|
-// public String groceryListFormat() {
|
42
|
|
-// StringBuilder sb = new StringBuilder();
|
43
|
|
-// for (Object item :hurtLocker.namePrice.keySet()) {
|
44
|
|
-// sb.append("name:%12s", item);
|
45
|
|
-// System.out.println(sb.toString());
|
46
|
|
-// } return sb.toString();
|
47
|
|
-// }
|
|
44
|
+ public String groceryListFormat() {
|
|
45
|
+ StringBuilder sb = new StringBuilder();
|
|
46
|
+ for (String item : groceryAccountedFor) {
|
|
47
|
+ int timesSeen = hurtLocker.namePrice.get(item).size();
|
|
48
|
+ sb.append(String.format("name:%8s seen:%2d %s \n", item, timesSeen, timeOrTimes(timesSeen)));
|
|
49
|
+
|
|
50
|
+ //sb.append(String.format(" seen:%3d %s \n", timesSeen, timeOrTimes(timesSeen)));
|
|
51
|
+ sb.append(String.format("============= =============\n"));
|
|
52
|
+ sb.append(countOccurrences(item));
|
|
53
|
+ }
|
|
54
|
+ int errorCount = hurtLocker.getExceptionsThrown();
|
|
55
|
+ sb.append(String.format("Errors seen:%2d %s\n", errorCount, timeOrTimes(errorCount)));
|
|
56
|
+ return sb.toString();
|
|
57
|
+ }
|
|
58
|
+ public String countOccurrences(String item) {
|
|
59
|
+ StringBuilder sb = new StringBuilder();
|
|
60
|
+ HashMap<Double, Integer> priceOccurrence = hurtLocker.getPriceOccurrence(item);
|
|
61
|
+ Iterator<Double> itemPriceIterator = priceOccurrence.keySet().iterator();
|
|
62
|
+ int count = 0;
|
|
63
|
+ while (itemPriceIterator.hasNext()) {
|
|
64
|
+ count++;
|
|
65
|
+ Double price = itemPriceIterator.next();
|
|
66
|
+ sb.append(String.format("Price:%7.2f seen:%2d %s\n", price, priceOccurrence.get(price), timeOrTimes(priceOccurrence.get(price))));
|
|
67
|
+ if (count < 2) sb.append(String.format("------------- -------------\n"));
|
|
68
|
+ sb.append("\n");
|
|
69
|
+ }
|
|
70
|
+ return sb.toString();
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ public String timeOrTimes(int timesSeen) {
|
|
74
|
+ String times;
|
|
75
|
+ if (timesSeen == 1) return "time";
|
|
76
|
+ else return "times";
|
|
77
|
+ }
|
48
|
78
|
|
49
|
79
|
public static void main(String[] args) throws Exception{
|
50
|
|
- String output = (new Main()).readRawDataToString();
|
51
|
|
- // System.out.println(output);
|
|
80
|
+
|
52
|
81
|
Main main = new Main();
|
|
82
|
+ String output = main.readRawDataToString("RawData.txt");
|
|
83
|
+ System.out.println(output);
|
53
|
84
|
|
54
|
|
- main.groceryListFormat();
|
55
|
85
|
|
56
|
86
|
// TODO: parse the data in output into items, and display to console.
|
57
|
87
|
|