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..41238bf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,4 +20,8 @@
2.4
+
+ 11
+ 11
+
diff --git a/src/main/java/GroceryList.java b/src/main/java/GroceryList.java
new file mode 100644
index 0000000..434cae6
--- /dev/null
+++ b/src/main/java/GroceryList.java
@@ -0,0 +1,40 @@
+import java.text.SimpleDateFormat;
+
+public class GroceryList {
+ String name;
+ Double price;
+ SimpleDateFormat date;
+
+ public GroceryList() {
+ }
+
+ public GroceryList(String name, Double price, SimpleDateFormat date) {
+ this.name = name;
+ this.price = price;
+ this.date = date;
+ }
+
+ 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 getDate() {
+ return date;
+ }
+
+ public void setDate(SimpleDateFormat date) {
+ this.date = date;
+ }
+}
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index 632942a..8b8f310 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,17 +1,257 @@
import org.apache.commons.io.IOUtils;
+
+import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+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"));
- return result;
+ File file = new File(classLoader.getResource("RawData.txt").getFile());
+ StringBuilder result = new StringBuilder("");
+
+ try(Scanner scanner = new Scanner(file)){
+ while(scanner.hasNext()){
+ String line = scanner.nextLine();
+ result.append(line).append("\n");
+ }
+ } catch(IOException e){
+ e.printStackTrace();
+ }
+ return result.toString();
+ }
+
+ public String findAlphabetCharacters() {
+ StringBuilder result = new StringBuilder();
+ String jerkText = readRawDataToString();
+ Pattern pattern = Pattern.compile("[A-Z]", Pattern.CASE_INSENSITIVE); //"/^[A-Z]+$/i"
+ Matcher matcher = pattern.matcher(jerkText);
+ String findee;
+ while(matcher.find()) {
+ findee = matcher.group();
+ result.append(findee);
+ }
+ return result.toString();
}
- public static void main(String[] args) throws Exception{
+ public String nameChange(String input){
+ try{
+ Pattern pattern = Pattern.compile("name", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(input);
+ String nameString = matcher.replaceAll("Name");
+ return nameString;
+ } catch (Exception e){
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ 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 priceChange(String input){
+ try{
+ Pattern pattern = Pattern.compile("price", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(input);
+ String priceString = matcher.replaceAll("Price");
+ return priceString;
+ } 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 apples = matcher.replaceAll("Apples");
+ return apples;
+ } 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 bread = matcher.replaceAll("Bread");
+ return bread;
+ } 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 cookies = matcher.replaceAll("Cookies");
+ return cookies;
+ } catch (Exception e){
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public static void main(String[] args) {
String output = (new Main()).readRawDataToString();
System.out.println(output);
}
+
+ public int countMilk(){
+ List index = new ArrayList<>();
+ String jerkText = readRawDataToString();
+ Pattern pattern = Pattern.compile("milk", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(jerkText);
+
+ for (int i = 0; matcher.find(); i++) {
+ index.add(matcher.start());
+ }
+ return index.size();
+ }
+
+
+ public String getList(String input) {
+ try {
+ Pattern pattern = Pattern.compile("##");
+ Matcher matcher = pattern.matcher(input);
+ String result = matcher.replaceAll("\n");
+ return result;
+ } catch (Exception e) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public String correctSeparator(){
+ try{
+ String jerkText = readRawDataToString();
+ Pattern pattern = Pattern.compile("[!@^%*]");
+ Matcher matcher = pattern.matcher(jerkText);
+ String result = matcher.replaceAll(";");
+ return result;
+ } catch (Exception e) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public String readyForFormatting(){
+ String result1 = getList(correctSeparator());
+ String result2 = changeApples(result1);
+ String result3 = changeBread(result2);
+ String result4 = changeCookies(result3);
+ String result5 = changeMilk(result4);
+ String result6 = nameChange(result5);
+ String result7 = priceChange(result6);
+ return result7;
+ }
+ public int findGroceries(String input){
+ int holdingValue = 0;
+ boolean checkValue = false;
+ Pattern pattern = Pattern.compile(input, Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(readyForFormatting());
+ while (!checkValue) {
+ if (!matcher.find()){
+ checkValue = true;
+ continue;
+ }
+ holdingValue++;
+ }
+ return holdingValue;
+ }
+
+ public int countingErrors(){
+ int counter = 0;
+ counter += findGroceries("Name:;");
+ counter += findGroceries("milk") - (findGroceries("milk;price:3.23") + findGroceries("milk;price:1.23"));
+ return counter;
+ }
+
+ public String formatting(){
+ 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" +
+
+ "name: Apples seen: " + findGroceries("apples") + " 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;
+ }
+
+// String jerkText = readRawDataToString();
+//
+// Pattern pattern = Pattern.compile("##");
+// Matcher matcher = pattern.matcher(jerkText);
+//
+// return matcher.replaceAll("\n");
+// }
+//
+// public String correctSeparator(){
+// String fix = getList();
+// Pattern pattern = Pattern.compile("[!@^%*]");
+// Matcher matcher = pattern.matcher(fix);
+//
+// return matcher.replaceAll(";");
+// }
+//
+// public String semiColonSeparator(){ // HELPER to find semiColon and puts each on a new line
+// String list = correctSeparator();
+// Pattern pattern = Pattern.compile(";");
+// Matcher matcher = pattern.matcher(list);
+//
+// return matcher.replaceAll("\n");
+// }
+//
+//
+// /**
+// * any instance of the name milk
+// * anything with a price of 3.23
+// * anything with a price of 1.23 without name bread
+// */
+// public int countMilk(){
+// List indices = new ArrayList<>();
+// String jerkText = readRawDataToString();
+// Pattern pattern = Pattern.compile("milk", Pattern.CASE_INSENSITIVE);
+// Matcher matcher = pattern.matcher(jerkText);
+// for (int i = 0; matcher.find(); i++) {
+// indices.add(matcher.start());
+// }
+// return indices.size();
+// }
+//
+// public int countCookies(){
+// List ind;
+// return 0;
+// }
+
+
}
diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java
new file mode 100644
index 0000000..a0a84b1
--- /dev/null
+++ b/src/test/java/MainTest.java
@@ -0,0 +1,47 @@
+import org.junit.Assert;
+import org.junit.Test;
+
+public class MainTest {
+
+ Main test = new Main();
+
+ @Test
+ public void findAlphabetsTest() {
+ // When
+ String seeker = test.findAlphabetCharacters();
+ System.out.println(seeker);
+ }
+
+// @Test
+// public void getListTest() {
+// // When
+// String seeker = test.getList();
+// System.out.println(seeker);
+// }
+//
+// @Test
+// public void countMMilkTest() {
+// // When
+// int actualCount = test.countMilk();
+// int expectedCount = 8;
+// Assert.assertEquals(expectedCount, actualCount);
+// }
+//
+// @Test
+// public void correctSeparatorTest(){
+// // When
+// String seeker = test.correctSeparator();
+// System.out.println(seeker);
+// }
+//
+//
+// @Test
+// public void semiColonSeparatorTest() { // HELPER to find semiColon and puts each on a new line
+// // When
+// String seeker = test.semiColonSeparator();
+// System.out.println(seeker);
+// }
+
+
+
+}
diff --git a/target/classes/Main.class b/target/classes/Main.class
index c9d3858..02505bd 100644
Binary files a/target/classes/Main.class and b/target/classes/Main.class differ