Преглед на файлове

just need to fix how I updating Arraylist Values when there is more than one price.

Joshua Wurdemann преди 6 години
родител
ревизия
6c14fe1305
променени са 2 файла, в които са добавени 23 реда и са изтрити 15 реда
  1. 18
    14
      src/main/java/io/zipcoder/ItemParser.java
  2. 5
    1
      src/main/java/io/zipcoder/Main.java

+ 18
- 14
src/main/java/io/zipcoder/ItemParser.java Целия файл

@@ -14,18 +14,16 @@ public class ItemParser {
14 14
     private Integer itemCount = 0;
15 15
     private Integer exceptionsCount = 0;
16 16
 
17
-    ItemParser(String raw) {
17
+    public ItemParser(String raw) {
18 18
         rawItems = parseRawDataIntoStringArray(raw);
19 19
         try {
20 20
             createMap();
21 21
         } catch (Exception e) {
22 22
             e.printStackTrace();
23 23
         }
24
-
25 24
     }
26 25
 
27
-    ItemParser() {
28
-
26
+    public ItemParser() {
29 27
     }
30 28
 
31 29
     private void expectionHandled() throws ItemParseException {
@@ -55,26 +53,31 @@ public class ItemParser {
55 53
     }
56 54
 
57 55
 
58
-    public Item parseStringIntoItem(String rawItem) throws ItemParseException {
59
-
56
+    public Item parseStringIntoItem(String rawItem) {
57
+      /*  if (checkName(rawItem).equals(" ") || checkPrice(rawItem).equals(" ")){
58
+            expectionHandled();
59
+        }*/
60 60
         String name = checkName(rawItem);
61 61
         Double price = Double.valueOf(checkPrice(rawItem));
62 62
         String type = checkType(rawItem);
63 63
         String expiration = checkExpiration(rawItem);
64
-        if (checkName(rawItem) == null | checkPrice(rawItem) == null) expectionHandled();
65 64
 
66 65
         return new Item(name, price, type, expiration);
67
-
68 66
     }
69 67
 
70 68
     public ArrayList<Item> rawItemToCleanItem() throws ItemParseException {
71 69
         ArrayList<Item> itemArrayList = new ArrayList<Item>();
70
+
72 71
         for (int i = 0; i < rawItems.size(); i++) {
73 72
             String s = rawItems.get(i);
74
-
75 73
             Item item = parseStringIntoItem(rawItems.get(i));
76 74
             System.out.println(item.toString());
77
-            itemArrayList.add(item);
75
+
76
+            if (!item.getName().equals(" ") && !item.getPrice().equals(0.0)) {
77
+                itemArrayList.add(item);
78
+            } else {
79
+                exceptionsCount++;
80
+            }
78 81
         }
79 82
         return itemArrayList;
80 83
     }
@@ -173,6 +176,7 @@ public class ItemParser {
173 176
     }
174 177
 
175 178
     public void print() {
179
+
176 180
         for (Map.Entry<String, ArrayList<ValueList>> entry : theMap.entrySet()) {
177 181
             //name of the Product;
178 182
             String name = entry.getKey();
@@ -196,7 +200,7 @@ public class ItemParser {
196 200
         if (matcherName.find()) {
197 201
             return matcherName.group(2).toLowerCase();
198 202
         }
199
-        return null;
203
+        return " ";
200 204
     }
201 205
 
202 206
     public String checkPrice(String input) {
@@ -207,7 +211,7 @@ public class ItemParser {
207 211
             return matcherPrice.group(2).toLowerCase();
208 212
         }
209 213
 
210
-        return null;
214
+        return "0.0";
211 215
     }
212 216
 
213 217
     public String checkType(String input) {
@@ -217,7 +221,7 @@ public class ItemParser {
217 221
         if (matcherType.find()) {
218 222
             return matcherType.group(2).toLowerCase();
219 223
         }
220
-        return null;
224
+        return " ";
221 225
     }
222 226
 
223 227
     public String checkExpiration(String input) {
@@ -228,6 +232,6 @@ public class ItemParser {
228 232
             return matcherExpiration.group(2).toLowerCase();
229 233
         }
230 234
 
231
-        return null;
235
+        return " ";
232 236
     }
233 237
 }

+ 5
- 1
src/main/java/io/zipcoder/Main.java Целия файл

@@ -2,6 +2,8 @@ package io.zipcoder;
2 2
 
3 3
 import org.apache.commons.io.IOUtils;
4 4
 
5
+import java.util.ArrayList;
6
+
5 7
 
6 8
 public class Main {
7 9
 
@@ -12,9 +14,11 @@ public class Main {
12 14
     }
13 15
 
14 16
     public static void main(String[] args) throws Exception {
15
-        String output = (new Main()).readRawDataToString();
17
+       String output = (new Main()).readRawDataToString();
16 18
 
17 19
         ItemParser parse = new ItemParser(output);
20
+      ArrayList numbers = parse.parseRawDataIntoStringArray(output);
21
+
18 22
 
19 23
         parse.print();
20 24