|
@@ -2,12 +2,15 @@ package io.zipcoder;
|
2
|
2
|
|
3
|
3
|
|
4
|
4
|
|
|
5
|
+import jdk.nashorn.internal.objects.Global;
|
|
6
|
+
|
5
|
7
|
import java.io.FileNotFoundException;
|
6
|
8
|
import java.io.PrintWriter;
|
7
|
9
|
import java.util.ArrayList;
|
8
|
10
|
import java.util.Arrays;
|
9
|
11
|
import java.util.HashMap;
|
10
|
12
|
import java.util.Map;
|
|
13
|
+import java.util.logging.Logger;
|
11
|
14
|
import java.util.regex.Matcher;
|
12
|
15
|
import java.util.regex.Pattern;
|
13
|
16
|
import java.util.stream.Collectors;
|
|
@@ -24,6 +27,7 @@ public final class ItemParser {
|
24
|
27
|
public ItemParser() {
|
25
|
28
|
|
26
|
29
|
groceryMap = new HashMap<>();
|
|
30
|
+ //add printWriter in constructor so that there is only ONE
|
27
|
31
|
try {
|
28
|
32
|
writer= new PrintWriter("/Users/karoushafennimore/Dev/PainfulAfternoon/src/main/resources/errors.txt");
|
29
|
33
|
} catch (FileNotFoundException e) {
|
|
@@ -36,18 +40,14 @@ public final class ItemParser {
|
36
|
40
|
StringBuilder sb = new StringBuilder();
|
37
|
41
|
//for every new entry - put the Key and how many times you saw it
|
38
|
42
|
for (Map.Entry<String , ArrayList<Item> > item : groceryMap.entrySet()) {
|
39
|
|
- sb.append("\nname: ");
|
40
|
|
- sb.append(String.format("%9s", item.getKey().substring(0, 1).toUpperCase() + item.getKey().substring(1)));
|
41
|
|
- sb.append("\t\t\tseen: " + item.getValue().size() + " times\n");
|
42
|
|
- sb.append("===============" + "\t\t\t" + "===============\n");
|
|
43
|
+ sb.append(String.format("\nname: %9s", item.getKey().substring(0, 1).toUpperCase() + item.getKey().substring(1)));
|
|
44
|
+ sb.append("\t\t\tseen: " + item.getValue().size() + " times\n" + "===============" + "\t\t\t" + "===============\n");
|
43
|
45
|
|
44
|
46
|
ArrayList<Double> tempList = uniquePrices(item);
|
45
|
47
|
|
46
|
48
|
for(int i = 0; i < tempList.size(); i++) {
|
47
|
|
- sb.append("Price:");
|
48
|
|
- sb.append(String.format("%9s", tempList.get(i)));
|
49
|
|
- sb.append("\t\t\tseen: " + priceCount(item.getValue(), tempList.get(i)) + " times\n");
|
50
|
|
- sb.append("---------------" + "\t\t\t" + "---------------\n");
|
|
49
|
+ sb.append(String.format("Price: %8s", tempList.get(i)));
|
|
50
|
+ sb.append("\t\t\tseen: " + priceCount(item.getValue(), tempList.get(i)) + " times\n---------------" + "\t\t\t" + "---------------\n");
|
51
|
51
|
}
|
52
|
52
|
}
|
53
|
53
|
sb.append("\nErrors" + "\t\t\t\t\tseen: " + exception + " times\n");
|
|
@@ -200,7 +200,7 @@ public final class ItemParser {
|
200
|
200
|
|
201
|
201
|
public void printErrorToFile(ItemParseException e) throws FileNotFoundException {
|
202
|
202
|
//getting entire stack report on the errors that I am getting.
|
203
|
|
- writer.write(Arrays.asList(e.getStackTrace()).stream().map(Object::toString).collect(Collectors.joining("\n")));
|
|
203
|
+ writer.write(Arrays.stream(e.getStackTrace()).map(Object::toString).collect(Collectors.joining("\n")));
|
204
|
204
|
|
205
|
205
|
}
|
206
|
206
|
|