|
|
|
|
26
|
|
26
|
|
27
|
public Item parseStringIntoItem(String rawItem) throws ItemParseException {
|
27
|
public Item parseStringIntoItem(String rawItem) throws ItemParseException {
|
28
|
LinkedHashMap<String, String> item = getKeyValueEntries(rawItem);
|
28
|
LinkedHashMap<String, String> item = getKeyValueEntries(rawItem);
|
29
|
- if (item.get(0) == null || item.get(1) == null) {
|
|
|
|
|
29
|
+ if (item.get("name") == null || item.get("price") == null) {
|
30
|
throw new ItemParseException();
|
30
|
throw new ItemParseException();
|
31
|
}
|
31
|
}
|
32
|
- Item newItem = new Item(fixAnyZeros(item.get(0)), Double.valueOf(item.get(1)), item.get(2), item.get(3));
|
|
|
|
|
32
|
+ Item newItem = new Item(fixAnyZeros(item.get("name")), Double.valueOf(item.get("price")), item.get("type"), item.get("expiration"));
|
33
|
return newItem;
|
33
|
return newItem;
|
34
|
}
|
34
|
}
|
35
|
|
35
|
|
|
|
|
|
45
|
for (String keyValues : keyValuePairs) {
|
45
|
for (String keyValues : keyValuePairs) {
|
46
|
ArrayList<String> keyAndValue = splitKeysAndValue(keyValues);
|
46
|
ArrayList<String> keyAndValue = splitKeysAndValue(keyValues);
|
47
|
if(keyAndValue.size() == 2) {
|
47
|
if(keyAndValue.size() == 2) {
|
48
|
- itemDescription.put(convertToLowerCase(keyAndValue.get(0)), convertToLowerCase(keyAndValue.get(1)));
|
|
|
|
|
48
|
+ itemDescription.put(keyAndValue.get(0).toLowerCase(), keyAndValue.get(1).toLowerCase());
|
49
|
}else{
|
49
|
}else{
|
50
|
- itemDescription.put(convertToLowerCase(keyAndValue.get(0)), null);
|
|
|
|
|
50
|
+ itemDescription.put(keyAndValue.get(0).toLowerCase(), null);
|
51
|
}
|
51
|
}
|
52
|
}
|
52
|
}
|
53
|
return itemDescription;
|
53
|
return itemDescription;
|
54
|
}
|
54
|
}
|
55
|
|
55
|
|
56
|
- private String convertToLowerCase(String s) {
|
|
|
57
|
- StringBuilder loweredString = new StringBuilder();
|
|
|
58
|
- for (int i = 0; i < s.length(); i++) {
|
|
|
59
|
- if (s.charAt(i) >= 65 && s.charAt(i) <= 90) {
|
|
|
60
|
- loweredString.append(s.charAt(i) + 32);
|
|
|
61
|
- } else {
|
|
|
62
|
- loweredString.append(s.charAt(i));
|
|
|
63
|
- }
|
|
|
64
|
- }
|
|
|
65
|
- return loweredString.toString();
|
|
|
66
|
- }
|
|
|
67
|
-
|
|
|
68
|
public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem) {
|
56
|
public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem) {
|
69
|
String stringPattern = "[;|^]";
|
57
|
String stringPattern = "[;|^]";
|
70
|
ArrayList<String> response = splitStringWithRegexPattern(stringPattern, rawItem);
|
58
|
ArrayList<String> response = splitStringWithRegexPattern(stringPattern, rawItem);
|
|
|
|
|
107
|
for (LinkedHashMap<String, Integer> item : itemSeenInfo) {
|
95
|
for (LinkedHashMap<String, Integer> item : itemSeenInfo) {
|
108
|
for (Map.Entry entry : item.entrySet()) {
|
96
|
for (Map.Entry entry : item.entrySet()) {
|
109
|
if (checkIfName(entry.getKey())) {
|
97
|
if (checkIfName(entry.getKey())) {
|
110
|
- output.append(String.format("Name: %-10s \t\t\t " +
|
|
|
|
|
98
|
+ output.append(String.format("\nName: %-10s \t\t\t " +
|
111
|
"Seen: %5d\n================ \t\t\t " +
|
99
|
"Seen: %5d\n================ \t\t\t " +
|
112
|
"===========\n", entry.getKey(), entry.getValue()));
|
100
|
"===========\n", entry.getKey(), entry.getValue()));
|
113
|
} else {
|
101
|
} else {
|
114
|
- output.append(String.format("Price: %-5s \t\t\t " +
|
|
|
|
|
102
|
+ output.append(String.format("Price: %-5s \t\t\t\t " +
|
115
|
"Seen: %5d\n---------------- \t\t\t " +
|
103
|
"Seen: %5d\n---------------- \t\t\t " +
|
116
|
"-----------\n", entry.getKey(), entry.getValue()));
|
104
|
"-----------\n", entry.getKey(), entry.getValue()));
|
117
|
}
|
105
|
}
|
118
|
}
|
106
|
}
|
119
|
}
|
107
|
}
|
120
|
- output.append("Errors \t\t\t Seen: " + exceptionCount);
|
|
|
|
|
108
|
+ output.append("\n\nErrors \t\t\t Seen: " + exceptionCount);
|
121
|
return output.toString();
|
109
|
return output.toString();
|
122
|
}
|
110
|
}
|
123
|
|
111
|
|