Browse Source

formatting

Trinh Tong 6 years ago
parent
commit
ddbe21fc72

+ 11
- 7
src/main/java/io/zipcoder/ItemParser.java View File

8
 import java.util.regex.Matcher;
8
 import java.util.regex.Matcher;
9
 import java.util.regex.Pattern;
9
 import java.util.regex.Pattern;
10
 
10
 
11
-import static io.zipcoder.LeetUtils.capitalizeMe;
12
-import static io.zipcoder.LeetUtils.fullManipulate;
11
+import static io.zipcoder.LeetUtils.*;
13
 
12
 
14
 public class ItemParser {
13
 public class ItemParser {
15
 
14
 
69
     }
68
     }
70
 
69
 
71
 
70
 
72
-
73
     public void printToFile(String fileName, String rawItemData) throws FileNotFoundException, ItemParseException {
71
     public void printToFile(String fileName, String rawItemData) throws FileNotFoundException, ItemParseException {
74
         // Output to file
72
         // Output to file
75
         ArrayList<String> allItemsRaw = parseRawDataIntoStringArray(rawItemData);
73
         ArrayList<String> allItemsRaw = parseRawDataIntoStringArray(rawItemData);
96
         resultsOutput.append("Tariq's Messed up Grocery List...\n\n");
94
         resultsOutput.append("Tariq's Messed up Grocery List...\n\n");
97
 
95
 
98
         for (SameItems s : itemCounters.values()) {
96
         for (SameItems s : itemCounters.values()) {
99
-            resultsOutput.append(String.format("name: %8s seen: %d", capitalizeMe(s.getName()), s.getCount()));
100
-//            resultsOutput.append(String.format("%s %s", item.getName(), item.getPrice()));
97
+            resultsOutput.append(stringFormatName(s.getName(), s.getCount()));
98
+            resultsOutput.append(doubleLine());
99
+
100
+            for (Double d:s.getPrices().getPrices().keySet()) {
101
+                resultsOutput.append(stringFormatPrice(d, s.getPrices().getPrices().get(d)));
102
+                resultsOutput.append(singleLine());
103
+            }
101
         }
104
         }
105
+        resultsOutput.append(errorLine(errors));
102
         System.out.println(resultsOutput.toString());
106
         System.out.println(resultsOutput.toString());
103
     }
107
     }
104
 
108
 
105
-    public HashMap<String, SameItems> sameItemCounter(ArrayList<Item> allItems) {
109
+
110
+    private HashMap<String, SameItems> sameItemCounter(ArrayList<Item> allItems) {
106
 
111
 
107
         HashMap<String, SameItems> itemCounters = new HashMap<>();
112
         HashMap<String, SameItems> itemCounters = new HashMap<>();
108
         for (Item i: allItems) {
113
         for (Item i: allItems) {
119
                 itemCounters.put(i.getName(),temp);
124
                 itemCounters.put(i.getName(),temp);
120
             }
125
             }
121
         }
126
         }
122
-
123
         return itemCounters;
127
         return itemCounters;
124
     }
128
     }
125
 
129
 

+ 24
- 0
src/main/java/io/zipcoder/LeetUtils.java View File

50
     public static String fullManipulate(String s) {
50
     public static String fullManipulate(String s) {
51
         return sameCase(l33TToString(s));
51
         return sameCase(l33TToString(s));
52
     }
52
     }
53
+
54
+    public static String stringFormatName(String name, int count) {
55
+        String time = (count > 1) ? "times" : "time";
56
+        return (String.format("name: %7s%6sseen: %d " + time, capitalizeMe(name), "", count));
57
+    }
58
+
59
+    public static String stringFormatPrice(Double price, int count) {
60
+        String time = (count > 1) ? "times" : "time";
61
+        return String.format("%7s%6.2f%5s%7s%d " + time + "\n","Price: ", price,"", "seen: ", count);
62
+    }
63
+
64
+    public static String errorLine(int count) {
65
+        String time = (count > 1) ? "times" : "time";
66
+        return (String.format("%s%19s%2d " + time, "Errors", "seen: ", count));
67
+    }
68
+
69
+    public static String doubleLine() {
70
+        return (String.format("\n%8s%6s%8s\n", "=============", "", "============="));
71
+    }
72
+
73
+    public static String singleLine() {
74
+        return (String.format("%8s%6s%8s\n\n", "-------------", "", "-------------"));
75
+    }
76
+
53
 }
77
 }

+ 3
- 0
src/main/java/io/zipcoder/Prices.java View File

18
     }
18
     }
19
 
19
 
20
 
20
 
21
+    public HashMap<Double, Integer> getPrices() {
22
+        return prices;
23
+    }
21
 }
24
 }