From 3241dc5b025846eb35f966604434b05d1f66b3c1 Mon Sep 17 00:00:00 2001 From: Jbanksalpha <78812718+Jbanksalpha@users.noreply.github.com> Date: Mon, 12 Apr 2021 16:29:19 -0400 Subject: [PATCH 1/2] worked on files --- Hurtlocker.iml | 18 ----------- pom.xml | 12 +++++++ src/main/java/Main.java | 53 +++++++++++++++++++++++++++++-- src/main/java/ParsedList.java | 56 +++++++++++++++++++++++++++++++++ src/main/resources/RawData.txt | 3 +- target/classes/Main.class | Bin 1162 -> 5023 bytes target/classes/RawData.txt | 3 +- 7 files changed, 123 insertions(+), 22 deletions(-) delete mode 100644 Hurtlocker.iml create mode 100644 src/main/java/ParsedList.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..3c31de2 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ io.zipcoder HurtLocker 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 632942a..db2483f 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,9 +1,19 @@ +import jdk.nashorn.internal.parser.DateParser; import org.apache.commons.io.IOUtils; + +import java.io.File; +import java.io.FileWriter; import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.regex.Pattern; +import java.util.stream.Collectors; public class Main { - public String readRawDataToString() throws Exception{ + public String readRawDataToString() throws Exception{ ClassLoader classLoader = getClass().getClassLoader(); String result = IOUtils.toString(classLoader.getResourceAsStream("RawData.txt")); return result; @@ -11,7 +21,46 @@ public String readRawDataToString() throws Exception{ public static void main(String[] args) throws Exception{ String output = (new Main()).readRawDataToString(); - System.out.println(output); + //System.out.println(output); + + List shoppingList = (List) Pattern.compile("RawData.txt", Pattern.UNIX_LINES) + .splitAsStream(output).map(String::toLowerCase).collect(Collectors.toList()); + + /* Map shop = new LinkedHashMap<>(); + shoppingList.forEach(word -> + shop.compute(word, (k, v) -> v != null ? v + 1 : 1)); + shop.forEach((k,v) -> System.out.println(String.format("%-20s Seen: %d", k, v))); */ + } + + private String uploadedFile() { + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource("RawData.txt").getFile()); + StringBuilder result = new StringBuilder(""); + + try(Scanner scanner = new Scanner(file)){ + while(scanner.hasNextLine()) { + String line = scanner.nextLine(); + result.append(line).append("\n"); + } + scanner.close(); + } catch(IOException e) { + e.printStackTrace(); + } + + return result.toString(); + } + + + + + + } + + + + + + diff --git a/src/main/java/ParsedList.java b/src/main/java/ParsedList.java new file mode 100644 index 0000000..8f62ca8 --- /dev/null +++ b/src/main/java/ParsedList.java @@ -0,0 +1,56 @@ +/*import java.io.File; +import java.io.IOException; +import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ParsedList { + + + static String rawDataStuff; + public ParsedList() {this.rawDataStuff = uploadedFile();} + + private String uploadedFile() { + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource("RawData.txt").getFile()); + StringBuilder result = new StringBuilder(""); + + try(Scanner scanner = new Scanner(file)){ + while(scanner.hasNextLine()) { + String line = scanner.nextLine(); + result.append(line).append("\n"); + } + scanner.close(); + } catch(IOException e) { + e.printStackTrace(); + } + + return result.toString(); + } + + public static String getRawDataStuff() { + return rawDataStuff; + } + + public String parsedString() { + if (this.rawDataStuff.matches("m.+k")){return "MIlk";} + else if (this.rawDataStuff.matches("br.+d")){return "Bread";} + else if (this.rawDataStuff.matches("c.+s")){return "Cookies";} + else {return "Apples";} + + } + public String milkMatch() { + Pattern pattern = Pattern.compile("m.+k"); + Matcher matcher = pattern.matcher(rawDataStuff); + boolean matchFound = matcher.find(); + } + + + + + + + + + +}*/ diff --git a/src/main/resources/RawData.txt b/src/main/resources/RawData.txt index f8c15a3..39f7256 100644 --- a/src/main/resources/RawData.txt +++ b/src/main/resources/RawData.txt @@ -1 +1,2 @@ -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## \ No newline at end of file +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## + diff --git a/target/classes/Main.class b/target/classes/Main.class index c9d3858bc278f548c9eaabc471ed4e0ba034dcf0..32d90123e605bd4d01bbe4f7f2e2bd98f06cf6ea 100644 GIT binary patch literal 5023 zcma)Ad3+Pc75>JSweoraStfu(022%t8zZjL#0CO(Aa-LLf{dw2(`J#^wy>;Kq!r+{ z=|R)`ZrY^jnVxRb(n6Zr98E|s(x&O%()(_D-%al}^qbk0v@#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c_q}O5SwV0*dm;;Ag#h^<8>e?$g1R! Date: Tue, 13 Apr 2021 07:38:44 -0400 Subject: [PATCH 2/2] reset the main method class of the lab to try all over again --- src/main/java/Main.java | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index db2483f..97d6c34 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -21,36 +21,13 @@ public String readRawDataToString() throws Exception{ public static void main(String[] args) throws Exception{ String output = (new Main()).readRawDataToString(); - //System.out.println(output); + System.out.println(output); - List shoppingList = (List) Pattern.compile("RawData.txt", Pattern.UNIX_LINES) - .splitAsStream(output).map(String::toLowerCase).collect(Collectors.toList()); - - /* Map shop = new LinkedHashMap<>(); - shoppingList.forEach(word -> - shop.compute(word, (k, v) -> v != null ? v + 1 : 1)); - shop.forEach((k,v) -> System.out.println(String.format("%-20s Seen: %d", k, v))); */ } - private String uploadedFile() { - ClassLoader classLoader = getClass().getClassLoader(); - File file = new File(classLoader.getResource("RawData.txt").getFile()); - StringBuilder result = new StringBuilder(""); - - try(Scanner scanner = new Scanner(file)){ - while(scanner.hasNextLine()) { - String line = scanner.nextLine(); - result.append(line).append("\n"); - } - scanner.close(); - } catch(IOException e) { - e.printStackTrace(); - } - - return result.toString(); - } +