瀏覽代碼

first checkin

Tariq Hook 6 年之前
當前提交
0f80a41055

+ 117
- 0
.gitignore 查看文件

@@ -0,0 +1,117 @@
1
+# Created by .ignore support plugin (hsz.mobi)
2
+### Java template
3
+# Compiled class file
4
+*.class
5
+
6
+# Log file
7
+*.log
8
+
9
+# BlueJ files
10
+*.ctxt
11
+
12
+# Mobile Tools for Java (J2ME)
13
+.mtj.tmp/
14
+
15
+# Package Files #
16
+*.jar
17
+*.war
18
+*.ear
19
+*.zip
20
+*.tar.gz
21
+*.rar
22
+
23
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24
+hs_err_pid*
25
+### Eclipse template
26
+
27
+.metadata
28
+bin/
29
+tmp/
30
+*.tmp
31
+*.bak
32
+*.swp
33
+*~.nib
34
+local.properties
35
+.settings/
36
+.loadpath
37
+.recommenders
38
+
39
+# Eclipse Core
40
+.project
41
+
42
+# External tool builders
43
+.externalToolBuilders/
44
+
45
+# Locally stored "Eclipse launch configurations"
46
+*.launch
47
+
48
+# PyDev specific (Python IDE for Eclipse)
49
+*.pydevproject
50
+
51
+# CDT-specific (C/C++ Development Tooling)
52
+.cproject
53
+
54
+# JDT-specific (Eclipse Java Development Tools)
55
+.classpath
56
+
57
+# Java annotation processor (APT)
58
+.factorypath
59
+
60
+# PDT-specific (PHP Development Tools)
61
+.buildpath
62
+
63
+# sbteclipse plugin
64
+.target
65
+
66
+# Tern plugin
67
+.tern-project
68
+
69
+# TeXlipse plugin
70
+.texlipse
71
+
72
+# STS (Spring Tool Suite)
73
+.springBeans
74
+
75
+# Code Recommenders
76
+.recommenders/
77
+
78
+# Scala IDE specific (Scala & Java development for Eclipse)
79
+.cache-main
80
+.scala_dependencies
81
+.worksheet
82
+### macOS template
83
+*.DS_Store
84
+.AppleDouble
85
+.LSOverride
86
+
87
+# Icon must end with two \r
88
+Icon
89
+
90
+
91
+# Thumbnails
92
+._*
93
+
94
+# Files that might appear in the root of a volume
95
+.DocumentRevisions-V100
96
+.fseventsd
97
+.Spotlight-V100
98
+.TemporaryItems
99
+.Trashes
100
+.VolumeIcon.icns
101
+.com.apple.timemachine.donotpresent
102
+
103
+# Directories potentially created on remote AFP share
104
+.AppleDB
105
+.AppleDesktop
106
+Network Trash Folder
107
+Temporary Items
108
+.apdisk
109
+
110
+#Intellij files
111
+.idea
112
+*.iml
113
+
114
+#maven build target
115
+target/
116
+
117
+*.log

+ 49
- 0
README 查看文件

@@ -0,0 +1,49 @@
1
+##WELCOME TO THE HURT LOCKER
2
+
3
+By this time you should have been introduced to Java Strings, Exceptions, Unit Testing, and Regex.
4
+
5
+#You will need all of these today!
6
+
7
+In this project you will find a file in the resource folder called RawData.txt. It was supposed to be a grocery list formated in JSON, but after a huge defeat this weekend in a game called Munchkin, Tariq your fearless yet petty leader decided to come reformat it in his own Object Notation. JerkSON... you are welcome.
8
+
9
+##JerkSON Format
10
+
11
+Just like Json , JerkSON is supposed to be a Key Value Pair data store.
12
+
13
+In Json Key and Value are seperated as such (Key:Value) where the colon is the seperator.
14
+
15
+In JerkSON Key and Value could be seperated by using a any of the following (:, @, ^, *, %) and there is no guarntee that there isn't another hidden symbol seperator. (There could be another one, or maybe there isn't , you tell me)... lol
16
+
17
+In Json Key and Value pairs are seperated by a ',' in JerkSON its '##'
18
+
19
+##Your Task
20
+Its your job to build a JerkSON data parser, that is able to read in the raw data , and output a string formated list that resembles (outputFormat.txt) 
21
+
22
+There are some things to look out for.... If you haven't figured it out by now Tariq has many wonderful qualities, spelling isn't one of them, so Words may not be spelled correctly. You need to decipher what Tariq was trying to spell using pattern matching.
23
+
24
+for example:
25
+
26
+In the shopping list Tariq has Cookies, but he could spell like Cookies, c00Kies, Co0kies and so on.
27
+
28
+YOU ARE NOT ALLOWED to use any Java based string manipulation!!!!!!!!!!!!
29
+
30
+You must use regex to detect the patterns and match them.
31
+
32
+
33
+Oh one more thing.... Tariq is kind of petty... so you can blame STELLA and JOCELYN for this.
34
+
35
+Its not guranteed that every Key will have a Value, and every Value will have a pair. For instance:
36
+
37
+you may see something like this
38
+
39
+Name:Milk;Price:3.23;type:;expiration:1/24/2016##
40
+
41
+Notice how TYPE has a key but no Value.... if you try and parse this into an object your program could crash.
42
+
43
+You will need to handle your exceptions!
44
+
45
+I also expect you to report on how many exceptions you saw while parsing the data.
46
+
47
+
48
+GOOD LUCK ZIPCODERS!!!! My the Odds be ever in your favor!!!!
49
+

+ 23
- 0
output.txt 查看文件

@@ -0,0 +1,23 @@
1
+name:    Milk 		 seen: 6 times
2
+============= 	 	 =============
3
+Price: 	 3.23		 seen: 5 times
4
+-------------		 -------------
5
+Price:   1.23		 seen: 1 time
6
+
7
+name:   Bread		 seen: 6 times
8
+=============		 =============
9
+Price:   1.23		 seen: 6 times
10
+-------------		 -------------
11
+
12
+name: Cookies     	 seen: 8 times
13
+=============     	 =============
14
+Price:   2.25        seen: 8 times
15
+-------------        -------------
16
+
17
+name:  Apples     	 seen: 4 times
18
+=============     	 =============
19
+Price:   0.25     	 seen: 2 times
20
+-------------     	 -------------
21
+Price:   0.23  	 	 seen: 2 times
22
+
23
+Errors         	 	 seen: 4 times

+ 23
- 0
pom.xml 查看文件

@@ -0,0 +1,23 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>io.zipcoder</groupId>
8
+    <artifactId>PainfullAfternoon</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+
11
+    <dependencies>
12
+        <dependency>
13
+            <groupId>junit</groupId>
14
+            <artifactId>junit</artifactId>
15
+            <version>4.12</version>
16
+        </dependency>
17
+        <dependency>
18
+            <groupId>org.apache.directory.studio</groupId>
19
+            <artifactId>org.apache.commons.io</artifactId>
20
+            <version>2.4</version>
21
+        </dependency>
22
+    </dependencies>
23
+</project>

+ 61
- 0
src/main/java/io/zipcoder/Item.java 查看文件

@@ -0,0 +1,61 @@
1
+package io.zipcoder;
2
+
3
+public class Item {
4
+    private String name;
5
+    private Double price;
6
+    private String type;
7
+    private String expiration;
8
+
9
+    /**
10
+     * Item should not be created unless you have all of the elements, which is why you are forcing
11
+     * it to be set in the constructor. In ItemParser, if you do not find all the elements of a Item,
12
+     * you should throw an Custom Exception.
13
+     * @param name
14
+     * @param price
15
+     * @param type
16
+     * @param expiration
17
+     */
18
+    public Item(String name, Double price, String type, String expiration){
19
+        this.name = name;
20
+        this.price = price;
21
+        this.type = type;
22
+        this.expiration = expiration;
23
+    }
24
+
25
+    public String getName() {
26
+        return name;
27
+    }
28
+
29
+    public void setName(String name) {
30
+        this.name = name;
31
+    }
32
+
33
+    public Double getPrice() {
34
+        return price;
35
+    }
36
+
37
+    public void setPrice(Double price) {
38
+        this.price = price;
39
+    }
40
+
41
+    public String getType() {
42
+        return type;
43
+    }
44
+
45
+    public void setType(String type) {
46
+        this.type = type;
47
+    }
48
+
49
+    public String getExpiration() {
50
+        return expiration;
51
+    }
52
+
53
+    public void setExpiration(String expiration) {
54
+        this.expiration = expiration;
55
+    }
56
+
57
+    @Override
58
+    public String toString(){
59
+        return "name:" + name + " price:" + price + " type:" + type + " expiration:" + expiration;
60
+    }
61
+}

+ 4
- 0
src/main/java/io/zipcoder/ItemParseException.java 查看文件

@@ -0,0 +1,4 @@
1
+package io.zipcoder;
2
+
3
+public class ItemParseException extends Exception {
4
+}

+ 23
- 0
src/main/java/io/zipcoder/ItemParser.java 查看文件

@@ -0,0 +1,23 @@
1
+package io.zipcoder;
2
+
3
+import java.util.ArrayList;
4
+
5
+public class ItemParser {
6
+
7
+    /**
8
+     *
9
+     * @param rawData
10
+     * @return
11
+     */
12
+
13
+    public ArrayList<String> parseRawDataIntoStringArray(String rawData){
14
+        return null;
15
+    }
16
+
17
+    public Item parseStringIntoItem(String rawItem) throws ItemParseException{
18
+        return null;
19
+    }
20
+
21
+
22
+
23
+}

+ 17
- 0
src/main/java/io/zipcoder/Main.java 查看文件

@@ -0,0 +1,17 @@
1
+package io.zipcoder;
2
+
3
+import org.apache.commons.io.IOUtils;
4
+
5
+public class Main {
6
+
7
+    public String readRawDataToString() throws Exception{
8
+        ClassLoader classLoader = getClass().getClassLoader();
9
+        String result = IOUtils.toString(classLoader.getResourceAsStream("RawData.txt"));
10
+        return result;
11
+    }
12
+
13
+    public static void main(String[] args) throws Exception{
14
+        String output = (new Main()).readRawDataToString();
15
+        // TODO: parse the data in output into items, and display to console.
16
+    }
17
+}

+ 1
- 0
src/main/resources/RawData.txt 查看文件

@@ -0,0 +1 @@
1
+naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##naME:BreaD;price:1.23;type:Food;expiration:1/02/2016##NAMe:BrEAD;price:1.23;type:Food;expiration:2/25/2016##naMe:MiLK;price:3.23;type:Food^expiration:1/11/2016##naMe:Cookies;price:2.25;type:Food%expiration:1/25/2016##naMe:CoOkieS;price:2.25;type:Food*expiration:1/25/2016##naMe:COokIes;price:2.25;type:Food;expiration:3/22/2016##naMe:COOkieS;price:2.25;type:Food;expiration:1/25/2016##NAME:MilK;price:3.23;type:Food;expiration:1/17/2016##naMe:MilK;price:1.23;type:Food!expiration:4/25/2016##naMe:apPles;price:0.25;type:Food;expiration:1/23/2016##naMe:apPles;price:0.23;type:Food;expiration:5/02/2016##NAMe:BrEAD;price:1.23;type:Food;expiration:1/25/2016##naMe:;price:3.23;type:Food;expiration:1/04/2016##naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##naME:BreaD;price:1.23;type:Food@expiration:1/02/2016##NAMe:BrEAD;price:1.23;type:Food@expiration:2/25/2016##naMe:MiLK;priCe:;type:Food;expiration:1/11/2016##naMe:Cookies;price:2.25;type:Food;expiration:1/25/2016##naMe:Co0kieS;pRice:2.25;type:Food;expiration:1/25/2016##naMe:COokIes;price:2.25;type:Food;expiration:3/22/2016##naMe:COOkieS;Price:2.25;type:Food;expiration:1/25/2016##NAME:MilK;price:3.23;type:Food;expiration:1/17/2016##naMe:MilK;priCe:;type:Food;expiration:4/25/2016##naMe:apPles;prIce:0.25;type:Food;expiration:1/23/2016##naMe:apPles;pRice:0.23;type:Food;expiration:5/02/2016##NAMe:BrEAD;price:1.23;type:Food;expiration:1/25/2016##naMe:;price:3.23;type:Food^expiration:1/04/2016##

+ 47
- 0
src/test/java/io/zipcoder/ItemParserTest.java 查看文件

@@ -0,0 +1,47 @@
1
+package io.zipcoder;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+import java.util.ArrayList;
8
+
9
+import static org.junit.Assert.*;
10
+
11
+public class ItemParserTest {
12
+
13
+    private String rawSingleItem =    "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##";
14
+
15
+    private String rawBrokenSingleItem =    "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##";
16
+
17
+    private String rawMultipleItems = "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##"
18
+                                      +"naME:BreaD;price:1.23;type:Food;expiration:1/02/2016##"
19
+                                      +"NAMe:BrEAD;price:1.23;type:Food;expiration:2/25/2016##";
20
+    private ItemParser itemParser;
21
+
22
+    @Before
23
+    public void setUp(){
24
+        itemParser = new ItemParser();
25
+    }
26
+
27
+    @Test
28
+    public void parseRawDataIntoStringArrayTest(){
29
+        Integer expectedArraySize = 3;
30
+        ArrayList<String> items = itemParser.parseRawDataIntoStringArray(rawMultipleItems);
31
+        Integer actualArraySize = items.size();
32
+        assertEquals(expectedArraySize, actualArraySize);
33
+    }
34
+
35
+    @Test
36
+    public void parseStringIntoItemTest() throws ItemParseException{
37
+        Item expected = new Item("milk", 3.23, "food","1/25/2016");
38
+        Item actual = itemParser.parseStringIntoItem(rawSingleItem);
39
+        assertEquals(expected.toString(), actual.toString());
40
+    }
41
+
42
+    @Test(expected = ItemParseException.class)
43
+    public void parseBrokenStringIntoItemTest() throws ItemParseException{
44
+        itemParser.parseStringIntoItem(rawBrokenSingleItem);
45
+    }
46
+
47
+}