From 2ac9c241abe8c4cc6664e05f650958cfeab059df Mon Sep 17 00:00:00 2001 From: MannyMb Date: Thu, 12 Aug 2021 15:43:05 -0400 Subject: [PATCH] will come back to fix tests --- Hurtlocker.iml | 18 --- pom.xml | 4 + src/main/java/GroceryList.java | 40 ++++++ src/main/java/Main.java | 248 ++++++++++++++++++++++++++++++++- src/test/java/MainTest.java | 47 +++++++ target/classes/Main.class | Bin 1162 -> 7262 bytes 6 files changed, 335 insertions(+), 22 deletions(-) delete mode 100644 Hurtlocker.iml create mode 100644 src/main/java/GroceryList.java create mode 100644 src/test/java/MainTest.java 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 c9d3858bc278f548c9eaabc471ed4e0ba034dcf0..02505bdd9aa577025834f441c14881babdf1265b 100644 GIT binary patch literal 7262 zcmbtZ349dg75{(9Zf3F>t_|06gm8poLkNe0Zh%T6S4{#E1Oc%Qn;}`)?5?{L2wH1Z zq_wSW?WIt)6%W*6i`oVRtG3qGTC2V9yVbVV+SZ=hgZ|&l>}EDe1%3_W+i$+(egF5q z_x|tg7=>dp`G_<;VlIyBIHBRu5XR%P(mWPI29Hbg zgpSYY_`GzV)bIrjPlYfI2X*Y$@kJe9(($y8D|LKX$5lF>(eV`>&uaLpNIh7N=kR<8 zU&Gfmd?SRjl?F!t8?@04q9p95Pzpvv5I({e{eO~|u17_d7NIm&2mF%zi%RM6$lk9pqlc zjicO|M7nO-MQZCp=>Q<+MG=lPH_~>S{+tT{aSa5r)XWK9q$x1JS@IdE$&oflM!XAZ#LFz6*XyYd(1S=6~EzeR(IRHmDtLvcrZOCq_G=Ie4kDl*wbyl}4j zl$U3?>z8FRNlWZtdYuY)yivSGA-K)`9O8~PrPDhTvRsSjdx0*x7Y#gf%OF~b)0){1 zZm1k&ny03_Z3lgMJl&nLUG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