Ver código fonte

erased my own lowercase method and it now works

ghost1497 6 anos atrás
pai
commit
85c668f1ee
1 arquivos alterados com 7 adições e 19 exclusões
  1. 7
    19
      src/main/java/io/zipcoder/ItemParser.java

+ 7
- 19
src/main/java/io/zipcoder/ItemParser.java Ver arquivo

@@ -26,10 +26,10 @@ public class ItemParser {
26 26
 
27 27
     public Item parseStringIntoItem(String rawItem) throws ItemParseException {
28 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 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 33
         return newItem;
34 34
     }
35 35
 
@@ -45,26 +45,14 @@ public class ItemParser {
45 45
         for (String keyValues : keyValuePairs) {
46 46
             ArrayList<String> keyAndValue = splitKeysAndValue(keyValues);
47 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 49
             }else{
50
-                itemDescription.put(convertToLowerCase(keyAndValue.get(0)), null);
50
+                itemDescription.put(keyAndValue.get(0).toLowerCase(), null);
51 51
             }
52 52
         }
53 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 56
     public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem) {
69 57
         String stringPattern = "[;|^]";
70 58
         ArrayList<String> response = splitStringWithRegexPattern(stringPattern, rawItem);
@@ -107,17 +95,17 @@ public class ItemParser {
107 95
         for (LinkedHashMap<String, Integer> item : itemSeenInfo) {
108 96
             for (Map.Entry entry : item.entrySet()) {
109 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 99
                             "Seen: %5d\n================ \t\t\t " +
112 100
                             "===========\n", entry.getKey(), entry.getValue()));
113 101
                 } else {
114
-                    output.append(String.format("Price: %-5s \t\t\t " +
102
+                    output.append(String.format("Price: %-5s \t\t\t\t " +
115 103
                             "Seen: %5d\n---------------- \t\t\t " +
116 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 109
         return output.toString();
122 110
     }
123 111