|
@@ -1,5 +1,7 @@
|
1
|
1
|
package io.zipcoder;
|
2
|
2
|
|
|
3
|
+import com.sun.xml.internal.fastinfoset.util.CharArray;
|
|
4
|
+
|
3
|
5
|
import java.util.ArrayList;
|
4
|
6
|
import java.util.Arrays;
|
5
|
7
|
import java.util.logging.Level;
|
|
@@ -18,21 +20,32 @@ public class ItemParser {
|
18
|
20
|
return response;
|
19
|
21
|
}
|
20
|
22
|
|
21
|
|
- public String correctCase(){
|
22
|
|
- return "";
|
23
|
|
- }
|
|
23
|
+ public String toLowerCase(String str){
|
|
24
|
+
|
|
25
|
+ StringBuilder inputLineT = new StringBuilder(str);
|
|
26
|
+
|
|
27
|
+ for(int i = 0 ; i < inputLineT.length() ; i++)
|
|
28
|
+ {
|
|
29
|
+ if(inputLineT.charAt(i) >= 65 && inputLineT.charAt(i) <=91)
|
|
30
|
+ {
|
|
31
|
+ inputLineT.setCharAt(i, (char)(inputLineT.charAt(i)+32));
|
|
32
|
+ }
|
|
33
|
+ }
|
|
34
|
+ return inputLineT.toString();
|
|
35
|
+ }
|
|
36
|
+
|
24
|
37
|
|
25
|
38
|
public Item parseStringIntoItem(String rawItem) throws ItemParseException{
|
26
|
|
- ArrayList<String> properties = findKeyValuePairsInRawItemData(rawItem);
|
27
|
|
- Pattern patternAlpha = Pattern.compile("(?<=:).*");
|
|
39
|
+ ArrayList<String> properties = findKeyValuePairsInRawItemData(toLowerCase(toLowerCase(rawItem)));
|
|
40
|
+ Pattern patternAlpha = Pattern.compile("(?<=:)[^\\s].*");
|
28
|
41
|
Pattern patternDate = Pattern.compile("\\d/\\d\\d/\\d\\d\\d\\d");
|
29
|
42
|
Pattern patternDouble = Pattern.compile("\\d.\\d\\d");
|
30
|
43
|
Matcher mName = patternAlpha.matcher(properties.get(0));
|
31
|
44
|
Matcher mPrice = patternDouble.matcher(properties.get(1));
|
32
|
45
|
Matcher mDescription = patternAlpha.matcher(properties.get(2));
|
33
|
46
|
Matcher mExpiration = patternDate.matcher(properties.get(3));
|
|
47
|
+ int exceptionCount=0;
|
34
|
48
|
|
35
|
|
-try {
|
36
|
49
|
|
37
|
50
|
if (mName.find() && mDescription.find() && mPrice.find() && mExpiration.find()) {
|
38
|
51
|
String name = mName.group();
|
|
@@ -40,13 +53,11 @@ try {
|
40
|
53
|
String type = mDescription.group();
|
41
|
54
|
String expiration = mExpiration.group();
|
42
|
55
|
return new Item(name, price, type, expiration);
|
43
|
|
- }
|
44
|
|
- } catch( ItemParseException e ){
|
45
|
|
- log.log(Level.WARNING, "invalid");
|
|
56
|
+ } else {
|
|
57
|
+ throw new ItemParseException(); }
|
46
|
58
|
}
|
47
|
59
|
|
48
|
|
- return null;
|
49
|
|
- }
|
|
60
|
+
|
50
|
61
|
|
51
|
62
|
public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem){
|
52
|
63
|
String stringPattern = "[;|^!%@*]";
|