diff --git a/Hurtlocker.iml b/Hurtlocker.iml
deleted file mode 100644
index 22967e8..0000000
--- a/Hurtlocker.iml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 39639cd..de7abea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,18 @@
io.zipcoder
HurtLocker
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 11
+
+
+
+
diff --git a/src/main/java/Grocery.java b/src/main/java/Grocery.java
new file mode 100644
index 0000000..b0a1148
--- /dev/null
+++ b/src/main/java/Grocery.java
@@ -0,0 +1,40 @@
+import java.text.SimpleDateFormat;
+
+public class Grocery {
+ private String name;
+ private Double price;
+ private SimpleDateFormat expirationDate;
+
+ public Grocery() {
+ }
+
+ public Grocery(String name, Double price, SimpleDateFormat expirationDate) {
+ this.name = name;
+ this.price = price;
+ this.expirationDate = expirationDate;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Double getPrice() {
+ return price;
+ }
+
+ public void setPrice(Double price) {
+ this.price = price;
+ }
+
+ public SimpleDateFormat getExpirationDate() {
+ return expirationDate;
+ }
+
+ public void setExpirationDate(SimpleDateFormat expirationDate) {
+ this.expirationDate = expirationDate;
+ }
+}
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index 632942a..82ba7ce 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,17 +1,252 @@
import org.apache.commons.io.IOUtils;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class Main {
- public String readRawDataToString() throws Exception{
+ public String readRawDataToString(){
ClassLoader classLoader = getClass().getClassLoader();
- String result = IOUtils.toString(classLoader.getResourceAsStream("RawData.txt"));
+ String result = null;
+ try {
+ result = IOUtils.toString(classLoader.getResourceAsStream("RawData.txt"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
return result;
}
public static void main(String[] args) throws Exception{
- String output = (new Main()).readRawDataToString();
- System.out.println(output);
+ Main newMain = new Main();
+ String output = newMain.readRawDataToString();
+ System.out.println(newMain.getList(output));
+ }
+
+ public String findAlphabetical() throws Exception {
+ String jerkText = readRawDataToString();
+ Pattern pattern = Pattern.compile("/^[A-Z]",Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(jerkText);
+ return null;
+ }
+
+ public String getList(String input) {
+ Pattern pattern = Pattern.compile("##");
+ Matcher matcher = pattern.matcher(input);
+ String result = matcher.replaceAll("\n");
+ return result;
+ }
+
+ public String correctSeparator(){
+
+ String correctMe = readRawDataToString();
+ Pattern pattern = Pattern.compile("[!@^%*]");
+ Matcher matcher = pattern.matcher(correctMe);
+ return matcher.replaceAll(";");
+ }
+
+ public String findSeparatorCorrected(){
+ String list = correctSeparator();
+ Pattern pattern = Pattern.compile(";");
+ Matcher matcher = pattern.matcher(list);
+ return matcher.replaceAll("\n");
+ }
+
+ public String reformatAfterCorrectSeparator(){
+ String list = findSeparatorCorrected();
+ Pattern pattern = Pattern.compile("2016");
+ Matcher matcher = pattern.matcher(list);
+ return matcher.replaceAll("2016\n");
+ }
+
+ public Integer countMilk323(){
+ List indexes = new ArrayList<>();
+ String jerkText = readRawDataToString();
+ Pattern pattern = Pattern.compile("milk",Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(jerkText);
+ while(matcher.find()){
+ indexes.add(matcher.start());
+ }
+ return indexes.size();
+ }
+ public Integer countCookies(){
+ List indexes = new ArrayList<>();
+ String jerkText = readRawDataToString();
+ Pattern pattern = Pattern.compile("c[oO0][oO0]kies",Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(jerkText);
+ while(matcher.find()){
+ indexes.add(matcher.start());
+ }
+ return indexes.size();
}
+
+ public Integer countBread(){
+ List indexes = new ArrayList<>();
+ String jerkText = readRawDataToString();
+ Pattern pattern = Pattern.compile("bread",Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(jerkText);
+ while(matcher.find()){
+ indexes.add(matcher.start());
+ }
+ return indexes.size();
+ }
+
+ public Integer countApple(){
+ List indexes = new ArrayList<>();
+ String jerkText = readRawDataToString();
+ Pattern pattern = Pattern.compile("apples",Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(jerkText);
+ while(matcher.find()){
+ indexes.add(matcher.start());
+ }
+ return indexes.size();
+ }
+
+//-------------Formatting String Into Correct List----------------
+ public String changeMilk (String input) {
+ try {
+ Pattern pattern = Pattern.compile("milk", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(input);
+ String milk = matcher.replaceAll("Milk");
+
+ return milk;
+ } catch (Exception e) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public String changeBread (String input) {
+ try {
+ Pattern pattern = Pattern.compile("bread", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(input);
+ String milk = matcher.replaceAll("Bread");
+
+ return milk;
+ } catch (Exception e) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public String changeCookies (String input) {
+ try {
+ Pattern pattern = Pattern.compile("c[o0][o0]kies", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(input);
+ String milk = matcher.replaceAll("Cookies");
+
+ return milk;
+ } catch (Exception e) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public String changeApples (String input) {
+ try {
+ Pattern pattern = Pattern.compile("apples", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(input);
+ String milk = matcher.replaceAll("Apples");
+
+ return milk;
+ } catch (Exception e) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public String nameChange(String input) {
+ try {
+ Pattern pattern = Pattern.compile("name", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(input);
+ String milk = matcher.replaceAll("Name");
+
+ return milk;
+ } catch (Exception e) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public String priceChange(String input) {
+ try {
+ Pattern pattern = Pattern.compile("price", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(input);
+ String milk = matcher.replaceAll("Price");
+
+ return milk;
+ } catch (Exception e) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public String readyForFormatting() {
+ String result = getList(correctSeparator());
+ String result1 = changeApples(result);
+ String result2 = changeBread(result1);
+ String result3 = changeCookies(result2);
+ String result4 = changeMilk(result3);
+ String result5 = nameChange(result4);
+ String result6 = priceChange(result5);
+ return result6;
+ }
+
+
+ public String doingTheFormatting() {
+ String result =
+ "name: Milk seen: " + findGroceries("milk") + " times\n" +
+ "============= =============\n" +
+ "Price: 3.23 seen: " + findGroceries("milk;price:3.23") + " times\n" +
+ "------------- -------------\n" +
+ "Price: 1.23 seen: " + findGroceries("milk;price:1.23") + " times\n\n" +
+
+ "name: Bread seen: " + findGroceries("bread") + " times\n" +
+ "============= =============\n" +
+ "Price: 1.23 seen: " + findGroceries("bread") + " times\n" +
+ "------------- -------------\n\n" +
+
+ "name: Cookies seen: " + findGroceries("cookies") + " times\n" +
+ "============= =============\n" +
+ "Price: 2.25 seen: " + findGroceries("cookies") + " times\n" +
+ "------------- -------------\n\n" +
+
+ "name: Apples seen: " + (findGroceries("apples;price:0.25") + findGroceries("apples;price:0.23")) + " times\n" +
+ "============= =============\n" +
+ "Price: 0.25 seen: " + findGroceries("price:0.25") + " times\n" +
+ "------------- -------------\n" +
+ "Price: 0.23 seen: " + findGroceries("price:0.23") + " times\n\n" +
+
+ "Errors seen: " + countingErrors() + " times";
+ return result;
+ }
+
+
+ // we can use a "scanner" something to check when the (';' <- those bois) come up
+
+ public int findGroceries(String input) {
+ Integer holdingValue = 0;
+ Boolean checkVal = false;
+ Pattern pattern = Pattern.compile(input, Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(readyForFormatting());
+ while(!checkVal) {
+ if (!matcher.find()) {
+ checkVal = true;
+ continue;
+ }
+ holdingValue++;
+ }
+ return holdingValue;
+ }
+
+ public int countingErrors() {
+ int counter = 0;
+ // beware
+// counter += findGroceries("apples") - (findGroceries("apples;price:0.25") + findGroceries("apples;price:0.23"));
+ counter += findGroceries("Name:;");
+ counter += findGroceries("milk") - (findGroceries("milk;price:3.23") + findGroceries("milk;price:1.23"));
+ return counter;
+ }
+
+
+
+
+
+
}
diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java
new file mode 100644
index 0000000..84a1a2b
--- /dev/null
+++ b/src/test/java/MainTest.java
@@ -0,0 +1,55 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+public class MainTest {
+ Main test = new Main();
+
+ /**
+ * //System.out.println(newMain.countMilk323());
+ * //System.out.println(newMain.correctSeparator());
+ * //System.out.println(newMain.findSeparatorCorrected());
+ * System.out.println(newMain.reformatAfterCorrectSeparator());
+ */
+ @Test
+ public void testPoundToNewLine(){
+ System.out.println(test.getList(test.readRawDataToString()));
+ }
+ @Test
+ public void testCorrectSeparator(){
+ System.out.println(test.correctSeparator());
+
+ }
+ @Test
+ public void testFindSeparatorCorrected(){
+ System.out.println(test.findSeparatorCorrected());
+ }
+
+ @Test
+ public void testReformatAfterCorrectSeparator(){
+ System.out.println(test.reformatAfterCorrectSeparator());
+ }
+
+ @Test
+ public void testCountMilk323(){
+ //given
+ Integer expected = 8;
+ //when
+ Integer actual = test.countMilk323();
+ //then
+ Assert.assertEquals(expected,actual);
+ }
+
+ @Test
+ public void testReadyForFormatting(){
+ System.out.println(test.readyForFormatting());
+ }
+
+ @Test
+ public void testFinal(){
+ System.out.println(test.doingTheFormatting());
+ }
+
+
+
+
+}
diff --git a/target/classes/Main.class b/target/classes/Main.class
index c9d3858..e1f664e 100644
Binary files a/target/classes/Main.class and b/target/classes/Main.class differ