|
@@ -66,8 +66,67 @@ public class ItemParser {
|
66
|
66
|
return priceTotals;
|
67
|
67
|
}
|
68
|
68
|
|
69
|
|
- public Integer totalTimesItemSeen(ArrayList<Item> filteredArrayList){
|
70
|
|
- return filteredArrayList.size();
|
|
69
|
+ public Map<Double, Integer> itemTypeMapWithCounts(String rawData, String filterType) throws ItemParseException {
|
|
70
|
+ ArrayList<Item> itemArrayList = createItemArrayList(rawData);
|
|
71
|
+ ArrayList<Item> filterItemArrayList = filterItemArrayList(itemArrayList, filterType);
|
|
72
|
+ Map<Double, Integer> priceTotals = individualItemCount(filterItemArrayList);
|
|
73
|
+ return priceTotals;
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ public Integer totalTimesItemSeen(String rawData, String filterType) throws ItemParseException {
|
|
77
|
+ ArrayList<Item> itemArrayList = createItemArrayList(rawData);
|
|
78
|
+ ArrayList<Item> filterItemArrayList = filterItemArrayList(itemArrayList, filterType);
|
|
79
|
+ return filterItemArrayList.size();
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ public ArrayList<String> filterTypeArrayList(String rawData) throws ItemParseException {
|
|
83
|
+ ArrayList<Item> itemArrayList = createItemArrayList(rawData);
|
|
84
|
+ ArrayList<String> filterType = new ArrayList<String>();
|
|
85
|
+
|
|
86
|
+ for(int i = 0; i < itemArrayList.size(); i++) {
|
|
87
|
+ if (!filterType.contains(itemArrayList.get(i).getName())) {
|
|
88
|
+ filterType.add(itemArrayList.get(i).getName());
|
|
89
|
+ }
|
|
90
|
+ }
|
|
91
|
+ return filterType;
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ public String formatText(String rawData) throws ItemParseException {
|
|
95
|
+ ArrayList<String> filterType = filterTypeArrayList(rawData);
|
|
96
|
+ StringBuilder sb = new StringBuilder();
|
|
97
|
+
|
|
98
|
+ for (int i = 0; i < filterType.size(); i++) {
|
|
99
|
+ String name = filterType.get(i);
|
|
100
|
+ Integer total = totalTimesItemSeen(rawData, filterType.get(i));
|
|
101
|
+ String priceFormated = formatPriceField(rawData, filterType.get(i));
|
|
102
|
+ sb.append("name: ");
|
|
103
|
+ sb.append(String.format("%7s", name.substring(0, 1).toUpperCase() + name.substring(1)));
|
|
104
|
+ sb.append("\t \t");
|
|
105
|
+ sb.append(" seen: " + total + " times\n");
|
|
106
|
+ sb.append("============= \t \t =============\n");
|
|
107
|
+ sb.append(priceFormated + "\n");
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ sb.append("Errors " + " seen: " + getExceptionsThrown(rawData) + " times");
|
|
111
|
+
|
|
112
|
+ return sb.toString();
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ public String formatPriceField(String rawData, String filterType) throws ItemParseException {
|
|
116
|
+ Map<Double, Integer> priceTotals = itemTypeMapWithCounts(rawData, filterType);
|
|
117
|
+ StringBuilder sb = new StringBuilder();
|
|
118
|
+ Set mapSet = (Set) priceTotals.entrySet();
|
|
119
|
+ Iterator mapIterator = mapSet.iterator();
|
|
120
|
+ while (mapIterator.hasNext()) {
|
|
121
|
+ Map.Entry mapEntry = (Map.Entry) mapIterator.next();
|
|
122
|
+ // getKey Method of HashMap access a key of map
|
|
123
|
+ Object keyValue = mapEntry.getKey();
|
|
124
|
+ //getValue method returns corresponding key's value
|
|
125
|
+ Object value = mapEntry.getValue();
|
|
126
|
+ sb.append("Price: " + keyValue + "\t\t seen: " + value + " times" + "\n");
|
|
127
|
+ sb.append("-------------\t\t -------------\n");
|
|
128
|
+ }
|
|
129
|
+ return sb.toString();
|
71
|
130
|
}
|
72
|
131
|
|
73
|
132
|
public String checkName(String input) throws ItemParseException {
|
|
@@ -114,7 +173,6 @@ public class ItemParser {
|
114
|
173
|
}
|
115
|
174
|
|
116
|
175
|
public Integer getExceptionsThrown(String rawData) {
|
117
|
|
-
|
118
|
176
|
ArrayList<String> parsedRawData = parseRawDataIntoStringArray(rawData);
|
119
|
177
|
for (int i = 0; i < parsedRawData.size(); i++)
|
120
|
178
|
try {
|