Sfoglia il codice sorgente

cleaning up some code

Karousha Fennimore 6 anni fa
parent
commit
9262de7c5e

+ 9
- 9
src/main/java/io/zipcoder/ItemParser.java Vedi File

@@ -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
 

+ 1
- 0
src/main/java/io/zipcoder/Main.java Vedi File

@@ -21,6 +21,7 @@ public class Main {
21 21
         ArrayList<String> temp = itemParser.parseRawDataIntoStringArray(output);
22 22
         itemParser.addItemToList(temp);
23 23
         System.out.println(itemParser.printGroceryList());
24
+        //close the file when you're done writing to it!
24 25
         itemParser.flushExceptionsToFile();
25 26
 
26 27
         // TODO: parse the data in output into items, and display to console.

+ 0
- 9
src/main/resources/errors.txt Vedi File

@@ -1,9 +0,0 @@
1
-io.zipcoder.ItemParser.parseStringIntoItem(ItemParser.java:133)
2
-io.zipcoder.ItemParser.addItemToList(ItemParser.java:112)
3
-io.zipcoder.Main.main(Main.java:22)io.zipcoder.ItemParser.parseStringIntoItem(ItemParser.java:133)
4
-io.zipcoder.ItemParser.addItemToList(ItemParser.java:112)
5
-io.zipcoder.Main.main(Main.java:22)io.zipcoder.ItemParser.parseStringIntoItem(ItemParser.java:133)
6
-io.zipcoder.ItemParser.addItemToList(ItemParser.java:112)
7
-io.zipcoder.Main.main(Main.java:22)io.zipcoder.ItemParser.parseStringIntoItem(ItemParser.java:133)
8
-io.zipcoder.ItemParser.addItemToList(ItemParser.java:112)
9
-io.zipcoder.Main.main(Main.java:22)