From 3afea46c0768e6730c3624ac28bdd30d8a813024 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 09:13:12 -0500 Subject: [PATCH 01/17] skeletized methods --- Hurtlocker.iml | 18 ------------------ src/main/java/Main.java | 1 - src/main/java/RegexThis.java | 12 ++++++++++++ 3 files changed, 12 insertions(+), 19 deletions(-) delete mode 100644 Hurtlocker.iml create mode 100644 src/main/java/RegexThis.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/src/main/java/Main.java b/src/main/java/Main.java index 632942a..cba5d1c 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -12,6 +12,5 @@ public String readRawDataToString() throws Exception{ public static void main(String[] args) throws Exception{ String output = (new Main()).readRawDataToString(); System.out.println(output); - } } diff --git a/src/main/java/RegexThis.java b/src/main/java/RegexThis.java new file mode 100644 index 0000000..bf33131 --- /dev/null +++ b/src/main/java/RegexThis.java @@ -0,0 +1,12 @@ +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class RegexThis { + //3 to 5 lines of regex + private String orig; + public static String regexer(String raw){ + + return raw; + } + +} From 9e3ea5e098ca0396be82b4b3830b57511fb8b7f0 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 09:37:16 -0500 Subject: [PATCH 02/17] created item builder class --- src/main/java/Item.java | 76 ++++++++++++++++++++++++++++++++++++ src/main/java/RegexThis.java | 9 +++-- 2 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 src/main/java/Item.java diff --git a/src/main/java/Item.java b/src/main/java/Item.java new file mode 100644 index 0000000..6c6fee0 --- /dev/null +++ b/src/main/java/Item.java @@ -0,0 +1,76 @@ +public class Item { + private final String name; + private final String price; + private final String type; + private final String expiration; + + public Item(ItemBuilder builder) { + this.name = builder.getName(); + this.price = builder.getPrice(); + this.type = builder.getType(); + this.expiration = builder.getExpiration(); + } + + public String getName() { + return name; + } + + public String getPrice() { + return price; + } + + public String getType() { + return type; + } + + public String getExpiration() { + return expiration; + } + + public static class ItemBuilder{ + private String name; + private String price; + private String type; + private String expiration; + public ItemBuilder(){ + } + public ItemBuilder setName(String name) { + this.name = name; + return this; + } + + public ItemBuilder setPrice(String price) { + this.price = price; + return this; + } + + public ItemBuilder setType(String type) { + this.type = type; + return this; + } + + public ItemBuilder setExpiration(String expiration) { + this.expiration = expiration; + return this; + } + + public String getName() { + return name; + } + + public String getPrice() { + return price; + } + + public String getType() { + return type; + } + + public String getExpiration() { + return expiration; + } + public Item build(){ + return new Item(this); + } + } +} diff --git a/src/main/java/RegexThis.java b/src/main/java/RegexThis.java index bf33131..f94c2bd 100644 --- a/src/main/java/RegexThis.java +++ b/src/main/java/RegexThis.java @@ -1,12 +1,15 @@ +import java.util.HashMap; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexThis { //3 to 5 lines of regex private String orig; - public static String regexer(String raw){ - - return raw; + public static Map regexer(String raw){ + Map refined = new HashMap(); + "" + return refined; } } From ebfc01a54fba389c07d3e228f8332807f8f4ece2 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 10:22:07 -0500 Subject: [PATCH 03/17] split apart the entries --- pom.xml | 12 ++++++++++++ src/main/java/RegexThis.java | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 39639cd..8d2631c 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ io.zipcoder HurtLocker 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 6 + 6 + + + + diff --git a/src/main/java/RegexThis.java b/src/main/java/RegexThis.java index f94c2bd..d6178ea 100644 --- a/src/main/java/RegexThis.java +++ b/src/main/java/RegexThis.java @@ -1,3 +1,4 @@ +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -6,10 +7,9 @@ public class RegexThis { //3 to 5 lines of regex private String orig; - public static Map regexer(String raw){ - Map refined = new HashMap(); - "" - return refined; + public static String[] splitter(String raw){ + return Arrays.copyOf((Pattern.compile("##")).split(raw),(Pattern.compile("##")).split(raw).length - 1); } + private static } From f135ac67270308dee88faef6644281f466ad2717 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 10:33:11 -0500 Subject: [PATCH 04/17] added error flag in itemBuilder --- src/main/java/Item.java | 12 ++++++++++++ src/main/java/RegexThis.java | 7 ++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/Item.java b/src/main/java/Item.java index 6c6fee0..4a1c3bf 100644 --- a/src/main/java/Item.java +++ b/src/main/java/Item.java @@ -3,12 +3,14 @@ public class Item { private final String price; private final String type; private final String expiration; + private boolean isError = false; public Item(ItemBuilder builder) { this.name = builder.getName(); this.price = builder.getPrice(); this.type = builder.getType(); this.expiration = builder.getExpiration(); + this.isError = builder.getIsError(); } public String getName() { @@ -26,12 +28,14 @@ public String getType() { public String getExpiration() { return expiration; } + //equals method public static class ItemBuilder{ private String name; private String price; private String type; private String expiration; + private boolean isError = false; public ItemBuilder(){ } public ItemBuilder setName(String name) { @@ -53,6 +57,10 @@ public ItemBuilder setExpiration(String expiration) { this.expiration = expiration; return this; } + public ItemBuilder denoteError(){ + this.isError = true; + return this; + } public String getName() { return name; @@ -69,6 +77,10 @@ public String getType() { public String getExpiration() { return expiration; } + + public boolean getIsError(){ + return isError; + } public Item build(){ return new Item(this); } diff --git a/src/main/java/RegexThis.java b/src/main/java/RegexThis.java index d6178ea..1ae3887 100644 --- a/src/main/java/RegexThis.java +++ b/src/main/java/RegexThis.java @@ -8,8 +8,9 @@ public class RegexThis { //3 to 5 lines of regex private String orig; public static String[] splitter(String raw){ - return Arrays.copyOf((Pattern.compile("##")).split(raw),(Pattern.compile("##")).split(raw).length - 1); + return (Pattern.compile("##")).split(raw); + } + public static String[][] paramSplitter(String[] raw){ + return (Pattern.compile) } - private static - } From 2ff0aeb9b4fa9458432ca750cebe11fb86d4e4b4 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 12:20:58 -0500 Subject: [PATCH 05/17] Regexer complete --- src/main/java/Item.java | 8 ++++---- src/main/java/RegexThis.java | 35 ++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/main/java/Item.java b/src/main/java/Item.java index 4a1c3bf..1c642c4 100644 --- a/src/main/java/Item.java +++ b/src/main/java/Item.java @@ -31,10 +31,10 @@ public String getExpiration() { //equals method public static class ItemBuilder{ - private String name; - private String price; - private String type; - private String expiration; + private String name = ""; + private String price = ""; + private String type = ""; + private String expiration = ""; private boolean isError = false; public ItemBuilder(){ } diff --git a/src/main/java/RegexThis.java b/src/main/java/RegexThis.java index 1ae3887..0e70088 100644 --- a/src/main/java/RegexThis.java +++ b/src/main/java/RegexThis.java @@ -1,16 +1,33 @@ -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; +import com.sun.media.sound.InvalidFormatException; + +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexThis { //3 to 5 lines of regex - private String orig; - public static String[] splitter(String raw){ - return (Pattern.compile("##")).split(raw); - } - public static String[][] paramSplitter(String[] raw){ - return (Pattern.compile) + public static List regexer(String raw){ + Pattern p = Pattern.compile("(?:##)?(?:name\\W)?([\\w]+)?(?:\\Wprice\\W)?([\\w\\.]+)?(?:\\Wtype\\W)?([\\w]+)?(?:\\Wexpiration\\W)?([\\w\\/]+)?" + ,Pattern.CASE_INSENSITIVE); + Matcher m = p.matcher(raw); + List items = new ArrayList(); + while(m.find()){ + if(m.groupCount() != 4){ + Item defect = new Item.ItemBuilder() + .denoteError() + .build(); + items.add(defect); + } + else{ + Item newbie = new Item.ItemBuilder() + .setName(m.group(0)) + .setPrice(m.group(1)) + .setType(m.group(2)) + .setExpiration(m.group(3)) + .build(); + items.add(newbie); + } + } + return items; } } From 6d99abe565e1350b5a80f3ca374d9bd4829c614b Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 12:26:57 -0500 Subject: [PATCH 06/17] added to string method to item --- src/main/java/Item.java | 18 ++++++++++++++++++ target/classes/Main.class | Bin 1162 -> 0 bytes 2 files changed, 18 insertions(+) delete mode 100644 target/classes/Main.class diff --git a/src/main/java/Item.java b/src/main/java/Item.java index 1c642c4..c3da449 100644 --- a/src/main/java/Item.java +++ b/src/main/java/Item.java @@ -28,7 +28,25 @@ public String getType() { public String getExpiration() { return expiration; } + public boolean isError(){ + return isError; + } //equals method + //toString method + + + @Override + public String toString() { + if(!isError) { + return "Item{" + + "name='" + name + '\'' + + ", price='" + price + '\'' + + ", type='" + type + '\'' + + ", expiration='" + expiration + '\'' + + '}'; + } + return "Erroneous entry"; + } public static class ItemBuilder{ private String name = ""; diff --git a/target/classes/Main.class b/target/classes/Main.class deleted file mode 100644 index c9d3858bc278f548c9eaabc471ed4e0ba034dcf0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1162 zcmZuwYg5xe6g^8z)288JOF>i=-z^{!-wHkuaK@P+4j?n?rzK=cm^A4msp7v@O^1Q2YPqK4I&NffQ%4yU9W$8KFsDOP z#~NhTCrGOes5g0FjJdJJ%lwp-67yBGD zRnUm*4W`n!f<|aNuUsWPr_{}>+y;g)Y~UX5Yj|MbAs$giTkm{)7;AWJ;0YErEE#wT zb~UZI2F6g*@Z7))ENggaU0y9bWVyv45TSeHPy>cp*{5b$3wTTZrUq)Th# zhC7r_ecm$6ZS-mzE`KGb6a1c*kM&Ej*d!>>v+q%*R3PzD?|6V z1+=;XdAu&Aewuc0nGeR``vOuBYW7@5xHD-5?cmH2#5ev7V3cd7eDG0;THnk}T882o|E`rKFglUTzojD{?~0&=aG(+RH~Gs_&~m|*Mz zIcG7+^&I(Wdd`z^0aNs-j2pBAw8dZ0-X9^`M9%sSeYS~wxA-LC5b{)6pd2M)JfYzt UE^(J Date: Mon, 13 Dec 2021 12:40:57 -0500 Subject: [PATCH 07/17] lunch commit --- src/main/java/Item.java | 4 ++-- src/main/java/Main.java | 3 +++ src/main/java/RegexThis.java | 20 ++++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/Item.java b/src/main/java/Item.java index c3da449..6c81d3b 100644 --- a/src/main/java/Item.java +++ b/src/main/java/Item.java @@ -43,9 +43,9 @@ public String toString() { ", price='" + price + '\'' + ", type='" + type + '\'' + ", expiration='" + expiration + '\'' + - '}'; + "}\n"; } - return "Erroneous entry"; + return "Erroneous entry\n"; } public static class ItemBuilder{ diff --git a/src/main/java/Main.java b/src/main/java/Main.java index cba5d1c..169b927 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -11,6 +11,9 @@ public String readRawDataToString() throws Exception{ public static void main(String[] args) throws Exception{ String output = (new Main()).readRawDataToString(); + System.out.println("Raw Data:"); System.out.println(output); + System.out.println("Regexed & Encapsulated"); + System.out.println(RegexThis.regexer(output)); } } diff --git a/src/main/java/RegexThis.java b/src/main/java/RegexThis.java index 0e70088..8aa9ae2 100644 --- a/src/main/java/RegexThis.java +++ b/src/main/java/RegexThis.java @@ -1,4 +1,3 @@ -import com.sun.media.sound.InvalidFormatException; import java.util.*; import java.util.regex.Matcher; @@ -12,7 +11,8 @@ public static List regexer(String raw){ Matcher m = p.matcher(raw); List items = new ArrayList(); while(m.find()){ - if(m.groupCount() != 4){ + if(m.groupCount() != 4 || ){ + System.out.println("OOF"); Item defect = new Item.ItemBuilder() .denoteError() .build(); @@ -20,14 +20,22 @@ public static List regexer(String raw){ } else{ Item newbie = new Item.ItemBuilder() - .setName(m.group(0)) - .setPrice(m.group(1)) - .setType(m.group(2)) - .setExpiration(m.group(3)) + .setName(m.group(1)) + .setPrice(m.group(2)) + .setType(m.group(3)) + .setExpiration(m.group(4)) .build(); items.add(newbie); } } + //TODO: + //take off the last entry as it is an empty string + //find a way to enforce error (maybe think about checking if any of the groups are null)(could be a one and done command for this) + //nicely formatted summary + + //MAYBE: + //replace inconsistent casing with regular casing + //fix regex to not include empty string return items; } } From c9cf8e738ccd86591a2fbb3e22e034ec76514cb9 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 13:12:09 -0500 Subject: [PATCH 08/17] regex no longer matches empty string --- src/main/java/RegexThis.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/RegexThis.java b/src/main/java/RegexThis.java index 8aa9ae2..ba6335f 100644 --- a/src/main/java/RegexThis.java +++ b/src/main/java/RegexThis.java @@ -6,7 +6,7 @@ public class RegexThis { //3 to 5 lines of regex public static List regexer(String raw){ - Pattern p = Pattern.compile("(?:##)?(?:name\\W)?([\\w]+)?(?:\\Wprice\\W)?([\\w\\.]+)?(?:\\Wtype\\W)?([\\w]+)?(?:\\Wexpiration\\W)?([\\w\\/]+)?" + Pattern p = Pattern.compile("(?:name\\W)?([\\w]+)?(?:\\Wprice\\W)?([\\w\\.]+)?(?:\\Wtype\\W)?([\\w]+)?(?:\\Wexpiration\\W)?([\\w\\/]+)?(?:##)" ,Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(raw); List items = new ArrayList(); @@ -35,7 +35,6 @@ public static List regexer(String raw){ //MAYBE: //replace inconsistent casing with regular casing - //fix regex to not include empty string return items; } } From 5df0628d1c087beac5a0fd4798fee982ba1f0f8a Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 13:19:24 -0500 Subject: [PATCH 09/17] enforced error checker for item class --- src/main/java/Item.java | 9 +++++++++ src/main/java/RegexThis.java | 4 +--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/Item.java b/src/main/java/Item.java index 6c81d3b..bef44f1 100644 --- a/src/main/java/Item.java +++ b/src/main/java/Item.java @@ -57,21 +57,25 @@ public static class ItemBuilder{ public ItemBuilder(){ } public ItemBuilder setName(String name) { + checkError(name); this.name = name; return this; } public ItemBuilder setPrice(String price) { + checkError(price); this.price = price; return this; } public ItemBuilder setType(String type) { + checkError(type); this.type = type; return this; } public ItemBuilder setExpiration(String expiration) { + checkError(expiration); this.expiration = expiration; return this; } @@ -79,6 +83,11 @@ public ItemBuilder denoteError(){ this.isError = true; return this; } + public void checkError(String input){ + if(input == null){ + this.isError = true; + } + } public String getName() { return name; diff --git a/src/main/java/RegexThis.java b/src/main/java/RegexThis.java index ba6335f..8828ea5 100644 --- a/src/main/java/RegexThis.java +++ b/src/main/java/RegexThis.java @@ -11,8 +11,7 @@ public static List regexer(String raw){ Matcher m = p.matcher(raw); List items = new ArrayList(); while(m.find()){ - if(m.groupCount() != 4 || ){ - System.out.println("OOF"); + if(m.groupCount() != 4){ Item defect = new Item.ItemBuilder() .denoteError() .build(); @@ -29,7 +28,6 @@ public static List regexer(String raw){ } } //TODO: - //take off the last entry as it is an empty string //find a way to enforce error (maybe think about checking if any of the groups are null)(could be a one and done command for this) //nicely formatted summary From a35fc3f505c3a07050c7fde0b1d3bb0fbecdf212 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 13:59:15 -0500 Subject: [PATCH 10/17] removed erroneous 0 and added colon --- src/main/java/Main.java | 2 +- src/main/java/RegexThis.java | 35 ++++++++++++++--------------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 169b927..edb1066 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -13,7 +13,7 @@ public static void main(String[] args) throws Exception{ String output = (new Main()).readRawDataToString(); System.out.println("Raw Data:"); System.out.println(output); - System.out.println("Regexed & Encapsulated"); + System.out.println("Regexed & Encapsulated:"); System.out.println(RegexThis.regexer(output)); } } diff --git a/src/main/java/RegexThis.java b/src/main/java/RegexThis.java index 8828ea5..b5b0a47 100644 --- a/src/main/java/RegexThis.java +++ b/src/main/java/RegexThis.java @@ -9,30 +9,23 @@ public static List regexer(String raw){ Pattern p = Pattern.compile("(?:name\\W)?([\\w]+)?(?:\\Wprice\\W)?([\\w\\.]+)?(?:\\Wtype\\W)?([\\w]+)?(?:\\Wexpiration\\W)?([\\w\\/]+)?(?:##)" ,Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(raw); + //matches gotten List items = new ArrayList(); + //encapsulate entries while(m.find()){ - if(m.groupCount() != 4){ - Item defect = new Item.ItemBuilder() - .denoteError() - .build(); - items.add(defect); - } - else{ - Item newbie = new Item.ItemBuilder() - .setName(m.group(1)) - .setPrice(m.group(2)) - .setType(m.group(3)) - .setExpiration(m.group(4)) - .build(); - items.add(newbie); - } + Item newbie = new Item.ItemBuilder() + .setName(m.group(1) != null ? (Pattern.compile("0")).matcher(m.group(1)).replaceAll("o") : null) + .setPrice(m.group(2)) + .setType(m.group(3)) + .setExpiration(m.group(4)) + .build(); + items.add(newbie); } - //TODO: - //find a way to enforce error (maybe think about checking if any of the groups are null)(could be a one and done command for this) - //nicely formatted summary - - //MAYBE: - //replace inconsistent casing with regular casing return items; } } +//TODO: +//nicely formatted summary +//give each group a fitting name +//replace inconsistent casing with regular casing + From 5909ca8e6aeed102377805eaaeb250f551705659 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 14:03:17 -0500 Subject: [PATCH 11/17] Named each capture group --- pom.xml | 4 ++-- src/main/java/Main.java | 5 +++-- src/main/java/RegexThis.java | 11 +++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 8d2631c..5ac4bdd 100644 --- a/pom.xml +++ b/pom.xml @@ -13,8 +13,8 @@ org.apache.maven.plugins maven-compiler-plugin - 6 - 6 + 7 + 7 diff --git a/src/main/java/Main.java b/src/main/java/Main.java index edb1066..395b4eb 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -12,8 +12,9 @@ public String readRawDataToString() throws Exception{ public static void main(String[] args) throws Exception{ String output = (new Main()).readRawDataToString(); System.out.println("Raw Data:"); - System.out.println(output); + System.out.println(output + "\n"); System.out.println("Regexed & Encapsulated:"); - System.out.println(RegexThis.regexer(output)); + System.out.println(RegexThis.regexer(output) + "\n"); + } } diff --git a/src/main/java/RegexThis.java b/src/main/java/RegexThis.java index b5b0a47..c1193f4 100644 --- a/src/main/java/RegexThis.java +++ b/src/main/java/RegexThis.java @@ -6,7 +6,7 @@ public class RegexThis { //3 to 5 lines of regex public static List regexer(String raw){ - Pattern p = Pattern.compile("(?:name\\W)?([\\w]+)?(?:\\Wprice\\W)?([\\w\\.]+)?(?:\\Wtype\\W)?([\\w]+)?(?:\\Wexpiration\\W)?([\\w\\/]+)?(?:##)" + Pattern p = Pattern.compile("(?:name\\W)?(?[\\w]+)?(?:\\Wprice\\W)?(?[\\w\\.]+)?(?:\\Wtype\\W)?(?[\\w]+)?(?:\\Wexpiration\\W)?(?[\\w\\/]+)?(?:##)" ,Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(raw); //matches gotten @@ -14,10 +14,10 @@ public static List regexer(String raw){ //encapsulate entries while(m.find()){ Item newbie = new Item.ItemBuilder() - .setName(m.group(1) != null ? (Pattern.compile("0")).matcher(m.group(1)).replaceAll("o") : null) - .setPrice(m.group(2)) - .setType(m.group(3)) - .setExpiration(m.group(4)) + .setName(m.group("NAME") != null ? (Pattern.compile("0")).matcher(m.group("NAME")).replaceAll("o") : null) + .setPrice(m.group("PRICE")) + .setType(m.group("TYPE")) + .setExpiration(m.group("EXPIRATION")) .build(); items.add(newbie); } @@ -26,6 +26,5 @@ public static List regexer(String raw){ } //TODO: //nicely formatted summary -//give each group a fitting name //replace inconsistent casing with regular casing From d503e81f22b9516c59cfcef0f71316772c0bd088 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 14:47:55 -0500 Subject: [PATCH 12/17] pretty summarization implemented --- pom.xml | 4 +-- src/main/java/Item.java | 1 + src/main/java/Summarization.java | 51 ++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/main/java/Summarization.java diff --git a/pom.xml b/pom.xml index 5ac4bdd..3c31de2 100644 --- a/pom.xml +++ b/pom.xml @@ -13,8 +13,8 @@ org.apache.maven.plugins maven-compiler-plugin - 7 - 7 + 8 + 8 diff --git a/src/main/java/Item.java b/src/main/java/Item.java index bef44f1..56df1a5 100644 --- a/src/main/java/Item.java +++ b/src/main/java/Item.java @@ -86,6 +86,7 @@ public ItemBuilder denoteError(){ public void checkError(String input){ if(input == null){ this.isError = true; + this.name = "error"; } } diff --git a/src/main/java/Summarization.java b/src/main/java/Summarization.java new file mode 100644 index 0000000..f96bc4d --- /dev/null +++ b/src/main/java/Summarization.java @@ -0,0 +1,51 @@ + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Summarization { + public static String Summarizer(List items){ + StringBuilder sb = new StringBuilder(); + Map> headcount = new HashMap<>(); + for(Item item: items){ + //make this non case-sensitive + if(!headcount.containsKey(item.getName())){ + headcount.put(item.getName(),(new HashMap())); + headcount.get(item.getName()).put(item.getPrice(),1); + } + else{ + if(headcount.get(item.getName()).containsKey(item.getPrice())){ + headcount.get(item.getName()).put(item.getPrice(),1); + } + else{ + headcount.get(item.getName()).replace(item.getPrice(), + headcount.get(item.getName()).get(item.getPrice())+ 1); + } + } + } + int errorCount = 0; + for(String name: headcount.keySet()){ + //error if + if(name.equals("error")){ + for(String price: headcount.get("error").keySet()){ + errorCount++; + //can prob just get size + } + } + else{ + int total = 0; + for(String price: headcount.get(name).keySet()){ + total+=headcount.get(name).get(price); + } + sb.append(String.format("name:%4s%9s%s times\n",name,"seen: ",total)); + sb.append("============= \t \t =============\n"); + for(String price: headcount.get(name).keySet()){ + sb.append(String.format("Price:%4s%9s%s times\n",price,"seen: ",headcount.get(name).get(price))); + sb.append("-------------\t\t -------------\n"); + } + sb.append("\n"); + } + } + return sb.toString(); + } +} From 20ec22aa5979e145dbe5bb5e4570195332f79783 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 15:18:13 -0500 Subject: [PATCH 13/17] bettered summary --- src/main/java/Item.java | 1 - src/main/java/Main.java | 6 +++++- src/main/java/Summarization.java | 27 +++++++++++++++------------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/Item.java b/src/main/java/Item.java index 56df1a5..bef44f1 100644 --- a/src/main/java/Item.java +++ b/src/main/java/Item.java @@ -86,7 +86,6 @@ public ItemBuilder denoteError(){ public void checkError(String input){ if(input == null){ this.isError = true; - this.name = "error"; } } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 395b4eb..447d01c 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,5 +1,6 @@ import org.apache.commons.io.IOUtils; import java.io.IOException; +import java.util.List; public class Main { @@ -14,7 +15,10 @@ public static void main(String[] args) throws Exception{ System.out.println("Raw Data:"); System.out.println(output + "\n"); System.out.println("Regexed & Encapsulated:"); - System.out.println(RegexThis.regexer(output) + "\n"); + List items = RegexThis.regexer(output); + System.out.println(items + "\n"); + System.out.println("Summarization: "); + System.out.println(Summarization.summarize(items)); } } diff --git a/src/main/java/Summarization.java b/src/main/java/Summarization.java index f96bc4d..0ab4b9c 100644 --- a/src/main/java/Summarization.java +++ b/src/main/java/Summarization.java @@ -4,48 +4,51 @@ import java.util.Map; public class Summarization { - public static String Summarizer(List items){ + public static String summarize(List items){ StringBuilder sb = new StringBuilder(); Map> headcount = new HashMap<>(); for(Item item: items){ //make this non case-sensitive if(!headcount.containsKey(item.getName())){ headcount.put(item.getName(),(new HashMap())); - headcount.get(item.getName()).put(item.getPrice(),1); + if(item.getName() == null){ + headcount.get(item.getName()).put("-1",1); + } + else{ + headcount.get(item.getName()).put(item.getPrice(),1); + } } else{ - if(headcount.get(item.getName()).containsKey(item.getPrice())){ + if(!headcount.get(item.getName()).containsKey(item.getPrice())){ headcount.get(item.getName()).put(item.getPrice(),1); } else{ - headcount.get(item.getName()).replace(item.getPrice(), - headcount.get(item.getName()).get(item.getPrice())+ 1); + Integer temp = headcount.get(item.getName()).get(item.getPrice()); + headcount.get(item.getName()).replace(item.getPrice(),temp + 1); } } } int errorCount = 0; for(String name: headcount.keySet()){ //error if - if(name.equals("error")){ - for(String price: headcount.get("error").keySet()){ - errorCount++; - //can prob just get size - } + if(name == null){ + errorCount = headcount.get(null).get("-1"); } else{ int total = 0; for(String price: headcount.get(name).keySet()){ total+=headcount.get(name).get(price); } - sb.append(String.format("name:%4s%9s%s times\n",name,"seen: ",total)); + sb.append(String.format("name:%4s \t \t seen: %s times\n",name,total)); sb.append("============= \t \t =============\n"); for(String price: headcount.get(name).keySet()){ - sb.append(String.format("Price:%4s%9s%s times\n",price,"seen: ",headcount.get(name).get(price))); + sb.append(String.format("Price:%4s \t \t seen: %s times\n",price,headcount.get(name).get(price))); sb.append("-------------\t\t -------------\n"); } sb.append("\n"); } } + sb.append(String.format("Errors \t \t seen: %s times",errorCount)); return sb.toString(); } } From 73fd857e1bfe3e6603f04576b1bf5fef74d9b0fa Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 15:48:36 -0500 Subject: [PATCH 14/17] finished case regulation --- src/main/java/Item.java | 14 ++++++++------ src/main/java/Main.java | 3 ++- src/main/java/RegexThis.java | 23 ++++++++++++++++++++++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/java/Item.java b/src/main/java/Item.java index bef44f1..4b0a320 100644 --- a/src/main/java/Item.java +++ b/src/main/java/Item.java @@ -1,5 +1,5 @@ public class Item { - private final String name; + private String name; private final String price; private final String type; private final String expiration; @@ -12,7 +12,9 @@ public Item(ItemBuilder builder) { this.expiration = builder.getExpiration(); this.isError = builder.getIsError(); } - + public void setName(String newName){ + this.name = newName; + } public String getName() { return name; } @@ -49,10 +51,10 @@ public String toString() { } public static class ItemBuilder{ - private String name = ""; - private String price = ""; - private String type = ""; - private String expiration = ""; + private String name; + private String price; + private String type; + private String expiration; private boolean isError = false; public ItemBuilder(){ } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 447d01c..4255c20 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -17,8 +17,9 @@ public static void main(String[] args) throws Exception{ System.out.println("Regexed & Encapsulated:"); List items = RegexThis.regexer(output); System.out.println(items + "\n"); + List beautifiedItems = RegexThis.beautifier(items); System.out.println("Summarization: "); - System.out.println(Summarization.summarize(items)); + System.out.println(Summarization.summarize(beautifiedItems)); } } diff --git a/src/main/java/RegexThis.java b/src/main/java/RegexThis.java index c1193f4..7a848e6 100644 --- a/src/main/java/RegexThis.java +++ b/src/main/java/RegexThis.java @@ -23,8 +23,29 @@ public static List regexer(String raw){ } return items; } + public static List beautifier(List raw){ + for(Item item: raw){ + String a = item.getName(); + if(a != null) { + Matcher cookie = Pattern.compile("cookies", Pattern.CASE_INSENSITIVE).matcher(a); + Matcher milk = Pattern.compile("milk", Pattern.CASE_INSENSITIVE).matcher(a); + Matcher bread = Pattern.compile("bread", Pattern.CASE_INSENSITIVE).matcher(a); + Matcher apples = Pattern.compile("apples", Pattern.CASE_INSENSITIVE).matcher(a); + if (cookie.matches()) { + item.setName("COOKIES"); + } else if (milk.matches()) { + item.setName("MILK"); + } else if (bread.matches()) { + item.setName("BREAD"); + } else if (apples.matches()) { + item.setName("APPLES"); + } + } + } + return raw; + } } //TODO: -//nicely formatted summary +//nicely formatted summary(kind of) //replace inconsistent casing with regular casing From 6b2c8b34360a1fd1241142650c02e051de297084 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 15:56:36 -0500 Subject: [PATCH 15/17] final commit --- src/main/java/Item.java | 1 + src/main/java/Summarization.java | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/Item.java b/src/main/java/Item.java index 4b0a320..5370c47 100644 --- a/src/main/java/Item.java +++ b/src/main/java/Item.java @@ -88,6 +88,7 @@ public ItemBuilder denoteError(){ public void checkError(String input){ if(input == null){ this.isError = true; + this.name = "error"; } } diff --git a/src/main/java/Summarization.java b/src/main/java/Summarization.java index 0ab4b9c..f3deda7 100644 --- a/src/main/java/Summarization.java +++ b/src/main/java/Summarization.java @@ -8,11 +8,10 @@ public static String summarize(List items){ StringBuilder sb = new StringBuilder(); Map> headcount = new HashMap<>(); for(Item item: items){ - //make this non case-sensitive if(!headcount.containsKey(item.getName())){ - headcount.put(item.getName(),(new HashMap())); - if(item.getName() == null){ - headcount.get(item.getName()).put("-1",1); + headcount.put(item.getName(),(new HashMap<>())); + if(item.getName() == null || item.getPrice() == null){ + headcount.get(null).put("-1",1); } else{ headcount.get(item.getName()).put(item.getPrice(),1); @@ -22,6 +21,10 @@ public static String summarize(List items){ if(!headcount.get(item.getName()).containsKey(item.getPrice())){ headcount.get(item.getName()).put(item.getPrice(),1); } + else if(item.getPrice() == null){ + Integer temp = headcount.get(null).get(item.getPrice()); + headcount.get("error").replace("-1",temp + 1); + } else{ Integer temp = headcount.get(item.getName()).get(item.getPrice()); headcount.get(item.getName()).replace(item.getPrice(),temp + 1); From f37cee4f74ecf70c3465857dfef9efb57bb2cad6 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 15:58:22 -0500 Subject: [PATCH 16/17] actual final commit --- src/main/java/Summarization.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/Summarization.java b/src/main/java/Summarization.java index f3deda7..0e4eddc 100644 --- a/src/main/java/Summarization.java +++ b/src/main/java/Summarization.java @@ -34,8 +34,8 @@ else if(item.getPrice() == null){ int errorCount = 0; for(String name: headcount.keySet()){ //error if - if(name == null){ - errorCount = headcount.get(null).get("-1"); + if(name == null || name.equals("error")){ + errorCount++; } else{ int total = 0; From e5408cc5365a32a5398b09ff4a0cd353d1f2efb4 Mon Sep 17 00:00:00 2001 From: Quatrani Paul Date: Mon, 13 Dec 2021 16:39:59 -0500 Subject: [PATCH 17/17] error count is now accurate --- src/main/java/Summarization.java | 43 ++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/main/java/Summarization.java b/src/main/java/Summarization.java index 0e4eddc..5235b52 100644 --- a/src/main/java/Summarization.java +++ b/src/main/java/Summarization.java @@ -7,12 +7,19 @@ public class Summarization { public static String summarize(List items){ StringBuilder sb = new StringBuilder(); Map> headcount = new HashMap<>(); + int errorCount = 0; for(Item item: items){ - if(!headcount.containsKey(item.getName())){ + if(item.isError()){ + errorCount++; + } + else if(!headcount.containsKey(item.getName())){ headcount.put(item.getName(),(new HashMap<>())); - if(item.getName() == null || item.getPrice() == null){ + if(item.getName() == null){ headcount.get(null).put("-1",1); } + else if(item.getPrice() == null){ + headcount.get("error").put("-1",1); + } else{ headcount.get(item.getName()).put(item.getPrice(),1); } @@ -21,8 +28,13 @@ public static String summarize(List items){ if(!headcount.get(item.getName()).containsKey(item.getPrice())){ headcount.get(item.getName()).put(item.getPrice(),1); } + else if(item.getName() == null){ + Integer temp = headcount.get(null).get("-1"); + headcount.get(null).put("-1",temp + 1); + + } else if(item.getPrice() == null){ - Integer temp = headcount.get(null).get(item.getPrice()); + Integer temp = headcount.get("error").get("-1"); headcount.get("error").replace("-1",temp + 1); } else{ @@ -31,25 +43,18 @@ else if(item.getPrice() == null){ } } } - int errorCount = 0; for(String name: headcount.keySet()){ - //error if - if(name == null || name.equals("error")){ - errorCount++; + int total = 0; + for(String price: headcount.get(name).keySet()){ + total+=headcount.get(name).get(price); } - else{ - int total = 0; - for(String price: headcount.get(name).keySet()){ - total+=headcount.get(name).get(price); - } - sb.append(String.format("name:%4s \t \t seen: %s times\n",name,total)); - sb.append("============= \t \t =============\n"); - for(String price: headcount.get(name).keySet()){ - sb.append(String.format("Price:%4s \t \t seen: %s times\n",price,headcount.get(name).get(price))); - sb.append("-------------\t\t -------------\n"); - } - sb.append("\n"); + sb.append(String.format("name:%4s \t \t seen: %s times\n",name,total)); + sb.append("============= \t \t =============\n"); + for(String price: headcount.get(name).keySet()){ + sb.append(String.format("Price:%4s \t \t seen: %s times\n",price,headcount.get(name).get(price))); + sb.append("-------------\t\t -------------\n"); } + sb.append("\n"); } sb.append(String.format("Errors \t \t seen: %s times",errorCount)); return sb.toString();