#5 jasamuels

Open
jasamuels wants to merge 1 commits from jasamuels/JerkSON-Parser:master into master
1 changed files with 21 additions and 3 deletions
  1. 21
    3
      src/main/java/io/zipcoder/ItemParser.java

+ 21
- 3
src/main/java/io/zipcoder/ItemParser.java View File

1
 package io.zipcoder;
1
 package io.zipcoder;
2
 
2
 
3
+import java.lang.reflect.Array;
3
 import java.util.ArrayList;
4
 import java.util.ArrayList;
4
 import java.util.Arrays;
5
 import java.util.Arrays;
6
+import java.util.stream.Stream;
5
 
7
 
6
 public class ItemParser {
8
 public class ItemParser {
7
 
9
 
8
-
9
     public ArrayList<String> parseRawDataIntoStringArray(String rawData){
10
     public ArrayList<String> parseRawDataIntoStringArray(String rawData){
10
         String stringPattern = "##";
11
         String stringPattern = "##";
11
         ArrayList<String> response = splitStringWithRegexPattern(stringPattern , rawData);
12
         ArrayList<String> response = splitStringWithRegexPattern(stringPattern , rawData);
13
     }
14
     }
14
 
15
 
15
     public Item parseStringIntoItem(String rawItem) throws ItemParseException{
16
     public Item parseStringIntoItem(String rawItem) throws ItemParseException{
16
-        return null;
17
+        ItemParser item = new ItemParser();
18
+
19
+        ArrayList<String> temp2 = item.findKeyValuePairsInRawItemData(rawItem);
20
+        ArrayList<String> temp3 = new ArrayList<>();
21
+
22
+        for (int i = 0; i < temp2.size(); i++){
23
+            String temp = temp2.get(i).substring(temp2.get(i).indexOf(":") + 1);
24
+
25
+            if (temp.contains("##")){
26
+                temp = temp.replaceAll("##", "");
27
+            }
28
+            temp3.add(temp);
29
+        }
30
+
31
+        if (Double.valueOf(temp3.get(1)) == null) {
32
+            throw new ItemParseException();
33
+        }
34
+
35
+        return new Item(temp3.get(0).toLowerCase(), Double.valueOf(temp3.get(1)), temp3.get(2).toLowerCase(), temp3.get(3).toLowerCase());
17
     }
36
     }
18
 
37
 
19
     public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem){
38
     public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem){
27
     }
46
     }
28
 
47
 
29
 
48
 
30
-
31
 }
49
 }