From 84444ac9ca22d285c332ee0ec420fd8157d27008 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Tue, 3 Mar 2020 12:11:55 +0800 Subject: [PATCH 001/435] Set theme jekyll-theme-cayman --- docs/_config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/_config.yml diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 000000000..c4192631f --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman \ No newline at end of file From 11dcfa15b9c3f21dc243f4abd7d312fa28c4e45e Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Tue, 3 Mar 2020 12:13:34 +0800 Subject: [PATCH 002/435] Set theme jekyll-theme-minimal --- docs/_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_config.yml b/docs/_config.yml index c4192631f..2f7efbeab 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-cayman \ No newline at end of file +theme: jekyll-theme-minimal \ No newline at end of file From 6c61e6130f162f519bcb74fca6aa161bf2f912ee Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Tue, 3 Mar 2020 12:51:24 +0800 Subject: [PATCH 003/435] Add personal data --- docs/AboutUs.md | 2 +- docs/team/ganapathysanathbalaji.md | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 docs/team/ganapathysanathbalaji.md diff --git a/docs/AboutUs.md b/docs/AboutUs.md index 0f072953e..a8ef6c8af 100644 --- a/docs/AboutUs.md +++ b/docs/AboutUs.md @@ -3,7 +3,7 @@ Display | Name | Github Profile | Portfolio --------|:----:|:--------------:|:---------: ![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) -![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Ganapathy Sanath Balaji | [Github](https://github.com/GanapathySanathBalaji) | [Portfolio](docs/team/ganapathysanathbalaji.md) ![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) diff --git a/docs/team/ganapathysanathbalaji.md b/docs/team/ganapathysanathbalaji.md new file mode 100644 index 000000000..e69de29bb From e3cd3da02805dd201389b841e6a5980f97ebcec2 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Tue, 3 Mar 2020 12:52:24 +0800 Subject: [PATCH 004/435] teryTay-AboutUs --- docs/AboutUs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/AboutUs.md b/docs/AboutUs.md index 0f072953e..a51275bb7 100644 --- a/docs/AboutUs.md +++ b/docs/AboutUs.md @@ -2,7 +2,7 @@ Display | Name | Github Profile | Portfolio --------|:----:|:--------------:|:---------: -![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://avatars2.githubusercontent.com/u/59829631?s=460&v=4?text=terry) | Terry Tay | [Github](https://github.com/terrytay) | [Portfolio](docs/team/terrytay.md) ![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) From d62daf7d889970b33b87ea153c9f887fc9d007cc Mon Sep 17 00:00:00 2001 From: hongquan448 Date: Tue, 3 Mar 2020 12:57:43 +0800 Subject: [PATCH 005/435] edit AboutUs --- docs/AboutUs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/AboutUs.md b/docs/AboutUs.md index 0f072953e..a2e3bb24f 100644 --- a/docs/AboutUs.md +++ b/docs/AboutUs.md @@ -6,4 +6,4 @@ Display | Name | Github Profile | Portfolio ![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) -![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Hong Quan | [Github](https://github.com/hongquan448) | [Portfolio](docs/team/hongquan.md) From 0290abf0752e9695238d7bc418e1b698e077bfe8 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Tue, 3 Mar 2020 13:05:21 +0800 Subject: [PATCH 006/435] Change to NizarMohd.md --- docs/AboutUs.md | 9 --------- docs/NizarMohd.md | 5 +++++ docs/README.md | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) delete mode 100644 docs/AboutUs.md create mode 100644 docs/NizarMohd.md diff --git a/docs/AboutUs.md b/docs/AboutUs.md deleted file mode 100644 index 0f072953e..000000000 --- a/docs/AboutUs.md +++ /dev/null @@ -1,9 +0,0 @@ -# About us - -Display | Name | Github Profile | Portfolio ---------|:----:|:--------------:|:---------: -![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) -![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) -![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) -![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) -![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) diff --git a/docs/NizarMohd.md b/docs/NizarMohd.md new file mode 100644 index 000000000..28bdba1bf --- /dev/null +++ b/docs/NizarMohd.md @@ -0,0 +1,5 @@ +# About us + +Display | Name | Github Profile | Portfolio +--------|:----:|:--------------:|:---------: +![](https://via.placeholder.com/100.png?text=Photo) | Nizar Mohamed | [Github](https://github.com/NizarMohd) | [Portfolio](docs/team/NizarMohd.md) diff --git a/docs/README.md b/docs/README.md index 5fda977aa..cf52f7e66 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,4 +5,4 @@ Useful links: * [User Guide](UserGuide.md) * [Developer Guide](UserGuide.md) -* [About Us](AboutUs.md) +* [About Us](NizarMohd.md) From a2e922adee5b5755a21e5d61eab84ca2b925ecf1 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Tue, 3 Mar 2020 13:09:49 +0800 Subject: [PATCH 007/435] Revert "Change to NizarMohd.md" This reverts commit 0290abf0752e9695238d7bc418e1b698e077bfe8. --- docs/AboutUs.md | 9 +++++++++ docs/NizarMohd.md | 5 ----- docs/README.md | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 docs/AboutUs.md delete mode 100644 docs/NizarMohd.md diff --git a/docs/AboutUs.md b/docs/AboutUs.md new file mode 100644 index 000000000..0f072953e --- /dev/null +++ b/docs/AboutUs.md @@ -0,0 +1,9 @@ +# About us + +Display | Name | Github Profile | Portfolio +--------|:----:|:--------------:|:---------: +![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) diff --git a/docs/NizarMohd.md b/docs/NizarMohd.md deleted file mode 100644 index 28bdba1bf..000000000 --- a/docs/NizarMohd.md +++ /dev/null @@ -1,5 +0,0 @@ -# About us - -Display | Name | Github Profile | Portfolio ---------|:----:|:--------------:|:---------: -![](https://via.placeholder.com/100.png?text=Photo) | Nizar Mohamed | [Github](https://github.com/NizarMohd) | [Portfolio](docs/team/NizarMohd.md) diff --git a/docs/README.md b/docs/README.md index cf52f7e66..5fda977aa 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,4 +5,4 @@ Useful links: * [User Guide](UserGuide.md) * [Developer Guide](UserGuide.md) -* [About Us](NizarMohd.md) +* [About Us](AboutUs.md) From 1507bfeb277fc99780df56faf2a10a4d600f6af2 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Tue, 3 Mar 2020 13:15:30 +0800 Subject: [PATCH 008/435] Change AboutUs --- docs/AboutUs.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/AboutUs.md b/docs/AboutUs.md index 0f072953e..898cc841b 100644 --- a/docs/AboutUs.md +++ b/docs/AboutUs.md @@ -2,8 +2,5 @@ Display | Name | Github Profile | Portfolio --------|:----:|:--------------:|:---------: -![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) -![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) -![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) -![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) -![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Nizar Mohamed| [Github](https://github.com/NizarMohd) | [Portfolio](docs/team/NizarMohd.md) +! \ No newline at end of file From f58886dbaa3db1269acd8a481a88bca6eb763cf1 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 5 Mar 2020 21:57:12 +0800 Subject: [PATCH 009/435] remove duke class --- src/main/java/seedu/duke/Duke.java | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/main/java/seedu/duke/Duke.java diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java deleted file mode 100644 index 5c74e68d5..000000000 --- a/src/main/java/seedu/duke/Duke.java +++ /dev/null @@ -1,21 +0,0 @@ -package seedu.duke; - -import java.util.Scanner; - -public class Duke { - /** - * Main entry-point for the java.duke.Duke application. - */ - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - System.out.println("What is your name?"); - - Scanner in = new Scanner(System.in); - System.out.println("Hello " + in.nextLine()); - } -} From 54e56dc7f6ea57737faf455bc35d6f93051a2919 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 5 Mar 2020 22:01:50 +0800 Subject: [PATCH 010/435] deleted duketest class --- src/test/java/seedu/duke/DukeTest.java | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 src/test/java/seedu/duke/DukeTest.java diff --git a/src/test/java/seedu/duke/DukeTest.java b/src/test/java/seedu/duke/DukeTest.java deleted file mode 100644 index 495ab98a3..000000000 --- a/src/test/java/seedu/duke/DukeTest.java +++ /dev/null @@ -1,12 +0,0 @@ -package seedu.duke; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -class DukeTest { - @Test - public void sampleTest() { - assertTrue(true); - } -} \ No newline at end of file From 0adb05820905598fa4db55bfd71ba6fbcd3d2091 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 5 Mar 2020 22:22:52 +0800 Subject: [PATCH 011/435] Add Location class and LocationTest --- src/main/java/Location.java | 2 ++ src/test/java/LocationTest.java | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 src/main/java/Location.java create mode 100644 src/test/java/LocationTest.java diff --git a/src/main/java/Location.java b/src/main/java/Location.java new file mode 100644 index 000000000..11311f127 --- /dev/null +++ b/src/main/java/Location.java @@ -0,0 +1,2 @@ +public class Location { +} diff --git a/src/test/java/LocationTest.java b/src/test/java/LocationTest.java new file mode 100644 index 000000000..6296cfb15 --- /dev/null +++ b/src/test/java/LocationTest.java @@ -0,0 +1,5 @@ +import static org.junit.jupiter.api.Assertions.*; + +class LocationTest { + +} \ No newline at end of file From 0d887eed68d4ac828bd0afabb15c548cffbdfccf Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 5 Mar 2020 22:24:05 +0800 Subject: [PATCH 012/435] Add Location class and LocationTest --- src/main/java/Location.java | 39 +++++++++++++++++++++++++++++++++ src/test/java/LocationTest.java | 34 ++++++++++++++++++++++++++++ text-ui-test/ACTUAL.TXT | 9 ++++++++ 3 files changed, 82 insertions(+) create mode 100644 text-ui-test/ACTUAL.TXT diff --git a/src/main/java/Location.java b/src/main/java/Location.java index 11311f127..33712eed5 100644 --- a/src/main/java/Location.java +++ b/src/main/java/Location.java @@ -1,2 +1,41 @@ public class Location { + private String name; + private String address; + private String faculty; + private boolean hasPort; + private boolean isIndoor; + private int maxPax; + + public Location(String name, String address, String faculty, boolean hasPort, boolean isIndoor, int maxPax) { + this.name = name; + this.address = address; + this.faculty = faculty; + this.hasPort = hasPort; + this.isIndoor = isIndoor; + this.maxPax = maxPax; + } + + public String getName() { + return name; + } + + public String getAddress() { + return address; + } + + public String getFaculty() { + return faculty; + } + + public boolean hasPort() { + return hasPort; + } + + public boolean isIndoor() { + return isIndoor; + } + + public int getMaxPax() { + return maxPax; + } } diff --git a/src/test/java/LocationTest.java b/src/test/java/LocationTest.java index 6296cfb15..36627106f 100644 --- a/src/test/java/LocationTest.java +++ b/src/test/java/LocationTest.java @@ -1,5 +1,39 @@ +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.*; class LocationTest { + Location location1 = new Location("mac commons", "utown", "nil", true, true, 5); + + @Test + void getName() { + assertEquals("mac commons", location1.getName()); + } + + @Test + void getAddress() { + assertEquals("utown", location1.getAddress()); + } + + @Test + void getFaculty() { + assertEquals("nil", location1.getFaculty()); + } + + @Test + void hasPort() { + assertEquals(true, location1.hasPort()); + } + + @Test + void isIndoor() { + assertEquals(true, location1.isIndoor()); + } + + @Test + void getMaxPax() { + assertEquals(5, location1.getMaxPax()); + } } \ No newline at end of file diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT new file mode 100644 index 000000000..892cb6cae --- /dev/null +++ b/text-ui-test/ACTUAL.TXT @@ -0,0 +1,9 @@ +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + +What is your name? +Hello James Gosling From 8c22b2630523490126a7d1ba35ff6021754a0bae Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 5 Mar 2020 22:45:52 +0800 Subject: [PATCH 013/435] Add javadoc to Location and LocationTest --- src/main/java/Location.java | 32 +++++++++++++++++++++++++------- src/test/java/LocationTest.java | 5 ++++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/java/Location.java b/src/main/java/Location.java index 33712eed5..5250ea9b5 100644 --- a/src/main/java/Location.java +++ b/src/main/java/Location.java @@ -6,13 +6,31 @@ public class Location { private boolean isIndoor; private int maxPax; - public Location(String name, String address, String faculty, boolean hasPort, boolean isIndoor, int maxPax) { - this.name = name; - this.address = address; - this.faculty = faculty; - this.hasPort = hasPort; - this.isIndoor = isIndoor; - this.maxPax = maxPax; + /** + * Constructs a Location class for a study area location with its information + * Precondition: 'All variables have to be filled. + * + * @param name name of study location + * @param address address of study location + * @param faculty faculty of study location + * @param hasPort true for availability of ports, else false + * @param isIndoor true for indoor, else false + * @param maxPax maximum number of seats for this study area + * + * @throws Exception when not all variables are filled + */ + public Location(String name, String address, String faculty, boolean hasPort, + boolean isIndoor, int maxPax) throws Exception { + try { + this.name = name; + this.address = address; + this.faculty = faculty; + this.hasPort = hasPort; + this.isIndoor = isIndoor; + this.maxPax = maxPax; + } catch (Exception e) { + System.out.println(e.getMessage()); + } } public String getName() { diff --git a/src/test/java/LocationTest.java b/src/test/java/LocationTest.java index 36627106f..f36bef096 100644 --- a/src/test/java/LocationTest.java +++ b/src/test/java/LocationTest.java @@ -1,12 +1,15 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; class LocationTest { Location location1 = new Location("mac commons", "utown", "nil", true, true, 5); + LocationTest() throws Exception { + } + @Test void getName() { assertEquals("mac commons", location1.getName()); From 238680a90a6bea64a9058b9a62430e6cef352cd2 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Fri, 6 Mar 2020 01:29:29 +0800 Subject: [PATCH 014/435] Add back seedu --- src/main/java/seedu/duke/Duke.java | 21 +++++++++++++++++++++ src/test/java/seedu/duke/DukeTest.java | 12 ++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/main/java/seedu/duke/Duke.java create mode 100644 src/test/java/seedu/duke/DukeTest.java diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java new file mode 100644 index 000000000..5c74e68d5 --- /dev/null +++ b/src/main/java/seedu/duke/Duke.java @@ -0,0 +1,21 @@ +package seedu.duke; + +import java.util.Scanner; + +public class Duke { + /** + * Main entry-point for the java.duke.Duke application. + */ + public static void main(String[] args) { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); + System.out.println("What is your name?"); + + Scanner in = new Scanner(System.in); + System.out.println("Hello " + in.nextLine()); + } +} diff --git a/src/test/java/seedu/duke/DukeTest.java b/src/test/java/seedu/duke/DukeTest.java new file mode 100644 index 000000000..495ab98a3 --- /dev/null +++ b/src/test/java/seedu/duke/DukeTest.java @@ -0,0 +1,12 @@ +package seedu.duke; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +class DukeTest { + @Test + public void sampleTest() { + assertTrue(true); + } +} \ No newline at end of file From 3e1d1e387404c9b331f2a4e8fd6bbae11c4531a5 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Fri, 6 Mar 2020 11:36:03 +0800 Subject: [PATCH 015/435] Add resourceloader without javadoc yet --- library/locations.txt | 0 src/main/java/resourceloader/Loader.java | 4 ++++ src/main/java/resourceloader/LocationLoader.java | 4 ++++ src/test/java/resourceloader/LocationLoaderTest.java | 5 +++++ 4 files changed, 13 insertions(+) create mode 100644 library/locations.txt create mode 100644 src/main/java/resourceloader/Loader.java create mode 100644 src/main/java/resourceloader/LocationLoader.java create mode 100644 src/test/java/resourceloader/LocationLoaderTest.java diff --git a/library/locations.txt b/library/locations.txt new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/java/resourceloader/Loader.java b/src/main/java/resourceloader/Loader.java new file mode 100644 index 000000000..82a35c160 --- /dev/null +++ b/src/main/java/resourceloader/Loader.java @@ -0,0 +1,4 @@ +package resourceloader; + +public class Loader { +} diff --git a/src/main/java/resourceloader/LocationLoader.java b/src/main/java/resourceloader/LocationLoader.java new file mode 100644 index 000000000..31a8312b8 --- /dev/null +++ b/src/main/java/resourceloader/LocationLoader.java @@ -0,0 +1,4 @@ +package resourceloader; + +public class LocationLoader { +} diff --git a/src/test/java/resourceloader/LocationLoaderTest.java b/src/test/java/resourceloader/LocationLoaderTest.java new file mode 100644 index 000000000..3cb2e338f --- /dev/null +++ b/src/test/java/resourceloader/LocationLoaderTest.java @@ -0,0 +1,5 @@ +import static org.junit.jupiter.api.Assertions.*; + +class LocationLoaderTest { + +} \ No newline at end of file From 4f0bce39fecef4a794f9212d352fdecf10a95bad Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Fri, 6 Mar 2020 11:38:10 +0800 Subject: [PATCH 016/435] Javadoc not added for resourceloader yet --- library/locations.txt | 1 + src/main/java/resourceloader/Loader.java | 15 ++++++++++- .../java/resourceloader/LocationLoader.java | 25 +++++++++++++++++-- .../resourceloader/LocationLoaderTest.java | 15 ++++++++++- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/library/locations.txt b/library/locations.txt index e69de29bb..9a2c7732f 100644 --- a/library/locations.txt +++ b/library/locations.txt @@ -0,0 +1 @@ +testing \ No newline at end of file diff --git a/src/main/java/resourceloader/Loader.java b/src/main/java/resourceloader/Loader.java index 82a35c160..74be1aec7 100644 --- a/src/main/java/resourceloader/Loader.java +++ b/src/main/java/resourceloader/Loader.java @@ -1,4 +1,17 @@ package resourceloader; -public class Loader { +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +/** + * Loader is a resource loader for all the external data that is within our java program. + * Examples of resources will be task data, study locations etc.. + * Loader is an interface that enables subsequent loaders to be made and disciplined, + * i.e. locationsLoader, organiserLoader.. + */ +public interface Loader { + public void loadFile() throws FileNotFoundException; + + public File getFile(); } diff --git a/src/main/java/resourceloader/LocationLoader.java b/src/main/java/resourceloader/LocationLoader.java index 31a8312b8..c8c543ae4 100644 --- a/src/main/java/resourceloader/LocationLoader.java +++ b/src/main/java/resourceloader/LocationLoader.java @@ -1,4 +1,25 @@ package resourceloader; -public class LocationLoader { -} +import java.io.File; +import java.io.FileNotFoundException; + +public class LocationLoader implements Loader { + private final String url; + private File file; + + public LocationLoader(String url) { + this.url = url; + } + + public void loadFile() throws FileNotFoundException { + try { + file = new File(url); + } catch (Exception e) { + throw new FileNotFoundException("File not found."); + } + } + + public File getFile() { + return this.file; + } +} \ No newline at end of file diff --git a/src/test/java/resourceloader/LocationLoaderTest.java b/src/test/java/resourceloader/LocationLoaderTest.java index 3cb2e338f..d8c13decf 100644 --- a/src/test/java/resourceloader/LocationLoaderTest.java +++ b/src/test/java/resourceloader/LocationLoaderTest.java @@ -1,5 +1,18 @@ -import static org.junit.jupiter.api.Assertions.*; +package resourceloader; + +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.FileNotFoundException; + +import static org.junit.jupiter.api.Assertions.assertEquals; class LocationLoaderTest { + LocationLoader locationLoader = new LocationLoader("library/locations.txt"); + @Test + void loadFile() throws FileNotFoundException { + locationLoader.loadFile(); + assertEquals(new File("library/locations.txt"), locationLoader.getFile()); + } } \ No newline at end of file From c0f2412e0791bfac1c1e543fc40bff37fb53f67a Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Fri, 6 Mar 2020 19:11:34 +0800 Subject: [PATCH 017/435] Link up LocationLoader, Location, StudyArea Class --- library/locations.txt | 3 +- .../java/resourceloader/LocationLoader.java | 31 ++++++++++++++++++- src/main/java/seedu/duke/Duke.java | 7 ++++- src/main/java/{ => studyarea}/Location.java | 2 ++ src/main/java/studyarea/StudyArea.java | 27 ++++++++++++++++ .../resourceloader/LocationLoaderTest.java | 6 +++- .../java/{ => studyarea}/LocationTest.java | 4 ++- src/test/java/studyarea/StudyAreaTest.java | 19 ++++++++++++ 8 files changed, 94 insertions(+), 5 deletions(-) rename src/main/java/{ => studyarea}/Location.java (98%) create mode 100644 src/main/java/studyarea/StudyArea.java rename src/test/java/{ => studyarea}/LocationTest.java (94%) create mode 100644 src/test/java/studyarea/StudyAreaTest.java diff --git a/library/locations.txt b/library/locations.txt index 9a2c7732f..d70644e90 100644 --- a/library/locations.txt +++ b/library/locations.txt @@ -1 +1,2 @@ -testing \ No newline at end of file +MacCommons 2 College Ave West Education Resource Centre - true true 5 +OCBC 2 College Ave West, Stephen Riady Centre - true false 2 \ No newline at end of file diff --git a/src/main/java/resourceloader/LocationLoader.java b/src/main/java/resourceloader/LocationLoader.java index c8c543ae4..adacd5436 100644 --- a/src/main/java/resourceloader/LocationLoader.java +++ b/src/main/java/resourceloader/LocationLoader.java @@ -1,16 +1,23 @@ package resourceloader; +import studyarea.Location; + import java.io.File; import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; public class LocationLoader implements Loader { + private static final String DIVIDER = " "; private final String url; private File file; - public LocationLoader(String url) { + public LocationLoader(String url) throws FileNotFoundException { this.url = url; + loadFile(); } + @Override public void loadFile() throws FileNotFoundException { try { file = new File(url); @@ -19,7 +26,29 @@ public void loadFile() throws FileNotFoundException { } } + @Override public File getFile() { return this.file; } + + /** + * Return the imported study area file as an ArrayList for the main controller + * to add it to its database. + * + * @return buffer ArrayList of Location from study area file + * @throws Exception to be edited + */ + public ArrayList pushToDatabase() throws Exception { + ArrayList buffer = new ArrayList<>(); + Scanner input = new Scanner(file); + while (input.hasNextLine()) { + String detailsOfLocation = input.nextLine(); + String[] detailsBuffer = detailsOfLocation.split(DIVIDER); + Location location = new Location(detailsBuffer[0], detailsBuffer[1], detailsBuffer[2], + Boolean.parseBoolean(detailsBuffer[3]), Boolean.parseBoolean(detailsBuffer[4]), + Integer.parseInt(detailsBuffer[5])); + buffer.add(location); + } + return buffer; + } } \ No newline at end of file diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 5c74e68d5..c9cb023c9 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,12 +1,14 @@ package seedu.duke; +import studyarea.StudyArea; + import java.util.Scanner; public class Duke { /** * Main entry-point for the java.duke.Duke application. */ - public static void main(String[] args) { + public static void main(String[] args) throws Exception { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" @@ -17,5 +19,8 @@ public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Hello " + in.nextLine()); + StudyArea studyArea = new StudyArea(); + String output = studyArea.getLocationsList().get(1).getAddress(); + System.out.println(output); } } diff --git a/src/main/java/Location.java b/src/main/java/studyarea/Location.java similarity index 98% rename from src/main/java/Location.java rename to src/main/java/studyarea/Location.java index 5250ea9b5..bfbd5b1ae 100644 --- a/src/main/java/Location.java +++ b/src/main/java/studyarea/Location.java @@ -1,3 +1,5 @@ +package studyarea; + public class Location { private String name; private String address; diff --git a/src/main/java/studyarea/StudyArea.java b/src/main/java/studyarea/StudyArea.java new file mode 100644 index 000000000..f726019de --- /dev/null +++ b/src/main/java/studyarea/StudyArea.java @@ -0,0 +1,27 @@ +package studyarea; + +import resourceloader.LocationLoader; + +import java.io.FileNotFoundException; +import java.util.ArrayList; + +public class StudyArea { + private ArrayList locations; + + /** + * Setups a resource loader to import the file by creating a new + * LocationLoader class. The file is then load onto the software and then + * parsed as an ArrayList to be stored in location in this StudyArea class. + + * @throws Exception to be edited + */ + public StudyArea() throws Exception { + LocationLoader locationLoader = new LocationLoader("library/locations.txt"); + locationLoader.loadFile(); + locations = locationLoader.pushToDatabase(); + } + + public ArrayList getLocationsList() { + return locations; + } +} diff --git a/src/test/java/resourceloader/LocationLoaderTest.java b/src/test/java/resourceloader/LocationLoaderTest.java index d8c13decf..f2349c96a 100644 --- a/src/test/java/resourceloader/LocationLoaderTest.java +++ b/src/test/java/resourceloader/LocationLoaderTest.java @@ -8,10 +8,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; class LocationLoaderTest { + LocationLoader locationLoader = new LocationLoader("library/locations.txt"); + LocationLoaderTest() throws FileNotFoundException { + } + @Test - void loadFile() throws FileNotFoundException { + void getFile() throws FileNotFoundException { locationLoader.loadFile(); assertEquals(new File("library/locations.txt"), locationLoader.getFile()); } diff --git a/src/test/java/LocationTest.java b/src/test/java/studyarea/LocationTest.java similarity index 94% rename from src/test/java/LocationTest.java rename to src/test/java/studyarea/LocationTest.java index f36bef096..95080a98e 100644 --- a/src/test/java/LocationTest.java +++ b/src/test/java/studyarea/LocationTest.java @@ -1,5 +1,7 @@ -import org.junit.jupiter.api.BeforeEach; +package studyarea; + import org.junit.jupiter.api.Test; +import studyarea.Location; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/studyarea/StudyAreaTest.java b/src/test/java/studyarea/StudyAreaTest.java new file mode 100644 index 000000000..0664f2cdf --- /dev/null +++ b/src/test/java/studyarea/StudyAreaTest.java @@ -0,0 +1,19 @@ +package studyarea; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class StudyAreaTest { + StudyArea studyArea = new StudyArea(); + + StudyAreaTest() throws Exception { + } + + @Test + void getLocationList() throws Exception { + assertEquals(new Location("OCBC","2 College Ave West, Stephen Riady Centre", + "-",true,false,2).getAddress(), + studyArea.getLocationsList().get(1).getAddress()); + } +} \ No newline at end of file From 7bf0ef63cb407279a0e00eabaf46a475398526b9 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Fri, 6 Mar 2020 23:33:53 +0800 Subject: [PATCH 018/435] Add Event.java, Ui.java and EventList.java --- src/main/java/event/Event.java | 77 ++++++++++++++ src/main/java/event/EventList.java | 162 +++++++++++++++++++++++++++++ src/main/java/ui/Ui.java | 15 +++ 3 files changed, 254 insertions(+) create mode 100644 src/main/java/event/Event.java create mode 100644 src/main/java/event/EventList.java create mode 100644 src/main/java/ui/Ui.java diff --git a/src/main/java/event/Event.java b/src/main/java/event/Event.java new file mode 100644 index 000000000..df79001ee --- /dev/null +++ b/src/main/java/event/Event.java @@ -0,0 +1,77 @@ +package event; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeParseException; + +/** + * Represents an event and contains the related functions. + */ +public class Event { + + private String description; + private LocalDate date; + private LocalTime startTime; + private LocalTime endTime; + private int priority; + + /** + * Constructor for Event Class. + * + * @param description Description of the event. + * @param date Date of specified Event. + * @param startTime Start time of specified event. + * @param endTime End time of specified event. + * @param priority Priority of specified event. + * @throws DateTimeParseException If wrong format is used for date, time fields. + */ + public Event(String description, String date, String startTime, String endTime, String priority) + throws DateTimeParseException { + this.description = description; + this.date = LocalDate.parse(date.strip()); + this.startTime = LocalTime.parse(startTime.strip()); + this.endTime = LocalTime.parse(endTime.strip()); + this.priority = Integer.parseInt(priority.strip()); + } + + /** + * Returns the information related to information in form of a string. + * + * @return eventInfo Contains information related to the event. + */ + public String getEventInformation() { + String eventInfo = description + " at " + date.toString() + " from " + startTime.toString() + + " to " + endTime.toString(); + return eventInfo; + } + + /** + * Returns the priority of the specified event. + * + * @return Priority of event. + */ + public int getPriority() { + return priority; + } + + /** + * Returns the date of the event. + * + * @return Date of event. + */ + public LocalDate getDate() { + return date; + } + + /** + * Used to identify if the string contains the keyword specified in its description. + * + * @param keyword The keyword to be matched with the description. + * @return containsKeyword Indicates the presence/absence of keyword in the event's description. + */ + public boolean hasKeyword(String keyword) { + boolean containsKeyword = description.contains(keyword); + return containsKeyword; + } + +} diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java new file mode 100644 index 000000000..4cd048277 --- /dev/null +++ b/src/main/java/event/EventList.java @@ -0,0 +1,162 @@ +package event; + +import java.time.format.DateTimeParseException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import ui.Ui; + +/** + * Handles all functions related to the list of events. + */ +public class EventList { + + Ui ui = new Ui(); + + /** Stores the event information. */ + private ArrayList events; + + /** + * Constructor for the EventList class. + */ + public EventList() { + events = new ArrayList(); + } + + /** + * Adds a new event to the list. + * + * @param newEvent Event represents the new event tot be added. + */ + public void addEvent(Event newEvent) { + ui.printLine(); + System.out.println("A new event with the following information has been added."); + System.out.println(newEvent.getEventInformation()); + ui.printLine(); + events.add(newEvent); + } + + /** + * Displays the current list of events. + */ + public void listEvents() { + ui.printLine(); + System.out.println("Here is the list of events added so far:"); + int eventNumber = 1; + for (Event event: events) { + System.out.println(eventNumber + ") " + event.getEventInformation()); + eventNumber++; + } + ui.printLine(); + } + + /** + * Deletes the event at the specified index. + * + * @param index The index (1-based) of the event to be deleted. + */ + public void deleteEvent(int index) { + try { + events.remove(index - 1); + ui.printLine(); + System.out.println("The event at the mentioned index has been deleted"); + ui.printLine(); + } catch (IndexOutOfBoundsException e) { + ui.printLine(); + System.out.println("Enter a valid index"); + ui.printLine(); + } + + } + + /** + * Clears all the events currently stored. + */ + public void clearEvents() { + events.clear(); + ui.printLine(); + System.out.println("The list of events is cleared."); + ui.printLine(); + } + + /** + * Lists all the tasks sorted by their priority. + */ + public void priorityView() { + ArrayList eventsSortedByPriority = events; + eventsSortedByPriority.sort(Comparator.comparingInt(Event::getPriority)); + Collections.reverse(eventsSortedByPriority); + ui.printLine(); + int eventNumber = 1; + for (Event event:eventsSortedByPriority) { + System.out.println(eventNumber + ") " + event.getEventInformation()); + eventNumber++; + } + if (eventNumber == 1) { + System.out.println("The list is empty."); + } + ui.printLine(); + } + + /** + * Lists all the tasks sorted by date along with the days remaining. + */ + public void countdownView() { + ArrayList eventsSortedByDate = events; + eventsSortedByDate.sort(Comparator.comparing(Event::getDate)); + ui.printLine(); + int eventNumber = 1; + for (Event event:eventsSortedByDate) { + System.out.println(eventNumber + ") " + event.getEventInformation()); + eventNumber++; + } + if (eventNumber == 1) { + System.out.println("The list is empty."); + } + ui.printLine(); + } + + /** + * Displays the list of events containing the keyword. + * + * @param keyword The keyword to be searched for. + */ + public void searchEvents(String keyword) { + ui.printLine(); + int eventNumber = 1; + for (Event event:events) { + if (event.hasKeyword(keyword)) { + System.out.println(eventNumber + ") " + event.getEventInformation()); + eventNumber++; + } + } + if (eventNumber == 1) { + System.out.println("The list is empty."); + } + ui.printLine(); + } + + /** + * Adds a new event to the list by parsing information from the user given string + * and calling {@link #addEvent(Event)} if the information is given in the correct format + * to add the event. + * + * @param eventDetails Contains all the information related to the event as provided by the user. + */ + public void add(String eventDetails) { + try { + String[] details = eventDetails.split(" ",2)[1].split("/"); + String description = details[0]; + String date = details[1].substring(2); + String startTime = details[2].substring(2); + String endTime = details[3].substring(2); + String priority = details[4].substring(2); + Event newEvent = new Event(description,date,startTime,endTime,priority); + addEvent(newEvent); + } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { + ui.printLine(); + System.out.println("Wrong format to add events"); + ui.printLine(); + } + } +} diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java new file mode 100644 index 000000000..325755ffa --- /dev/null +++ b/src/main/java/ui/Ui.java @@ -0,0 +1,15 @@ +package ui; + +/** + * Contains functions used to interact with the user. + */ +public class Ui { + + /** + * Prints a line made up of '_'. + */ + public void printLine() { + System.out.println("____________________________________________________________________________________"); + } + +} From c17da9d6c0e7f41fa145dcd6c8a08f4bddc151cd Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Fri, 6 Mar 2020 23:34:35 +0800 Subject: [PATCH 019/435] Edit Duke.java to support new commands. --- src/main/java/seedu/duke/Duke.java | 72 ++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index c9cb023c9..6cf84ab93 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,10 +1,27 @@ package seedu.duke; -import studyarea.StudyArea; +import event.EventList; +import ui.Ui; import java.util.Scanner; public class Duke { + + public static Ui ui = new Ui(); + + public static final String ADD_COMMAND = "add"; + public static final String VIEW_COMMAND = "view"; + public static final String PRIORITY_VIEW_COMMAND = "priority_view"; + public static final String COUNTDOWN_VIEW_COMMAND = "countdown"; + public static final String CLEAR_COMMAND = "clear"; + public static final String SEARCH_COMMAND = "search"; + public static final String DELETE_COMMAND = "delete"; + public static final String INVALID_INDEX_MESSAGE = "Enter a valid index"; + public static final String INVALID_COMMAND_MESSAGE = "Enter a valid command"; + public static final String BYE_COMMAND = "bye"; + public static final String BYE_MESSAGE = "Bye!!!!!!"; + static EventList eventList = new EventList(); + /** * Main entry-point for the java.duke.Duke application. */ @@ -19,8 +36,55 @@ public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); System.out.println("Hello " + in.nextLine()); - StudyArea studyArea = new StudyArea(); - String output = studyArea.getLocationsList().get(1).getAddress(); - System.out.println(output); + runCommands(); + } + + private static void runCommands() { + Scanner in = new Scanner(System.in); + String command; + command = in.nextLine(); + while (!command.equals(BYE_COMMAND)) { + try { + String commandType = command.split(" ")[0]; + switch (commandType) { + case ADD_COMMAND: + eventList.add(command); + break; + case VIEW_COMMAND: + eventList.listEvents(); + break; + case PRIORITY_VIEW_COMMAND: + eventList.priorityView(); + break; + case COUNTDOWN_VIEW_COMMAND: + eventList.countdownView(); + break; + case CLEAR_COMMAND: + eventList.clearEvents(); + break; + case SEARCH_COMMAND: + eventList.searchEvents(command.split(" ", 2)[1]); + break; + case DELETE_COMMAND: + eventList.deleteEvent(Integer.parseInt(command.split(" ", 2)[1])); + break; + default: + ui.printLine(); + System.out.println(INVALID_COMMAND_MESSAGE); + ui.printLine(); + break; + } + } catch (NumberFormatException e) { + ui.printLine(); + System.out.println(INVALID_INDEX_MESSAGE); + ui.printLine(); + } catch (IndexOutOfBoundsException e) { + ui.printLine(); + System.out.println(INVALID_COMMAND_MESSAGE); + ui.printLine(); + } + command = in.nextLine(); + } + System.out.println(BYE_MESSAGE); } } From 03f01d524203782fd3f2ba3797dc02bd61cce943 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Sat, 7 Mar 2020 13:49:59 +0800 Subject: [PATCH 020/435] Update EventList.java under addEvent, I have modifed the sequence of execution to display the added msg after the event has indeed been added. --- src/main/java/event/EventList.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index 4cd048277..63ede6860 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -30,10 +30,11 @@ public EventList() { */ public void addEvent(Event newEvent) { ui.printLine(); + + events.add(newEvent); System.out.println("A new event with the following information has been added."); System.out.println(newEvent.getEventInformation()); ui.printLine(); - events.add(newEvent); } /** From ceb26d23f02545f83ba3b95e1526a4100f9e2725 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 7 Mar 2020 17:51:41 +0800 Subject: [PATCH 021/435] Add support to load and save events --- data/EventList.txt | 0 src/main/java/event/Event.java | 3 + src/main/java/event/EventList.java | 33 ++++---- src/main/java/resourceloader/EventLoader.java | 77 +++++++++++++++++++ src/main/java/seedu/duke/Duke.java | 10 ++- 5 files changed, 107 insertions(+), 16 deletions(-) create mode 100644 data/EventList.txt create mode 100644 src/main/java/resourceloader/EventLoader.java diff --git a/data/EventList.txt b/data/EventList.txt new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/java/event/Event.java b/src/main/java/event/Event.java index df79001ee..c50b74a99 100644 --- a/src/main/java/event/Event.java +++ b/src/main/java/event/Event.java @@ -74,4 +74,7 @@ public boolean hasKeyword(String keyword) { return containsKeyword; } + public String getFormattedDetails() { + return description + "#" + date + "#" + startTime + "#" + endTime + "#" + priority; + } } diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index 4cd048277..3b59b7d0d 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -14,7 +14,7 @@ public class EventList { Ui ui = new Ui(); /** Stores the event information. */ - private ArrayList events; + public ArrayList events; /** * Constructor for the EventList class. @@ -23,6 +23,10 @@ public EventList() { events = new ArrayList(); } + public EventList(ArrayList events) { + this.events = events; + } + /** * Adds a new event to the list. * @@ -30,8 +34,9 @@ public EventList() { */ public void addEvent(Event newEvent) { ui.printLine(); - System.out.println("A new event with the following information has been added."); - System.out.println(newEvent.getEventInformation()); + events.add(newEvent); + ui.printWithIndentation("A new event with the following information has been added."); + ui.printWithIndentation(newEvent.getEventInformation()); ui.printLine(); events.add(newEvent); } @@ -44,7 +49,7 @@ public void listEvents() { System.out.println("Here is the list of events added so far:"); int eventNumber = 1; for (Event event: events) { - System.out.println(eventNumber + ") " + event.getEventInformation()); + ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); eventNumber++; } ui.printLine(); @@ -59,11 +64,11 @@ public void deleteEvent(int index) { try { events.remove(index - 1); ui.printLine(); - System.out.println("The event at the mentioned index has been deleted"); + ui.printWithIndentation("The event at the mentioned index has been deleted"); ui.printLine(); } catch (IndexOutOfBoundsException e) { ui.printLine(); - System.out.println("Enter a valid index"); + ui.printWithIndentation("Enter a valid index"); ui.printLine(); } @@ -75,7 +80,7 @@ public void deleteEvent(int index) { public void clearEvents() { events.clear(); ui.printLine(); - System.out.println("The list of events is cleared."); + ui.printWithIndentation("The list of events is cleared."); ui.printLine(); } @@ -89,11 +94,11 @@ public void priorityView() { ui.printLine(); int eventNumber = 1; for (Event event:eventsSortedByPriority) { - System.out.println(eventNumber + ") " + event.getEventInformation()); + ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); eventNumber++; } if (eventNumber == 1) { - System.out.println("The list is empty."); + ui.printWithIndentation("The list is empty."); } ui.printLine(); } @@ -107,11 +112,11 @@ public void countdownView() { ui.printLine(); int eventNumber = 1; for (Event event:eventsSortedByDate) { - System.out.println(eventNumber + ") " + event.getEventInformation()); + ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); eventNumber++; } if (eventNumber == 1) { - System.out.println("The list is empty."); + ui.printWithIndentation("The list is empty."); } ui.printLine(); } @@ -126,12 +131,12 @@ public void searchEvents(String keyword) { int eventNumber = 1; for (Event event:events) { if (event.hasKeyword(keyword)) { - System.out.println(eventNumber + ") " + event.getEventInformation()); + ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); eventNumber++; } } if (eventNumber == 1) { - System.out.println("The list is empty."); + ui.printWithIndentation("The list is empty."); } ui.printLine(); } @@ -155,7 +160,7 @@ public void add(String eventDetails) { addEvent(newEvent); } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { ui.printLine(); - System.out.println("Wrong format to add events"); + ui.printWithIndentation("Wrong format to add events"); ui.printLine(); } } diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java new file mode 100644 index 000000000..aedeec167 --- /dev/null +++ b/src/main/java/resourceloader/EventLoader.java @@ -0,0 +1,77 @@ +package resourceloader; + +import event.Event; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Scanner; + +public class EventLoader { + + private String filePath; + private Path fileDirectory; + + public EventLoader(String filePath) { + this.filePath = filePath; + this.fileDirectory = Paths.get(filePath).getParent(); + } + + + public ArrayList loadFile() { + ArrayList events = new ArrayList<>();; + File dataFile; + Scanner s; + try { + dataFile = new File(filePath); + s = new Scanner(dataFile); + while (s.hasNext()) { + String eventDescription = s.nextLine(); + Event newEvent = parseEventDetails(eventDescription); + events.add(newEvent); + } + } catch (FileNotFoundException e) { + createNewDataFile(); + } + return events; + } + + private Event parseEventDetails(String taskDescription) { + String[] splitDescription = taskDescription.split("#", 5); + String description = splitDescription[0]; + String date = splitDescription[1]; + String startTime = splitDescription[2]; + String endTime = splitDescription[3]; + String priority = splitDescription[4]; + return new Event(description ,date ,startTime, endTime, priority); + } + + private void createNewDataFile() { + + try { + Files.createDirectories(fileDirectory); + Files.createFile(Paths.get(filePath)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void saveEvents(ArrayList events) { + + try { + FileWriter fw = new FileWriter(filePath); + for (Event event: events) { + fw.write(event.getFormattedDetails()); + } + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 6cf84ab93..5c4426515 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,14 +1,17 @@ package seedu.duke; import event.EventList; +import resourceloader.EventLoader; import ui.Ui; +import java.io.File; import java.util.Scanner; public class Duke { + private static final String FILE_PATH = "data" + File.separator + "EventList.txt"; public static Ui ui = new Ui(); - + public static EventLoader eventLoader; public static final String ADD_COMMAND = "add"; public static final String VIEW_COMMAND = "view"; public static final String PRIORITY_VIEW_COMMAND = "priority_view"; @@ -20,7 +23,7 @@ public class Duke { public static final String INVALID_COMMAND_MESSAGE = "Enter a valid command"; public static final String BYE_COMMAND = "bye"; public static final String BYE_MESSAGE = "Bye!!!!!!"; - static EventList eventList = new EventList(); + static EventList eventList; /** * Main entry-point for the java.duke.Duke application. @@ -36,7 +39,10 @@ public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); System.out.println("Hello " + in.nextLine()); + eventLoader = new EventLoader(FILE_PATH); + eventList = new EventList(eventLoader.loadFile()); runCommands(); + eventLoader.saveEvents(eventList.events); } private static void runCommands() { From 185f85117c945f658ed1a9f758470b0255ad6bec Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 7 Mar 2020 18:10:36 +0800 Subject: [PATCH 022/435] Add new function in "Ui" Class --- src/main/java/ui/Ui.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 325755ffa..7a0c4d296 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -12,4 +12,7 @@ public void printLine() { System.out.println("____________________________________________________________________________________"); } + public void printWithIndentation(String line) { + System.out.println(" " + line); + } } From 4aa99d7f47492406cd87d261848fc283b02f3843 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 7 Mar 2020 18:21:14 +0800 Subject: [PATCH 023/435] Add javadoc comments --- src/main/java/resourceloader/EventLoader.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java index aedeec167..9f4b4218b 100644 --- a/src/main/java/resourceloader/EventLoader.java +++ b/src/main/java/resourceloader/EventLoader.java @@ -12,17 +12,34 @@ import java.util.ArrayList; import java.util.Scanner; + +/** + * Handles the task of loading and storing events. + */ public class EventLoader { + /** Location of data file. */ private String filePath; + /** Directory of data file. */ private Path fileDirectory; + /** + * Constructor for EventLoader object. + * Initialises the object with the file path provided. + * + * @param filePath The location of the data file. + */ public EventLoader(String filePath) { this.filePath = filePath; this.fileDirectory = Paths.get(filePath).getParent(); } + /** + * Reads the list of events stored previously and returns it as an ArrayList of Events. + * + * @return events The list of events stored previously. + */ public ArrayList loadFile() { ArrayList events = new ArrayList<>();; File dataFile; @@ -41,6 +58,12 @@ public ArrayList loadFile() { return events; } + /** + * Parses the Event details from the given string and returns a new event object with the specified details. + * + * @param taskDescription Contains all the details with regards to the Event. + * @return newEvent The new event created with the details provided. + */ private Event parseEventDetails(String taskDescription) { String[] splitDescription = taskDescription.split("#", 5); String description = splitDescription[0]; @@ -48,9 +71,14 @@ private Event parseEventDetails(String taskDescription) { String startTime = splitDescription[2]; String endTime = splitDescription[3]; String priority = splitDescription[4]; - return new Event(description ,date ,startTime, endTime, priority); + Event newEvent = new Event(description, date, startTime, endTime, priority); + return newEvent; } + + /** + * Creates a new data file when the application is run for the first time. + */ private void createNewDataFile() { try { @@ -61,8 +89,12 @@ private void createNewDataFile() { } } + /** + * Saves the list of current tasks to the data file. + * + * @param events Represents the current list of events. + */ public void saveEvents(ArrayList events) { - try { FileWriter fw = new FileWriter(filePath); for (Event event: events) { From 2bb4e6998e5d3f3f6fb64876e7a385314f8dc844 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Sat, 7 Mar 2020 20:12:22 +0800 Subject: [PATCH 024/435] Create eventList.txt --- library/eventList.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 library/eventList.txt diff --git a/library/eventList.txt b/library/eventList.txt new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/library/eventList.txt @@ -0,0 +1 @@ + From 78a5fd68e2aac9e0a0b9203451ca89ff37929457 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Sat, 7 Mar 2020 20:12:45 +0800 Subject: [PATCH 025/435] Delete EventList.txt --- data/EventList.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 data/EventList.txt diff --git a/data/EventList.txt b/data/EventList.txt deleted file mode 100644 index e69de29bb..000000000 From 6ffc3d623909794e4b54ca908745224123ec3e6e Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Sat, 7 Mar 2020 20:15:00 +0800 Subject: [PATCH 026/435] Update Duke.java --- src/main/java/seedu/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 5c4426515..29d29d93d 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -9,7 +9,7 @@ public class Duke { - private static final String FILE_PATH = "data" + File.separator + "EventList.txt"; + private static final String FILE_PATH = "library" + File.separator + "eventList.txt"; public static Ui ui = new Ui(); public static EventLoader eventLoader; public static final String ADD_COMMAND = "add"; From f6f689ca32cd2535b727595310df8f3633a777fe Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 7 Mar 2020 23:02:54 +0800 Subject: [PATCH 027/435] Add JUnit Test for Event Class --- src/main/java/event/Event.java | 73 +++++++++-- src/main/java/event/EventList.java | 14 ++- src/main/java/resourceloader/EventLoader.java | 8 +- src/test/java/event/EventTest.java | 117 ++++++++++++++++++ 4 files changed, 198 insertions(+), 14 deletions(-) create mode 100644 src/test/java/event/EventTest.java diff --git a/src/main/java/event/Event.java b/src/main/java/event/Event.java index c50b74a99..487c48845 100644 --- a/src/main/java/event/Event.java +++ b/src/main/java/event/Event.java @@ -2,6 +2,7 @@ import java.time.LocalDate; import java.time.LocalTime; +import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; /** @@ -23,15 +24,58 @@ public class Event { * @param startTime Start time of specified event. * @param endTime End time of specified event. * @param priority Priority of specified event. - * @throws DateTimeParseException If wrong format is used for date, time fields. + * @throws Exception If wrong format is used for date, time or priority fields. */ public Event(String description, String date, String startTime, String endTime, String priority) - throws DateTimeParseException { + throws Exception { + parseDescription(description); + parseDate(date); + parseStartTime(startTime); + parseEndTime(endTime); + parsePriority(priority); + if (this.startTime.isAfter(this.endTime)) { + throw new Exception("Start time should be before End time"); + } + if (this.date.isBefore(LocalDate.now())) { + throw new Exception("Date specified must be a current or a future date"); + } + } + + private void parsePriority(String priority) throws Exception { + try { + this.priority = Integer.parseInt(priority.strip()); + } catch (NumberFormatException e) { + throw new Exception("Priority should be an integer"); + } + } + + private void parseEndTime(String endTime) throws Exception { + try { + this.endTime = LocalTime.parse(endTime.strip()); + } catch (DateTimeParseException e) { + throw new Exception("End time provided is invalid or in wrong format (Should be HH:MM)"); + } + } + + private void parseStartTime(String startTime) throws Exception { + try { + this.startTime = LocalTime.parse(startTime.strip()); + } catch (DateTimeParseException e) { + throw new Exception("Start time provided is invalid or in wrong format (Should be HH:MM)"); + } + } + + private void parseDate(String date) throws Exception { + try { + this.date = LocalDate.parse(date.strip()); + } catch (DateTimeParseException e) { + throw new Exception("Date provided is invalid or is in wrong format (Should be YYYY-MM-DD)"); + } + + } + + private void parseDescription(String description) { this.description = description; - this.date = LocalDate.parse(date.strip()); - this.startTime = LocalTime.parse(startTime.strip()); - this.endTime = LocalTime.parse(endTime.strip()); - this.priority = Integer.parseInt(priority.strip()); } /** @@ -40,8 +84,8 @@ public Event(String description, String date, String startTime, String endTime, * @return eventInfo Contains information related to the event. */ public String getEventInformation() { - String eventInfo = description + " at " + date.toString() + " from " + startTime.toString() - + " to " + endTime.toString(); + String eventInfo = description + " at " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + " from " + + startTime.toString() + " to " + endTime.toString(); return eventInfo; } @@ -69,12 +113,21 @@ public LocalDate getDate() { * @param keyword The keyword to be matched with the description. * @return containsKeyword Indicates the presence/absence of keyword in the event's description. */ - public boolean hasKeyword(String keyword) { + public boolean hasKeyword(String keyword) throws Exception { + if (keyword.equals("")) { + throw new Exception("Keyword is empty"); + } boolean containsKeyword = description.contains(keyword); return containsKeyword; } + /** + * Returns the event in the format used to store it in the data file. + * + * @return formattedEventDetails Contains the event details in the required format. + */ public String getFormattedDetails() { - return description + "#" + date + "#" + startTime + "#" + endTime + "#" + priority; + String formattedEventDetails = description + "#" + date + "#" + startTime + "#" + endTime + "#" + priority; + return formattedEventDetails; } } diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index ced7941ad..947d606da 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -129,9 +129,13 @@ public void searchEvents(String keyword) { ui.printLine(); int eventNumber = 1; for (Event event:events) { - if (event.hasKeyword(keyword)) { - ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); - eventNumber++; + try { + if (event.hasKeyword(keyword)) { + ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); + eventNumber++; + } + } catch (Exception e) { + e.printStackTrace(); } } if (eventNumber == 1) { @@ -161,6 +165,10 @@ public void add(String eventDetails) { ui.printLine(); ui.printWithIndentation("Wrong format to add events"); ui.printLine(); + } catch (Exception e) { + ui.printLine(); + ui.printWithIndentation(e.getMessage()); + ui.printLine(); } } } diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java index 9f4b4218b..9326382c0 100644 --- a/src/main/java/resourceloader/EventLoader.java +++ b/src/main/java/resourceloader/EventLoader.java @@ -1,6 +1,7 @@ package resourceloader; import event.Event; +import ui.Ui; import java.io.File; import java.io.FileNotFoundException; @@ -44,6 +45,7 @@ public ArrayList loadFile() { ArrayList events = new ArrayList<>();; File dataFile; Scanner s; + Ui ui = new Ui(); try { dataFile = new File(filePath); s = new Scanner(dataFile); @@ -54,6 +56,10 @@ public ArrayList loadFile() { } } catch (FileNotFoundException e) { createNewDataFile(); + } catch (Exception e) { + ui.printLine(); + ui.printWithIndentation(e.getMessage()); + ui.printLine(); } return events; } @@ -64,7 +70,7 @@ public ArrayList loadFile() { * @param taskDescription Contains all the details with regards to the Event. * @return newEvent The new event created with the details provided. */ - private Event parseEventDetails(String taskDescription) { + private Event parseEventDetails(String taskDescription) throws Exception { String[] splitDescription = taskDescription.split("#", 5); String description = splitDescription[0]; String date = splitDescription[1]; diff --git a/src/test/java/event/EventTest.java b/src/test/java/event/EventTest.java new file mode 100644 index 000000000..439260df9 --- /dev/null +++ b/src/test/java/event/EventTest.java @@ -0,0 +1,117 @@ +package event; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Contains all the tests related to the Event class. + */ +class EventTest { + + @Test + void eventInformation() throws Exception { + assertEquals("Team Meeting at Mar 21 2020 from 09:00 to 17:00", + new Event("Team Meeting", "2020-03-21", "09:00", + "17:00", "1").getEventInformation()); + } + + @Test + void formattedDetails() throws Exception { + assertEquals("Team Meeting#2020-03-21#09:00#17:00#1", + new Event("Team Meeting", "2020-03-21", "09:00", + "17:00", "1").getFormattedDetails()); + } + + @Test + void createEvent_invalidDate_throwException() { + try { + Event event = new Event("Team Meeting", "2020-03-021", "09:00", + "17:00", "1"); + fail("Invalid date not rejected"); + } catch (Exception e) { + assertEquals("Date provided is invalid or is in wrong format (Should be YYYY-MM-DD)", + e.getMessage()); + } + } + + + @Test + void createEvent_invalidStartTime_throwException() { + try { + Event event = new Event("Team Meeting", "2020-03-21", "25:00", + "17:00", "1"); + fail("Invalid start time not rejected"); + } catch (Exception e) { + assertEquals("Start time provided is invalid or in wrong format (Should be HH:MM)",e.getMessage()); + } + } + + @Test + void createEvent_invalidEndTime_throwException() { + try { + Event event = new Event("Team Meeting", "2020-03-21", "09:00", + "10:70", "1"); + fail("Invalid end time not rejected"); + } catch (Exception e) { + assertEquals("End time provided is invalid or in wrong format (Should be HH:MM)",e.getMessage()); + } + } + + @Test + void createEvent_invalidPriority_throwException() { + try { + Event event = new Event("Team Meeting", "2020-03-21", "09:00", + "10:50", "High"); + fail("Invalid priority not rejected"); + } catch (Exception e) { + assertEquals("Priority should be an integer",e.getMessage()); + } + } + + @Test + void createEvent_startTimeAfterEndTime_throwException() { + try { + Event event = new Event("Team Meeting", "2020-03-21", "09:00", + "08:50", "1"); + fail("Start time after end time not rejected"); + } catch (Exception e) { + assertEquals("Start time should be before End time",e.getMessage()); + } + } + + @Test + void createEvent_dateAlreadyPassed_throwException() { + try { + Event event = new Event("Team Meeting", "2019-03-21", "09:00", + "09:50", "1"); + fail("Event before current date not rejected"); + } catch (Exception e) { + assertEquals("Date specified must be a current or a future date",e.getMessage()); + } + } + + @Test + void searchKeyword_emptyKeyword_throwException() throws Exception { + try { + boolean hasKeyword = new Event("Team Meeting", "2020-03-21", "09:00", + "17:00", "1").hasKeyword(""); + fail("Empty keyword not detected"); + } catch (Exception e) { + assertEquals("Keyword is empty", e.getMessage()); + } + } + + @Test + void searchKeyword_containsKeyword() throws Exception { + assertEquals(true, new Event("Team Meeting", "2020-03-21", "09:00", + "17:00", "1").hasKeyword("Meeting")); + } + + @Test + void searchKeyword_doesntContainsKeyword() throws Exception { + assertEquals(false, new Event("Team Meeting", "2020-03-21", "09:00", + "17:00", "1").hasKeyword("Class")); + } + +} \ No newline at end of file From 08ed775aa8dae8495c4f315290a61754677d0818 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 7 Mar 2020 23:06:36 +0800 Subject: [PATCH 028/435] Tweak code to follow coding standard --- src/test/java/event/EventTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/event/EventTest.java b/src/test/java/event/EventTest.java index 439260df9..ad2a1aca5 100644 --- a/src/test/java/event/EventTest.java +++ b/src/test/java/event/EventTest.java @@ -2,7 +2,8 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Contains all the tests related to the Event class. @@ -113,5 +114,5 @@ void searchKeyword_doesntContainsKeyword() throws Exception { assertEquals(false, new Event("Team Meeting", "2020-03-21", "09:00", "17:00", "1").hasKeyword("Class")); } - + } \ No newline at end of file From 39fded61018f1307e1e5cdc5df72077268b7f1bf Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sun, 8 Mar 2020 14:26:37 +0800 Subject: [PATCH 029/435] Implement Study Area V1.0 --- library/locations.txt | 10 +- ...cationLoader.java => StudyAreaLoader.java} | 31 +++- .../studyarea/IllegalStudyAreaException.java | 14 ++ src/main/java/studyarea/Location.java | 61 ------- src/main/java/studyarea/StudyArea.java | 84 +++++++-- src/main/java/studyarea/StudyAreaCommand.java | 94 ++++++++++ src/main/java/studyarea/StudyAreaList.java | 169 ++++++++++++++++++ src/main/java/studyarea/Utility.java | 64 +++++++ ...aderTest.java => StudyAreaLoaderTest.java} | 7 +- src/test/java/studyarea/LocationTest.java | 44 ----- .../java/studyarea/StudyAreaListTest.java | 19 ++ src/test/java/studyarea/StudyAreaTest.java | 34 +++- 12 files changed, 491 insertions(+), 140 deletions(-) rename src/main/java/resourceloader/{LocationLoader.java => StudyAreaLoader.java} (55%) create mode 100644 src/main/java/studyarea/IllegalStudyAreaException.java delete mode 100644 src/main/java/studyarea/Location.java create mode 100644 src/main/java/studyarea/StudyAreaCommand.java create mode 100644 src/main/java/studyarea/StudyAreaList.java create mode 100644 src/main/java/studyarea/Utility.java rename src/test/java/resourceloader/{LocationLoaderTest.java => StudyAreaLoaderTest.java} (65%) delete mode 100644 src/test/java/studyarea/LocationTest.java create mode 100644 src/test/java/studyarea/StudyAreaListTest.java diff --git a/library/locations.txt b/library/locations.txt index d70644e90..42de138ad 100644 --- a/library/locations.txt +++ b/library/locations.txt @@ -1,2 +1,8 @@ -MacCommons 2 College Ave West Education Resource Centre - true true 5 -OCBC 2 College Ave West, Stephen Riady Centre - true false 2 \ No newline at end of file +MacCommons~2 College Ave West Education Resource Centre~Utown~true~true~5 +OCBC~2 College Ave West, Stephen Riady Centre~Utown~true~false~2 +EA Level 3~9 Engineering Drive 1,EA~Engineering~true~true~4 +EA Level 2~9 Engineering Drive 1~Engineering~true~true~4 +EA Level 1~9 Engineering Drive 1~Engineering~true~true~4 +EA Level 4~9 Engineering Drive 1, Outside Staff Offices~Engineering~true~false~6 +EA Level 5~9 Engineering Drive 1, Outside of the door beside EA05~Engineering~true~false~4 +EA Level 6~9 Engineering Drive 1, EA06-23~Engineering~true~true~4 \ No newline at end of file diff --git a/src/main/java/resourceloader/LocationLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java similarity index 55% rename from src/main/java/resourceloader/LocationLoader.java rename to src/main/java/resourceloader/StudyAreaLoader.java index adacd5436..f6e321451 100644 --- a/src/main/java/resourceloader/LocationLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -1,18 +1,25 @@ package resourceloader; -import studyarea.Location; +import studyarea.IllegalStudyAreaException; +import studyarea.StudyArea; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; -public class LocationLoader implements Loader { - private static final String DIVIDER = " "; +import static studyarea.Utility.INCONSISTENT_DATA_STORAGE; + +/** + * This class loads all the required information of Study Areas that is stored in location.txt. + */ + +public class StudyAreaLoader implements Loader { + private static final String DIVIDER = "~"; private final String url; private File file; - public LocationLoader(String url) throws FileNotFoundException { + public StudyAreaLoader(String url) throws FileNotFoundException { this.url = url; loadFile(); } @@ -36,19 +43,25 @@ public File getFile() { * to add it to its database. * * @return buffer ArrayList of Location from study area file - * @throws Exception to be edited + * @throws FileNotFoundException if location.txt does not exist. */ - public ArrayList pushToDatabase() throws Exception { - ArrayList buffer = new ArrayList<>(); + + public ArrayList pushToDatabase() throws FileNotFoundException, IllegalStudyAreaException { + ArrayList buffer = new ArrayList<>(); Scanner input = new Scanner(file); while (input.hasNextLine()) { String detailsOfLocation = input.nextLine(); String[] detailsBuffer = detailsOfLocation.split(DIVIDER); - Location location = new Location(detailsBuffer[0], detailsBuffer[1], detailsBuffer[2], + if (detailsBuffer.length != 6) { + throw new IllegalStudyAreaException(INCONSISTENT_DATA_STORAGE); + } + StudyArea studyArea = new StudyArea(detailsBuffer[0], detailsBuffer[1], detailsBuffer[2], Boolean.parseBoolean(detailsBuffer[3]), Boolean.parseBoolean(detailsBuffer[4]), Integer.parseInt(detailsBuffer[5])); - buffer.add(location); + buffer.add(studyArea); } return buffer; } + + } \ No newline at end of file diff --git a/src/main/java/studyarea/IllegalStudyAreaException.java b/src/main/java/studyarea/IllegalStudyAreaException.java new file mode 100644 index 000000000..f7dabc5a2 --- /dev/null +++ b/src/main/java/studyarea/IllegalStudyAreaException.java @@ -0,0 +1,14 @@ +package studyarea; + +/** + * This is an extension of the Exception class that exist only for Study Area related modules. + */ + +public class IllegalStudyAreaException extends Exception { + + public IllegalStudyAreaException(String message) { + super(message); + } + + +} diff --git a/src/main/java/studyarea/Location.java b/src/main/java/studyarea/Location.java deleted file mode 100644 index bfbd5b1ae..000000000 --- a/src/main/java/studyarea/Location.java +++ /dev/null @@ -1,61 +0,0 @@ -package studyarea; - -public class Location { - private String name; - private String address; - private String faculty; - private boolean hasPort; - private boolean isIndoor; - private int maxPax; - - /** - * Constructs a Location class for a study area location with its information - * Precondition: 'All variables have to be filled. - * - * @param name name of study location - * @param address address of study location - * @param faculty faculty of study location - * @param hasPort true for availability of ports, else false - * @param isIndoor true for indoor, else false - * @param maxPax maximum number of seats for this study area - * - * @throws Exception when not all variables are filled - */ - public Location(String name, String address, String faculty, boolean hasPort, - boolean isIndoor, int maxPax) throws Exception { - try { - this.name = name; - this.address = address; - this.faculty = faculty; - this.hasPort = hasPort; - this.isIndoor = isIndoor; - this.maxPax = maxPax; - } catch (Exception e) { - System.out.println(e.getMessage()); - } - } - - public String getName() { - return name; - } - - public String getAddress() { - return address; - } - - public String getFaculty() { - return faculty; - } - - public boolean hasPort() { - return hasPort; - } - - public boolean isIndoor() { - return isIndoor; - } - - public int getMaxPax() { - return maxPax; - } -} diff --git a/src/main/java/studyarea/StudyArea.java b/src/main/java/studyarea/StudyArea.java index f726019de..1760fbdca 100644 --- a/src/main/java/studyarea/StudyArea.java +++ b/src/main/java/studyarea/StudyArea.java @@ -1,27 +1,81 @@ package studyarea; -import resourceloader.LocationLoader; +import static java.lang.System.lineSeparator; +import static studyarea.Utility.ADDRESS_MAX_LENGTH; +import static studyarea.Utility.TAB; +import static studyarea.Utility.formatMessage; -import java.io.FileNotFoundException; -import java.util.ArrayList; +/** + * This is the Study Area class. All study area is stored as a Study Area object. + */ public class StudyArea { - private ArrayList locations; + private String name; + private String address; + private String faculty; + private boolean hasPort; + private boolean isIndoor; + private int maxPax; /** - * Setups a resource loader to import the file by creating a new - * LocationLoader class. The file is then load onto the software and then - * parsed as an ArrayList to be stored in location in this StudyArea class. - - * @throws Exception to be edited + * Constructs a Location class for a study area location with its information + * Precondition: 'All variables have to be filled. + * + * @param name name of study location + * @param address address of study location + * @param faculty faculty of study location + * @param hasPort true for availability of ports, else false + * @param isIndoor true for indoor, else false + * @param maxPax maximum number of seats for this study area */ - public StudyArea() throws Exception { - LocationLoader locationLoader = new LocationLoader("library/locations.txt"); - locationLoader.loadFile(); - locations = locationLoader.pushToDatabase(); + + public StudyArea(String name, String address, String faculty, boolean hasPort, + boolean isIndoor, int maxPax) { + this.name = name; + this.address = formatMessage(address, ADDRESS_MAX_LENGTH).trim(); + this.faculty = faculty; + this.hasPort = hasPort; + this.isIndoor = isIndoor; + this.maxPax = maxPax; } - public ArrayList getLocationsList() { - return locations; + public String getName() { + return this.name; } + + public String getAddress() { + return this.address; + } + + public String getFaculty() { + return this.faculty; + } + + public boolean hasPort() { + return this.hasPort; + } + + public boolean isIndoor() { + return this.isIndoor; + } + + public Integer getMaxPax() { + return this.maxPax; + } + + /** + * Prints the StudyArea into a standard String format. + * @return String value of all the attributes of the specific StudyArea. + */ + public String toString() { + String text = TAB + "Name: " + this.name + lineSeparator() + TAB + + "Address: " + this.address + lineSeparator() + TAB + + "Faculty: " + this.faculty + lineSeparator() + TAB + + "Port: " + this.hasPort + lineSeparator() + TAB + + "Indoor: " + this.isIndoor + lineSeparator() + TAB + + "Average number of Pax: " + this.maxPax; + String line = TAB + "__________________________________________________________"; + return line + lineSeparator() + text + lineSeparator() + line; + } + } diff --git a/src/main/java/studyarea/StudyAreaCommand.java b/src/main/java/studyarea/StudyAreaCommand.java new file mode 100644 index 000000000..ddfe56caa --- /dev/null +++ b/src/main/java/studyarea/StudyAreaCommand.java @@ -0,0 +1,94 @@ +package studyarea; + +import ui.Ui; + +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; +import static studyarea.Utility.AVAILABLE_STUDY_AREAS; +import static studyarea.Utility.EMPTY_LIST; +import static studyarea.Utility.END_COMMAND; +import static studyarea.Utility.END_MESSAGE; +import static studyarea.Utility.FLAGS; +import static studyarea.Utility.HELP_COMMAND; +import static studyarea.Utility.MAX_LINE_LENGTH; +import static studyarea.Utility.PROMPT_USER; +import static studyarea.Utility.START_STUDY_AREA_SEARCH; +import static studyarea.Utility.formatMessage; + +/** + * This is the Study Area Command class. It executes the Study Area Search function and interact with Users accordingly. + */ + +public class StudyAreaCommand { + + /** + * List out all the study areas that match with User's preference. + * @param availStudyAreas this is the list of all study areas in location.txt. + */ + + public static void printList(ArrayList availStudyAreas) { + if (availStudyAreas.isEmpty()) { + System.out.println(formatMessage(EMPTY_LIST, MAX_LINE_LENGTH)); + } else { + System.out.println(formatMessage(AVAILABLE_STUDY_AREAS, MAX_LINE_LENGTH)); + for (StudyArea studyArea : availStudyAreas) { + System.out.println(studyArea.toString()); + } + } + } + + + /** + * Filters command based on User Input. + * @param command This is the command entered by User. + * @param studyAreaList This is the list of all Study Areas in location.txt. + * @return boolean status. False if User enters "end" , else will always return true; + */ + + public static boolean filterCommand(String command,StudyAreaList studyAreaList) { + switch (command) { + case END_COMMAND : + System.out.println(formatMessage(END_MESSAGE, MAX_LINE_LENGTH)); + return false; + case HELP_COMMAND : + System.out.println(FLAGS); + break; + default: + try { + ArrayList availStudyAreas = studyAreaList.searchList(command); + printList(availStudyAreas); + } catch (IllegalStudyAreaException e) { + System.out.println(formatMessage(e.getMessage(), MAX_LINE_LENGTH)); + } finally { + System.out.println(formatMessage(PROMPT_USER, MAX_LINE_LENGTH)); + } + } + return true; + } + + /** + * Executes the Study Area search feature. + * @param args this is temporary. + * @throws FileNotFoundException If location.txt does not ext, this exception is thrown. + * @throws IllegalStudyAreaException If data is inconsistent while loading available list, this exception is thrown. + */ + + public static void main(String[] args) throws FileNotFoundException, IllegalStudyAreaException { + + Ui ui = new Ui(); + ui.printLine(); + System.out.println(formatMessage(START_STUDY_AREA_SEARCH, MAX_LINE_LENGTH)); + Scanner in = new Scanner(System.in); + StudyAreaList studyAreaList = new StudyAreaList(); + boolean status = true; + while (status) { + ui.printLine(); + String command = in.nextLine(); + ui.printLine(); + status = filterCommand(command, studyAreaList); + } + ui.printLine(); + in.close(); + } +} diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java new file mode 100644 index 000000000..91681ce2e --- /dev/null +++ b/src/main/java/studyarea/StudyAreaList.java @@ -0,0 +1,169 @@ +package studyarea; + +import resourceloader.StudyAreaLoader; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import static studyarea.Utility.DUPLICATE_FLAGS; +import static studyarea.Utility.FLAG; +import static studyarea.Utility.INDOOR_FLAG; +import static studyarea.Utility.MULTIPLE_WHITE_SPACES; +import static studyarea.Utility.NOT_INTEGER; +import static studyarea.Utility.NO_SIZE_INDICATED; +import static studyarea.Utility.ONLY_FLAG; +import static studyarea.Utility.PORTS_FLAG; +import static studyarea.Utility.SIZE_FLAG; +import static studyarea.Utility.SPACE; +import static studyarea.Utility.WRONG_FLAG_ARGUMENT_POSITION; +import static studyarea.Utility.WRONG_FLAG_USAGE; + +/** + * This is the class that stores and manages all of the Study Areas in location.txt + */ + +public class StudyAreaList { + private ArrayList studyAreaList; + + /** + * Setup a resource loader to import the file by creating a new + * LocationLoader class. The file is then load onto the software and then + * parsed as an ArrayList to be stored in location in this StudyArea class. + * + * @throws FileNotFoundException to be edited + */ + + public StudyAreaList() throws FileNotFoundException, IllegalStudyAreaException { + StudyAreaLoader studyAreaLoader = new StudyAreaLoader("library/locations.txt"); + studyAreaLoader.loadFile(); + this.studyAreaList = studyAreaLoader.pushToDatabase(); + } + + /** + * Gets the list of all the Locations in location.txt + * + * @return ArrayList of StudyAreas. + */ + + public ArrayList getStudyAreaList() { + return this.studyAreaList; + } + + /** + * Obtains all the supported flags in this organiser app. + * + * @param commands This is the User commands that has been split by spaces. + * @return String Array of a fixed size of 5 + * @throws IllegalStudyAreaException when arguments for flags are invalid. + */ + + public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException { + String[] flags = new String[5]; + StringBuilder name = new StringBuilder(); + boolean isNotFlag = true; + for (int i = 0; i < commands.length; i++) { + if (commands[i].equals(SIZE_FLAG)) { + isNotFlag = false; + try { + int size = Integer.parseInt(commands[i + 1]); + if (flags[0] == null) { + flags[0] = SIZE_FLAG; + flags[1] = Integer.toString(size); + } else { + throw new IllegalStudyAreaException(DUPLICATE_FLAGS); + } + } catch (NumberFormatException e) { + throw new IllegalStudyAreaException(NOT_INTEGER); + } catch (ArrayIndexOutOfBoundsException e) { + throw new IllegalStudyAreaException(NO_SIZE_INDICATED); + } finally { + i++; + } + } else if (commands[i].contains(FLAG)) { + isNotFlag = false; + if (commands[i].length() == 1) { + throw new IllegalStudyAreaException(ONLY_FLAG); + } + switch (commands[i].charAt(1)) { + case 'p': + if (flags[2] == null) { + flags[2] = PORTS_FLAG; + } else { + throw new IllegalStudyAreaException(DUPLICATE_FLAGS); + } + break; + case 'i': + if (flags[3] == null) { + flags[3] = INDOOR_FLAG; + } else { + throw new IllegalStudyAreaException(DUPLICATE_FLAGS); + } + break; + default: + throw new IllegalStudyAreaException(WRONG_FLAG_USAGE); + } + } else { + if (isNotFlag) { + name.append(commands[i]).append(SPACE); + flags[4] = name.toString().trim(); + } else { + throw new IllegalStudyAreaException(WRONG_FLAG_ARGUMENT_POSITION); + } + } + } + return flags; + } + + /** + * Checks if search key is found in Study Area's Name and Faculty attributes. + * @param name This is the Study Area's Name Attribute. + * @param faculty This is the Study Area's Faculty Attribute. + * @param key This is the search key entered by User. + * @return True if can be found in either case. False if not found in both cases. + */ + + public static boolean containsKey(String name, String faculty, String key) { + if (name.toLowerCase().contains(key.toLowerCase())) { //toLowerCase() so casing does not affect matching. + return true; + } + return faculty.toLowerCase().contains(key.toLowerCase()); // if first check is false, return true depends on + // second check. + } + + /** + * Finds a list of StudyAreas based on User requirements. + * + * @param userIn This is the requirement entered by User + * @return ArrayList of StudyAreas + */ + + public ArrayList searchList(String userIn) throws IllegalStudyAreaException { + String[] temp = userIn.split(MULTIPLE_WHITE_SPACES); + String[] flags = getFlagsInfo(temp); + ArrayList availStudyAreas = new ArrayList<>(); + for (StudyArea studyArea : this.studyAreaList) { + boolean isAvail = true; + for (String flag : flags) { + if (flag != null && isAvail) { + switch (flag) { + case PORTS_FLAG: + isAvail = isAvail && studyArea.hasPort(); + break; + case INDOOR_FLAG: + isAvail = isAvail && studyArea.isIndoor(); + break; + case SIZE_FLAG: + boolean isMaxPax = flags[1].equals(studyArea.getMaxPax().toString()); + isAvail = isAvail && isMaxPax; + break; + default: + isAvail = isAvail && containsKey(studyArea.getName(), studyArea.getFaculty(), flags[4]); + break; + } + } + } + if (isAvail) { + availStudyAreas.add(studyArea); + } + } + return availStudyAreas; + } +} diff --git a/src/main/java/studyarea/Utility.java b/src/main/java/studyarea/Utility.java new file mode 100644 index 000000000..13ff68a53 --- /dev/null +++ b/src/main/java/studyarea/Utility.java @@ -0,0 +1,64 @@ +package studyarea; + +import java.util.StringTokenizer; + +/** + * This class holds all the Utilities required for the Study Area related classes. + */ + +public class Utility { + public static final int MAX_LINE_LENGTH = 55; + public static final int ADDRESS_MAX_LENGTH = 48; + public static final String FLAG = "-"; + public static final String MULTIPLE_WHITE_SPACES = "\\s+"; + public static final String DUPLICATE_FLAGS = "Duplicate flags entered!"; + public static final String SIZE_FLAG = "-s"; + public static final String PORTS_FLAG = "-p"; + public static final String INDOOR_FLAG = "-i"; + public static final String NOT_INTEGER = "Argument used after size flag \"-s\" is not an integer"; + public static final String WRONG_FLAG_USAGE = "Flags indicated are wrongly used. Please enter \"help\" for the" + + " supported flags!"; + public static final String SPACE = " "; + public static final String WRONG_FLAG_ARGUMENT_POSITION = "Flags are to be used only after location"; + public static final String START_STUDY_AREA_SEARCH = "Please enter the location for your desired study area. " + + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" + + " location is entered. When you are done with the search, enter \"end\"."; + public static final String PROMPT_USER = "Please enter the location for your desired study area."; + public static final String FLAGS = "\t Here is a list of supported flags!\n\t -p for study areas with ports\n\t" + + " -i for study areas that are indoors\n\t -s {size} for maximum number of pax"; + public static final String AVAILABLE_STUDY_AREAS = "Here are the available study areas!"; + public static final String EMPTY_LIST = "Oops! Based on your criteria we were not able to find a compatible study" + + "area!"; + public static final String ONLY_FLAG = "Please enter the flag along with \"-\""; + public static final String INCONSISTENT_DATA_STORAGE = "Data is wrongly stored in locations.txt"; + public static final String END_COMMAND = "end"; + public static final String HELP_COMMAND = "help"; + public static final String TAB = "\t "; + public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; + public static final String END_MESSAGE = "Thank you for using our study area search service!"; + + /** + * This method ensures that the message printed is within the standard
+ * length. + * @param message is the String that we intend to format to a standard length
+ * per line.
+ * @param maxLength This is the standard length intended to be formatted. + * @return String of standard length per line + */ + + public static String formatMessage(String message, int maxLength) { + StringTokenizer token = new StringTokenizer(message, SPACE); + StringBuilder standardLengthMessage = new StringBuilder(message.length()); + int lineLength = 0; + while (token.hasMoreTokens()) { + String word = token.nextToken(); + if (lineLength + word.length() > maxLength) { + standardLengthMessage.append("\n\t "); + lineLength = 0; + } + standardLengthMessage.append(word).append(SPACE); + lineLength += word.length() + 1; + } + return TAB + standardLengthMessage.toString().stripTrailing(); + } +} diff --git a/src/test/java/resourceloader/LocationLoaderTest.java b/src/test/java/resourceloader/StudyAreaLoaderTest.java similarity index 65% rename from src/test/java/resourceloader/LocationLoaderTest.java rename to src/test/java/resourceloader/StudyAreaLoaderTest.java index f2349c96a..a2d97de89 100644 --- a/src/test/java/resourceloader/LocationLoaderTest.java +++ b/src/test/java/resourceloader/StudyAreaLoaderTest.java @@ -1,17 +1,18 @@ package resourceloader; import org.junit.jupiter.api.Test; +import studyarea.StudyArea; import java.io.File; import java.io.FileNotFoundException; import static org.junit.jupiter.api.Assertions.assertEquals; -class LocationLoaderTest { +class StudyAreaLoaderTest { - LocationLoader locationLoader = new LocationLoader("library/locations.txt"); + StudyAreaLoader locationLoader = new StudyAreaLoader("library/locations.txt"); - LocationLoaderTest() throws FileNotFoundException { + StudyAreaLoaderTest() throws FileNotFoundException { } @Test diff --git a/src/test/java/studyarea/LocationTest.java b/src/test/java/studyarea/LocationTest.java deleted file mode 100644 index 95080a98e..000000000 --- a/src/test/java/studyarea/LocationTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package studyarea; - -import org.junit.jupiter.api.Test; -import studyarea.Location; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class LocationTest { - - Location location1 = new Location("mac commons", "utown", "nil", true, true, 5); - - LocationTest() throws Exception { - } - - @Test - void getName() { - assertEquals("mac commons", location1.getName()); - } - - @Test - void getAddress() { - assertEquals("utown", location1.getAddress()); - } - - @Test - void getFaculty() { - assertEquals("nil", location1.getFaculty()); - } - - @Test - void hasPort() { - assertEquals(true, location1.hasPort()); - } - - @Test - void isIndoor() { - assertEquals(true, location1.isIndoor()); - } - - @Test - void getMaxPax() { - assertEquals(5, location1.getMaxPax()); - } -} \ No newline at end of file diff --git a/src/test/java/studyarea/StudyAreaListTest.java b/src/test/java/studyarea/StudyAreaListTest.java new file mode 100644 index 000000000..0f719a761 --- /dev/null +++ b/src/test/java/studyarea/StudyAreaListTest.java @@ -0,0 +1,19 @@ +package studyarea; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class StudyAreaListTest { + StudyAreaList studyAreaList = new StudyAreaList(); + + StudyAreaListTest() throws Exception { + } + + @Test + void getStudyAreaList() throws Exception { + assertEquals(new StudyArea("OCBC","2 College Ave West, Stephen Riady Centre", + "-",true,false,2).getAddress(), + studyAreaList.getStudyAreaList().get(1).getAddress()); + } +} \ No newline at end of file diff --git a/src/test/java/studyarea/StudyAreaTest.java b/src/test/java/studyarea/StudyAreaTest.java index 0664f2cdf..e1fb2389a 100644 --- a/src/test/java/studyarea/StudyAreaTest.java +++ b/src/test/java/studyarea/StudyAreaTest.java @@ -5,15 +5,37 @@ import static org.junit.jupiter.api.Assertions.assertEquals; class StudyAreaTest { - StudyArea studyArea = new StudyArea(); - StudyAreaTest() throws Exception { + StudyArea location1 = new StudyArea("mac commons", "utown", "nil", true, true, + 5); + + @Test + void getAddress() { + assertEquals("utown", location1.getAddress()); + } + + @Test + void getFaculty() { + assertEquals("nil", location1.getFaculty()); + } + + @Test + void hasPort() { + assertEquals(true, location1.hasPort()); + } + + @Test + void isIndoor() { + assertEquals(true, location1.isIndoor()); + } + + @Test + void getMaxPax() { + assertEquals(5, location1.getMaxPax()); } @Test - void getLocationList() throws Exception { - assertEquals(new Location("OCBC","2 College Ave West, Stephen Riady Centre", - "-",true,false,2).getAddress(), - studyArea.getLocationsList().get(1).getAddress()); + void getName() { + assertEquals("mac commons", location1.getName()); } } \ No newline at end of file From 5a35713000a6cd32b074fbd5ee1dae7d0aa69df5 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sun, 8 Mar 2020 14:28:06 +0800 Subject: [PATCH 030/435] include location.txt --- library/locations.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/locations.txt b/library/locations.txt index d70644e90..42de138ad 100644 --- a/library/locations.txt +++ b/library/locations.txt @@ -1,2 +1,8 @@ -MacCommons 2 College Ave West Education Resource Centre - true true 5 -OCBC 2 College Ave West, Stephen Riady Centre - true false 2 \ No newline at end of file +MacCommons~2 College Ave West Education Resource Centre~Utown~true~true~5 +OCBC~2 College Ave West, Stephen Riady Centre~Utown~true~false~2 +EA Level 3~9 Engineering Drive 1,EA~Engineering~true~true~4 +EA Level 2~9 Engineering Drive 1~Engineering~true~true~4 +EA Level 1~9 Engineering Drive 1~Engineering~true~true~4 +EA Level 4~9 Engineering Drive 1, Outside Staff Offices~Engineering~true~false~6 +EA Level 5~9 Engineering Drive 1, Outside of the door beside EA05~Engineering~true~false~4 +EA Level 6~9 Engineering Drive 1, EA06-23~Engineering~true~true~4 \ No newline at end of file From 5c8af2cf81811e41068d2c6ea5d404c696ed151e Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sun, 8 Mar 2020 15:05:29 +0800 Subject: [PATCH 031/435] Implement Study Area Version 1.0 --- src/main/java/studyarea/StudyAreaCommand.java | 3 +-- src/main/java/studyarea/StudyAreaList.java | 15 ++++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/studyarea/StudyAreaCommand.java b/src/main/java/studyarea/StudyAreaCommand.java index ddfe56caa..bdee92cf7 100644 --- a/src/main/java/studyarea/StudyAreaCommand.java +++ b/src/main/java/studyarea/StudyAreaCommand.java @@ -58,10 +58,9 @@ public static boolean filterCommand(String command,StudyAreaList studyAreaList) try { ArrayList availStudyAreas = studyAreaList.searchList(command); printList(availStudyAreas); + System.out.println(formatMessage(PROMPT_USER, MAX_LINE_LENGTH)); } catch (IllegalStudyAreaException e) { System.out.println(formatMessage(e.getMessage(), MAX_LINE_LENGTH)); - } finally { - System.out.println(formatMessage(PROMPT_USER, MAX_LINE_LENGTH)); } } return true; diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 91681ce2e..0274669fe 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -3,6 +3,8 @@ import resourceloader.StudyAreaLoader; import java.io.FileNotFoundException; import java.util.ArrayList; +import java.util.Arrays; + import static studyarea.Utility.DUPLICATE_FLAGS; import static studyarea.Utility.FLAG; import static studyarea.Utility.INDOOR_FLAG; @@ -67,6 +69,7 @@ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException if (flags[0] == null) { flags[0] = SIZE_FLAG; flags[1] = Integer.toString(size); + i++; } else { throw new IllegalStudyAreaException(DUPLICATE_FLAGS); } @@ -74,8 +77,6 @@ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException throw new IllegalStudyAreaException(NOT_INTEGER); } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalStudyAreaException(NO_SIZE_INDICATED); - } finally { - i++; } } else if (commands[i].contains(FLAG)) { isNotFlag = false; @@ -145,17 +146,17 @@ public ArrayList searchList(String userIn) throws IllegalStudyAreaExc if (flag != null && isAvail) { switch (flag) { case PORTS_FLAG: - isAvail = isAvail && studyArea.hasPort(); + isAvail = studyArea.hasPort(); break; case INDOOR_FLAG: - isAvail = isAvail && studyArea.isIndoor(); + isAvail = studyArea.isIndoor(); break; case SIZE_FLAG: - boolean isMaxPax = flags[1].equals(studyArea.getMaxPax().toString()); - isAvail = isAvail && isMaxPax; + isAvail = Integer.toString(studyArea.getMaxPax()).equals(flags[1]); + flags[1] = null; //so as to skip iteration on flags[1]. break; default: - isAvail = isAvail && containsKey(studyArea.getName(), studyArea.getFaculty(), flags[4]); + isAvail = containsKey(studyArea.getName(), studyArea.getFaculty(), flags[4]); break; } } From 90b8d5b17c3c4ea47c0174e8b51126bb7fd55c50 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sun, 8 Mar 2020 22:54:30 +0800 Subject: [PATCH 032/435] Change Logo and edit Javadoc --- .../java/resourceloader/StudyAreaLoader.java | 1 + src/main/java/seedu/duke/Duke.java | 31 +++++++++++--- src/main/java/studyarea/StudyAreaCommand.java | 41 +++++++++++-------- src/main/java/studyarea/StudyAreaList.java | 4 +- src/main/java/studyarea/Utility.java | 4 ++ 5 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index f6e321451..7ead32e41 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -44,6 +44,7 @@ public File getFile() { * * @return buffer ArrayList of Location from study area file * @throws FileNotFoundException if location.txt does not exist. + * @throws IllegalStudyAreaException if data stored is inconsistent */ public ArrayList pushToDatabase() throws FileNotFoundException, IllegalStudyAreaException { diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 6cf84ab93..63113af82 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -24,13 +24,32 @@ public class Duke { /** * Main entry-point for the java.duke.Duke application. + * @param args this is an optional argument. */ - public static void main(String[] args) throws Exception { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; + public static void main(String[] args) { + String logo = "_______/\\\\\\\\\\_____________________________________________________/\\\\\\\\\\_____/\\\\\\__" + + "__________________________________________/\\\\\\____________\n" + + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" + + "_________________________________________/\\\\\\\\\\\\\\_________\n" + + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" + + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______\n" + + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" + + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\_______\n" + + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" + + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" + + "___\n" + + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" + + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" + + "_____\n" + + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" + + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______\n" + + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\\\/\\\\" + + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" + + "_/\\\\\\_____\n" + + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" + + "_\\///______\\////////_____\\//////////______\\///_____"; System.out.println("Hello from\n" + logo); System.out.println("What is your name?"); diff --git a/src/main/java/studyarea/StudyAreaCommand.java b/src/main/java/studyarea/StudyAreaCommand.java index bdee92cf7..4e7ac847b 100644 --- a/src/main/java/studyarea/StudyAreaCommand.java +++ b/src/main/java/studyarea/StudyAreaCommand.java @@ -5,7 +5,9 @@ import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; + import static studyarea.Utility.AVAILABLE_STUDY_AREAS; +import static studyarea.Utility.EMPTY_COMMAND; import static studyarea.Utility.EMPTY_LIST; import static studyarea.Utility.END_COMMAND; import static studyarea.Utility.END_MESSAGE; @@ -44,26 +46,33 @@ public static void printList(ArrayList availStudyAreas) { * @param command This is the command entered by User. * @param studyAreaList This is the list of all Study Areas in location.txt. * @return boolean status. False if User enters "end" , else will always return true; + * @throws IllegalStudyAreaException if command is invalid. */ - public static boolean filterCommand(String command,StudyAreaList studyAreaList) { - switch (command) { - case END_COMMAND : - System.out.println(formatMessage(END_MESSAGE, MAX_LINE_LENGTH)); - return false; - case HELP_COMMAND : - System.out.println(FLAGS); - break; - default: - try { - ArrayList availStudyAreas = studyAreaList.searchList(command); - printList(availStudyAreas); - System.out.println(formatMessage(PROMPT_USER, MAX_LINE_LENGTH)); - } catch (IllegalStudyAreaException e) { - System.out.println(formatMessage(e.getMessage(), MAX_LINE_LENGTH)); + public static boolean filterCommand(String command,StudyAreaList studyAreaList) throws IllegalStudyAreaException { + + command = command.trim(); + if (command.isEmpty()) { + throw new IllegalStudyAreaException(EMPTY_COMMAND); + } else { + switch (command) { + case END_COMMAND: + System.out.println(formatMessage(END_MESSAGE, MAX_LINE_LENGTH)); + return false; + case HELP_COMMAND: + System.out.println(FLAGS); + break; + default: + try { + ArrayList availStudyAreas = studyAreaList.searchList(command); + printList(availStudyAreas); + System.out.println(formatMessage(PROMPT_USER, MAX_LINE_LENGTH)); + } catch (IllegalStudyAreaException e) { + System.out.println(formatMessage(e.getMessage(), MAX_LINE_LENGTH)); + } } + return true; } - return true; } /** diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 0274669fe..3c45789cd 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -30,7 +30,8 @@ public class StudyAreaList { * LocationLoader class. The file is then load onto the software and then * parsed as an ArrayList to be stored in location in this StudyArea class. * - * @throws FileNotFoundException to be edited + * @throws FileNotFoundException if location.txt is missing. + * @throws IllegalStudyAreaException if data stored in location.txt is inconsistent. */ public StudyAreaList() throws FileNotFoundException, IllegalStudyAreaException { @@ -134,6 +135,7 @@ public static boolean containsKey(String name, String faculty, String key) { * * @param userIn This is the requirement entered by User * @return ArrayList of StudyAreas + * @throws IllegalStudyAreaException if User enters invalid commands */ public ArrayList searchList(String userIn) throws IllegalStudyAreaException { diff --git a/src/main/java/studyarea/Utility.java b/src/main/java/studyarea/Utility.java index 13ff68a53..c0b97c890 100644 --- a/src/main/java/studyarea/Utility.java +++ b/src/main/java/studyarea/Utility.java @@ -1,5 +1,7 @@ package studyarea; +import java.util.HashMap; +import java.util.HashSet; import java.util.StringTokenizer; /** @@ -36,6 +38,7 @@ public class Utility { public static final String TAB = "\t "; public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; + public static final String EMPTY_COMMAND = "Command entered is empty!"; /** * This method ensures that the message printed is within the standard
@@ -61,4 +64,5 @@ public static String formatMessage(String message, int maxLength) { } return TAB + standardLengthMessage.toString().stripTrailing(); } + } From 874c983a2738c9346cb89858d89db61b7e5751d0 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Sun, 8 Mar 2020 23:52:33 +0800 Subject: [PATCH 033/435] Merge Event, StudyArea --- library/eventList.txt | 1 - src/main/java/command/EventCommand.java | 63 ++++++++++ .../StudyAreaCommand.java | 51 +++----- src/main/java/driver/Driver.java | 43 +++++++ src/main/java/resourceloader/Loader.java | 17 --- .../java/resourceloader/StudyAreaLoader.java | 18 ++- src/main/java/seedu/duke/Duke.java | 85 ++----------- src/main/java/studyarea/StudyArea.java | 20 +-- src/main/java/studyarea/StudyAreaList.java | 116 ++++++++---------- src/main/java/studyarea/Utility.java | 64 ---------- src/main/java/ui/Ui.java | 76 +++++++++++- .../resourceloader/StudyAreaLoaderTest.java | 23 ---- .../java/studyarea/StudyAreaListTest.java | 19 --- 13 files changed, 278 insertions(+), 318 deletions(-) create mode 100644 src/main/java/command/EventCommand.java rename src/main/java/{studyarea => command}/StudyAreaCommand.java (50%) create mode 100644 src/main/java/driver/Driver.java delete mode 100644 src/main/java/resourceloader/Loader.java delete mode 100644 src/main/java/studyarea/Utility.java delete mode 100644 src/test/java/resourceloader/StudyAreaLoaderTest.java delete mode 100644 src/test/java/studyarea/StudyAreaListTest.java diff --git a/library/eventList.txt b/library/eventList.txt index 8b1378917..e69de29bb 100644 --- a/library/eventList.txt +++ b/library/eventList.txt @@ -1 +0,0 @@ - diff --git a/src/main/java/command/EventCommand.java b/src/main/java/command/EventCommand.java new file mode 100644 index 000000000..9e9c98ef9 --- /dev/null +++ b/src/main/java/command/EventCommand.java @@ -0,0 +1,63 @@ +package command; + +import event.EventList; +import ui.Ui; + +import java.util.Scanner; + +public class EventCommand { + + /** + * Commands for Events. + * + * @param eventList evenList + */ + public static void runCommands(EventList eventList) { + Scanner in = new Scanner(System.in); + String command; + command = in.nextLine(); + while (!command.equals(Ui.BYE_COMMAND)) { + try { + String commandType = command.split(" ")[0]; + switch (commandType) { + case Ui.ADD_COMMAND: + eventList.add(command); + break; + case Ui.VIEW_COMMAND: + eventList.listEvents(); + break; + case Ui.PRIORITY_VIEW_COMMAND: + eventList.priorityView(); + break; + case Ui.COUNTDOWN_VIEW_COMMAND: + eventList.countdownView(); + break; + case Ui.CLEAR_COMMAND: + eventList.clearEvents(); + break; + case Ui.SEARCH_COMMAND: + eventList.searchEvents(command.split(" ", 2)[1]); + break; + case Ui.DELETE_COMMAND: + eventList.deleteEvent(Integer.parseInt(command.split(" ", 2)[1])); + break; + default: + Ui.printLine(); + System.out.println(Ui.INVALID_COMMAND_MESSAGE); + Ui.printLine(); + break; + } + } catch (NumberFormatException e) { + Ui.printLine(); + System.out.println(Ui.INVALID_INDEX_MESSAGE); + Ui.printLine(); + } catch (IndexOutOfBoundsException e) { + Ui.printLine(); + System.out.println(Ui.INVALID_COMMAND_MESSAGE); + Ui.printLine(); + } + command = in.nextLine(); + } + System.out.println(Ui.BYE_MESSAGE); + } +} diff --git a/src/main/java/studyarea/StudyAreaCommand.java b/src/main/java/command/StudyAreaCommand.java similarity index 50% rename from src/main/java/studyarea/StudyAreaCommand.java rename to src/main/java/command/StudyAreaCommand.java index bdee92cf7..be6c63ff0 100644 --- a/src/main/java/studyarea/StudyAreaCommand.java +++ b/src/main/java/command/StudyAreaCommand.java @@ -1,20 +1,13 @@ -package studyarea; +package command; +import studyarea.IllegalStudyAreaException; +import studyarea.StudyArea; +import studyarea.StudyAreaList; import ui.Ui; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; -import static studyarea.Utility.AVAILABLE_STUDY_AREAS; -import static studyarea.Utility.EMPTY_LIST; -import static studyarea.Utility.END_COMMAND; -import static studyarea.Utility.END_MESSAGE; -import static studyarea.Utility.FLAGS; -import static studyarea.Utility.HELP_COMMAND; -import static studyarea.Utility.MAX_LINE_LENGTH; -import static studyarea.Utility.PROMPT_USER; -import static studyarea.Utility.START_STUDY_AREA_SEARCH; -import static studyarea.Utility.formatMessage; /** * This is the Study Area Command class. It executes the Study Area Search function and interact with Users accordingly. @@ -26,12 +19,11 @@ public class StudyAreaCommand { * List out all the study areas that match with User's preference. * @param availStudyAreas this is the list of all study areas in location.txt. */ - public static void printList(ArrayList availStudyAreas) { if (availStudyAreas.isEmpty()) { - System.out.println(formatMessage(EMPTY_LIST, MAX_LINE_LENGTH)); + System.out.println(Ui.formatMessage(Ui.EMPTY_LIST, Ui.MAX_LINE_LENGTH)); } else { - System.out.println(formatMessage(AVAILABLE_STUDY_AREAS, MAX_LINE_LENGTH)); + System.out.println(Ui.formatMessage(Ui.AVAILABLE_STUDY_AREAS, Ui.MAX_LINE_LENGTH)); for (StudyArea studyArea : availStudyAreas) { System.out.println(studyArea.toString()); } @@ -46,21 +38,21 @@ public static void printList(ArrayList availStudyAreas) { * @return boolean status. False if User enters "end" , else will always return true; */ - public static boolean filterCommand(String command,StudyAreaList studyAreaList) { + public static boolean filterCommand(String command, StudyAreaList studyAreaList) { switch (command) { - case END_COMMAND : - System.out.println(formatMessage(END_MESSAGE, MAX_LINE_LENGTH)); + case Ui.END_COMMAND : + System.out.println(Ui.formatMessage(Ui.END_MESSAGE, Ui.MAX_LINE_LENGTH)); return false; - case HELP_COMMAND : - System.out.println(FLAGS); + case Ui.HELP_COMMAND : + System.out.println(Ui.FLAGS); break; default: try { ArrayList availStudyAreas = studyAreaList.searchList(command); printList(availStudyAreas); - System.out.println(formatMessage(PROMPT_USER, MAX_LINE_LENGTH)); + System.out.println(Ui.formatMessage(Ui.PROMPT_USER, Ui.MAX_LINE_LENGTH)); } catch (IllegalStudyAreaException e) { - System.out.println(formatMessage(e.getMessage(), MAX_LINE_LENGTH)); + System.out.println(Ui.formatMessage(e.getMessage(), Ui.MAX_LINE_LENGTH)); } } return true; @@ -68,26 +60,21 @@ public static boolean filterCommand(String command,StudyAreaList studyAreaList) /** * Executes the Study Area search feature. - * @param args this is temporary. - * @throws FileNotFoundException If location.txt does not ext, this exception is thrown. - * @throws IllegalStudyAreaException If data is inconsistent while loading available list, this exception is thrown. + * @param studyAreaList studyAreaList object that holds information on studyAreas available. */ - - public static void main(String[] args) throws FileNotFoundException, IllegalStudyAreaException { + public static void runCommands(StudyAreaList studyAreaList) { Ui ui = new Ui(); ui.printLine(); - System.out.println(formatMessage(START_STUDY_AREA_SEARCH, MAX_LINE_LENGTH)); + System.out.println(Ui.formatMessage(Ui.START_STUDY_AREA_SEARCH, Ui.MAX_LINE_LENGTH)); Scanner in = new Scanner(System.in); - StudyAreaList studyAreaList = new StudyAreaList(); boolean status = true; while (status) { - ui.printLine(); + Ui.printLine(); String command = in.nextLine(); - ui.printLine(); + Ui.printLine(); status = filterCommand(command, studyAreaList); } - ui.printLine(); - in.close(); + Ui.printLine(); } } diff --git a/src/main/java/driver/Driver.java b/src/main/java/driver/Driver.java new file mode 100644 index 000000000..a09b7c01a --- /dev/null +++ b/src/main/java/driver/Driver.java @@ -0,0 +1,43 @@ +package driver; + +import command.EventCommand; +import event.EventList; +import java.io.FileNotFoundException; + +import resourceloader.EventLoader; +import resourceloader.StudyAreaLoader; +import studyarea.IllegalStudyAreaException; +import command.StudyAreaCommand; +import studyarea.StudyAreaList; +import ui.Ui; + +public class Driver { + public static EventLoader eventLoader; + public static StudyAreaLoader studyAreaLoader; + + /** + * Constructor for Driver Class. + * This class setups the loading of events and study areas into + * the program and runs either study area or organiser functionality. + * + * @param mode 1 for organiser, 0 for study area + * @throws FileNotFoundException if file is not found. + * @throws IllegalStudyAreaException custom exception for study area + */ + public Driver(int mode) throws FileNotFoundException, IllegalStudyAreaException { + eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); + EventList eventList = new EventList(eventLoader.loadFile()); + + studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); + StudyAreaList studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); + + if (mode == 1) { + EventCommand eventCommand = new EventCommand(); + eventCommand.runCommands(eventList); + eventLoader.saveEvents(eventList.events); + } else { + StudyAreaCommand studyAreaCommand = new StudyAreaCommand(); + studyAreaCommand.runCommands(studyAreaList); + } + } +} diff --git a/src/main/java/resourceloader/Loader.java b/src/main/java/resourceloader/Loader.java deleted file mode 100644 index 74be1aec7..000000000 --- a/src/main/java/resourceloader/Loader.java +++ /dev/null @@ -1,17 +0,0 @@ -package resourceloader; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; - -/** - * Loader is a resource loader for all the external data that is within our java program. - * Examples of resources will be task data, study locations etc.. - * Loader is an interface that enables subsequent loaders to be made and disciplined, - * i.e. locationsLoader, organiserLoader.. - */ -public interface Loader { - public void loadFile() throws FileNotFoundException; - - public File getFile(); -} diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index f6e321451..0cee4dcc5 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -2,19 +2,18 @@ import studyarea.IllegalStudyAreaException; import studyarea.StudyArea; +import ui.Ui; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; -import static studyarea.Utility.INCONSISTENT_DATA_STORAGE; - /** * This class loads all the required information of Study Areas that is stored in location.txt. */ -public class StudyAreaLoader implements Loader { +public class StudyAreaLoader { private static final String DIVIDER = "~"; private final String url; private File file; @@ -24,7 +23,11 @@ public StudyAreaLoader(String url) throws FileNotFoundException { loadFile(); } - @Override + /** + * Loads url into file. + * + * @throws FileNotFoundException if file is not present error + */ public void loadFile() throws FileNotFoundException { try { file = new File(url); @@ -33,11 +36,6 @@ public void loadFile() throws FileNotFoundException { } } - @Override - public File getFile() { - return this.file; - } - /** * Return the imported study area file as an ArrayList for the main controller * to add it to its database. @@ -53,7 +51,7 @@ public ArrayList pushToDatabase() throws FileNotFoundException, Illeg String detailsOfLocation = input.nextLine(); String[] detailsBuffer = detailsOfLocation.split(DIVIDER); if (detailsBuffer.length != 6) { - throw new IllegalStudyAreaException(INCONSISTENT_DATA_STORAGE); + throw new IllegalStudyAreaException(Ui.INCONSISTENT_DATA_STORAGE); } StudyArea studyArea = new StudyArea(detailsBuffer[0], detailsBuffer[1], detailsBuffer[2], Boolean.parseBoolean(detailsBuffer[3]), Boolean.parseBoolean(detailsBuffer[4]), diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 29d29d93d..0b47e8ba3 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,30 +1,10 @@ package seedu.duke; -import event.EventList; -import resourceloader.EventLoader; -import ui.Ui; - -import java.io.File; +import driver.Driver; import java.util.Scanner; public class Duke { - private static final String FILE_PATH = "library" + File.separator + "eventList.txt"; - public static Ui ui = new Ui(); - public static EventLoader eventLoader; - public static final String ADD_COMMAND = "add"; - public static final String VIEW_COMMAND = "view"; - public static final String PRIORITY_VIEW_COMMAND = "priority_view"; - public static final String COUNTDOWN_VIEW_COMMAND = "countdown"; - public static final String CLEAR_COMMAND = "clear"; - public static final String SEARCH_COMMAND = "search"; - public static final String DELETE_COMMAND = "delete"; - public static final String INVALID_INDEX_MESSAGE = "Enter a valid index"; - public static final String INVALID_COMMAND_MESSAGE = "Enter a valid command"; - public static final String BYE_COMMAND = "bye"; - public static final String BYE_MESSAGE = "Bye!!!!!!"; - static EventList eventList; - /** * Main entry-point for the java.duke.Duke application. */ @@ -39,58 +19,19 @@ public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); System.out.println("Hello " + in.nextLine()); - eventLoader = new EventLoader(FILE_PATH); - eventList = new EventList(eventLoader.loadFile()); - runCommands(); - eventLoader.saveEvents(eventList.events); - } - private static void runCommands() { - Scanner in = new Scanner(System.in); - String command; - command = in.nextLine(); - while (!command.equals(BYE_COMMAND)) { - try { - String commandType = command.split(" ")[0]; - switch (commandType) { - case ADD_COMMAND: - eventList.add(command); - break; - case VIEW_COMMAND: - eventList.listEvents(); - break; - case PRIORITY_VIEW_COMMAND: - eventList.priorityView(); - break; - case COUNTDOWN_VIEW_COMMAND: - eventList.countdownView(); - break; - case CLEAR_COMMAND: - eventList.clearEvents(); - break; - case SEARCH_COMMAND: - eventList.searchEvents(command.split(" ", 2)[1]); - break; - case DELETE_COMMAND: - eventList.deleteEvent(Integer.parseInt(command.split(" ", 2)[1])); - break; - default: - ui.printLine(); - System.out.println(INVALID_COMMAND_MESSAGE); - ui.printLine(); - break; - } - } catch (NumberFormatException e) { - ui.printLine(); - System.out.println(INVALID_INDEX_MESSAGE); - ui.printLine(); - } catch (IndexOutOfBoundsException e) { - ui.printLine(); - System.out.println(INVALID_COMMAND_MESSAGE); - ui.printLine(); - } - command = in.nextLine(); + /** + * To run: + * events: enter 1 + * study areas: enter 0 + * To end events loop: enter bye in events prog + * To end study areas loop: enter end in study area loop + * To end overall prog, enter ctrl+c or ctrl+z + * Take note: this is still temporary + */ + while (true) { + Scanner mode = new Scanner(System.in); + Driver driver = new Driver(mode.nextInt()); } - System.out.println(BYE_MESSAGE); } } diff --git a/src/main/java/studyarea/StudyArea.java b/src/main/java/studyarea/StudyArea.java index 1760fbdca..b6eb7895f 100644 --- a/src/main/java/studyarea/StudyArea.java +++ b/src/main/java/studyarea/StudyArea.java @@ -1,9 +1,9 @@ package studyarea; +import ui.Ui; + import static java.lang.System.lineSeparator; -import static studyarea.Utility.ADDRESS_MAX_LENGTH; -import static studyarea.Utility.TAB; -import static studyarea.Utility.formatMessage; + /** * This is the Study Area class. All study area is stored as a Study Area object. @@ -32,7 +32,7 @@ public class StudyArea { public StudyArea(String name, String address, String faculty, boolean hasPort, boolean isIndoor, int maxPax) { this.name = name; - this.address = formatMessage(address, ADDRESS_MAX_LENGTH).trim(); + this.address = Ui.formatMessage(address, Ui.ADDRESS_MAX_LENGTH).trim(); this.faculty = faculty; this.hasPort = hasPort; this.isIndoor = isIndoor; @@ -68,13 +68,13 @@ public Integer getMaxPax() { * @return String value of all the attributes of the specific StudyArea. */ public String toString() { - String text = TAB + "Name: " + this.name + lineSeparator() + TAB - + "Address: " + this.address + lineSeparator() + TAB - + "Faculty: " + this.faculty + lineSeparator() + TAB - + "Port: " + this.hasPort + lineSeparator() + TAB - + "Indoor: " + this.isIndoor + lineSeparator() + TAB + String text = Ui.TAB + "Name: " + this.name + lineSeparator() + Ui.TAB + + "Address: " + this.address + lineSeparator() + Ui.TAB + + "Faculty: " + this.faculty + lineSeparator() + Ui.TAB + + "Port: " + this.hasPort + lineSeparator() + Ui.TAB + + "Indoor: " + this.isIndoor + lineSeparator() + Ui.TAB + "Average number of Pax: " + this.maxPax; - String line = TAB + "__________________________________________________________"; + String line = Ui.TAB + "__________________________________________________________"; return line + lineSeparator() + text + lineSeparator() + line; } diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 0274669fe..2f36b914c 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -1,22 +1,9 @@ package studyarea; -import resourceloader.StudyAreaLoader; +import ui.Ui; + import java.io.FileNotFoundException; import java.util.ArrayList; -import java.util.Arrays; - -import static studyarea.Utility.DUPLICATE_FLAGS; -import static studyarea.Utility.FLAG; -import static studyarea.Utility.INDOOR_FLAG; -import static studyarea.Utility.MULTIPLE_WHITE_SPACES; -import static studyarea.Utility.NOT_INTEGER; -import static studyarea.Utility.NO_SIZE_INDICATED; -import static studyarea.Utility.ONLY_FLAG; -import static studyarea.Utility.PORTS_FLAG; -import static studyarea.Utility.SIZE_FLAG; -import static studyarea.Utility.SPACE; -import static studyarea.Utility.WRONG_FLAG_ARGUMENT_POSITION; -import static studyarea.Utility.WRONG_FLAG_USAGE; /** * This is the class that stores and manages all of the Study Areas in location.txt @@ -25,18 +12,9 @@ public class StudyAreaList { private ArrayList studyAreaList; - /** - * Setup a resource loader to import the file by creating a new - * LocationLoader class. The file is then load onto the software and then - * parsed as an ArrayList to be stored in location in this StudyArea class. - * - * @throws FileNotFoundException to be edited - */ - - public StudyAreaList() throws FileNotFoundException, IllegalStudyAreaException { - StudyAreaLoader studyAreaLoader = new StudyAreaLoader("library/locations.txt"); - studyAreaLoader.loadFile(); - this.studyAreaList = studyAreaLoader.pushToDatabase(); + // Assigns studyAreaList into object's studyAreaList. + public StudyAreaList(ArrayList studyAreaList) { + this.studyAreaList = studyAreaList; } /** @@ -44,7 +22,6 @@ public StudyAreaList() throws FileNotFoundException, IllegalStudyAreaException { * * @return ArrayList of StudyAreas. */ - public ArrayList getStudyAreaList() { return this.studyAreaList; } @@ -56,57 +33,56 @@ public ArrayList getStudyAreaList() { * @return String Array of a fixed size of 5 * @throws IllegalStudyAreaException when arguments for flags are invalid. */ - public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException { String[] flags = new String[5]; StringBuilder name = new StringBuilder(); boolean isNotFlag = true; for (int i = 0; i < commands.length; i++) { - if (commands[i].equals(SIZE_FLAG)) { + if (commands[i].equals(Ui.SIZE_FLAG)) { isNotFlag = false; try { int size = Integer.parseInt(commands[i + 1]); if (flags[0] == null) { - flags[0] = SIZE_FLAG; + flags[0] = Ui.SIZE_FLAG; flags[1] = Integer.toString(size); i++; } else { - throw new IllegalStudyAreaException(DUPLICATE_FLAGS); + throw new IllegalStudyAreaException(Ui.DUPLICATE_FLAGS); } } catch (NumberFormatException e) { - throw new IllegalStudyAreaException(NOT_INTEGER); + throw new IllegalStudyAreaException(Ui.NOT_INTEGER); } catch (ArrayIndexOutOfBoundsException e) { - throw new IllegalStudyAreaException(NO_SIZE_INDICATED); + throw new IllegalStudyAreaException(Ui.NO_SIZE_INDICATED); } - } else if (commands[i].contains(FLAG)) { + } else if (commands[i].contains(Ui.FLAG)) { isNotFlag = false; if (commands[i].length() == 1) { - throw new IllegalStudyAreaException(ONLY_FLAG); + throw new IllegalStudyAreaException(Ui.ONLY_FLAG); } switch (commands[i].charAt(1)) { case 'p': if (flags[2] == null) { - flags[2] = PORTS_FLAG; + flags[2] = Ui.PORTS_FLAG; } else { - throw new IllegalStudyAreaException(DUPLICATE_FLAGS); + throw new IllegalStudyAreaException(Ui.DUPLICATE_FLAGS); } break; case 'i': if (flags[3] == null) { - flags[3] = INDOOR_FLAG; + flags[3] = Ui.INDOOR_FLAG; } else { - throw new IllegalStudyAreaException(DUPLICATE_FLAGS); + throw new IllegalStudyAreaException(Ui.DUPLICATE_FLAGS); } break; default: - throw new IllegalStudyAreaException(WRONG_FLAG_USAGE); + throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); } } else { if (isNotFlag) { - name.append(commands[i]).append(SPACE); + name.append(commands[i]).append(Ui.SPACE); flags[4] = name.toString().trim(); } else { - throw new IllegalStudyAreaException(WRONG_FLAG_ARGUMENT_POSITION); + throw new IllegalStudyAreaException(Ui.WRONG_FLAG_ARGUMENT_POSITION); } } } @@ -137,34 +113,38 @@ public static boolean containsKey(String name, String faculty, String key) { */ public ArrayList searchList(String userIn) throws IllegalStudyAreaException { - String[] temp = userIn.split(MULTIPLE_WHITE_SPACES); - String[] flags = getFlagsInfo(temp); - ArrayList availStudyAreas = new ArrayList<>(); - for (StudyArea studyArea : this.studyAreaList) { - boolean isAvail = true; - for (String flag : flags) { - if (flag != null && isAvail) { - switch (flag) { - case PORTS_FLAG: - isAvail = studyArea.hasPort(); - break; - case INDOOR_FLAG: - isAvail = studyArea.isIndoor(); - break; - case SIZE_FLAG: - isAvail = Integer.toString(studyArea.getMaxPax()).equals(flags[1]); - flags[1] = null; //so as to skip iteration on flags[1]. - break; - default: - isAvail = containsKey(studyArea.getName(), studyArea.getFaculty(), flags[4]); - break; + try { + String[] temp = userIn.split(Ui.MULTIPLE_WHITE_SPACES); + String[] flags = getFlagsInfo(temp); + ArrayList availStudyAreas = new ArrayList<>(); + for (StudyArea studyArea : this.studyAreaList) { + boolean isAvail = true; + for (String flag : flags) { + if (flag != null && isAvail) { + switch (flag) { + case Ui.PORTS_FLAG: + isAvail = studyArea.hasPort(); + break; + case Ui.INDOOR_FLAG: + isAvail = studyArea.isIndoor(); + break; + case Ui.SIZE_FLAG: + isAvail = Integer.toString(studyArea.getMaxPax()).equals(flags[1]); + flags[1] = null; //so as to skip iteration on flags[1]. + break; + default: + isAvail = containsKey(studyArea.getName(), studyArea.getFaculty(), flags[4]); + break; + } } } + if (isAvail) { + availStudyAreas.add(studyArea); + } } - if (isAvail) { - availStudyAreas.add(studyArea); - } + return availStudyAreas; + } catch (Exception e) { + throw new IllegalStudyAreaException(e.getMessage()); } - return availStudyAreas; } } diff --git a/src/main/java/studyarea/Utility.java b/src/main/java/studyarea/Utility.java deleted file mode 100644 index 13ff68a53..000000000 --- a/src/main/java/studyarea/Utility.java +++ /dev/null @@ -1,64 +0,0 @@ -package studyarea; - -import java.util.StringTokenizer; - -/** - * This class holds all the Utilities required for the Study Area related classes. - */ - -public class Utility { - public static final int MAX_LINE_LENGTH = 55; - public static final int ADDRESS_MAX_LENGTH = 48; - public static final String FLAG = "-"; - public static final String MULTIPLE_WHITE_SPACES = "\\s+"; - public static final String DUPLICATE_FLAGS = "Duplicate flags entered!"; - public static final String SIZE_FLAG = "-s"; - public static final String PORTS_FLAG = "-p"; - public static final String INDOOR_FLAG = "-i"; - public static final String NOT_INTEGER = "Argument used after size flag \"-s\" is not an integer"; - public static final String WRONG_FLAG_USAGE = "Flags indicated are wrongly used. Please enter \"help\" for the" - + " supported flags!"; - public static final String SPACE = " "; - public static final String WRONG_FLAG_ARGUMENT_POSITION = "Flags are to be used only after location"; - public static final String START_STUDY_AREA_SEARCH = "Please enter the location for your desired study area. " - + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" - + " location is entered. When you are done with the search, enter \"end\"."; - public static final String PROMPT_USER = "Please enter the location for your desired study area."; - public static final String FLAGS = "\t Here is a list of supported flags!\n\t -p for study areas with ports\n\t" - + " -i for study areas that are indoors\n\t -s {size} for maximum number of pax"; - public static final String AVAILABLE_STUDY_AREAS = "Here are the available study areas!"; - public static final String EMPTY_LIST = "Oops! Based on your criteria we were not able to find a compatible study" - + "area!"; - public static final String ONLY_FLAG = "Please enter the flag along with \"-\""; - public static final String INCONSISTENT_DATA_STORAGE = "Data is wrongly stored in locations.txt"; - public static final String END_COMMAND = "end"; - public static final String HELP_COMMAND = "help"; - public static final String TAB = "\t "; - public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; - public static final String END_MESSAGE = "Thank you for using our study area search service!"; - - /** - * This method ensures that the message printed is within the standard
- * length. - * @param message is the String that we intend to format to a standard length
- * per line.
- * @param maxLength This is the standard length intended to be formatted. - * @return String of standard length per line - */ - - public static String formatMessage(String message, int maxLength) { - StringTokenizer token = new StringTokenizer(message, SPACE); - StringBuilder standardLengthMessage = new StringBuilder(message.length()); - int lineLength = 0; - while (token.hasMoreTokens()) { - String word = token.nextToken(); - if (lineLength + word.length() > maxLength) { - standardLengthMessage.append("\n\t "); - lineLength = 0; - } - standardLengthMessage.append(word).append(SPACE); - lineLength += word.length() + 1; - } - return TAB + standardLengthMessage.toString().stripTrailing(); - } -} diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 7a0c4d296..5230437b1 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -1,18 +1,90 @@ package ui; +import java.io.File; +import java.util.StringTokenizer; + /** * Contains functions used to interact with the user. */ public class Ui { + public static final String FILE_PATH_EVENTS = "library" + File.separator + "eventList.txt"; + public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; + + public static final String ADD_COMMAND = "add"; + public static final String VIEW_COMMAND = "view"; + public static final String PRIORITY_VIEW_COMMAND = "priority_view"; + public static final String COUNTDOWN_VIEW_COMMAND = "countdown"; + public static final String CLEAR_COMMAND = "clear"; + public static final String SEARCH_COMMAND = "search"; + public static final String DELETE_COMMAND = "delete"; + public static final String INVALID_INDEX_MESSAGE = "Enter a valid index"; + public static final String INVALID_COMMAND_MESSAGE = "Enter a valid command"; + public static final String BYE_COMMAND = "bye"; + public static final String BYE_MESSAGE = "Bye!!!!!!"; /** * Prints a line made up of '_'. */ - public void printLine() { + public static void printLine() { System.out.println("____________________________________________________________________________________"); } - public void printWithIndentation(String line) { + public static void printWithIndentation(String line) { System.out.println(" " + line); } + + public static final int MAX_LINE_LENGTH = 55; + public static final int ADDRESS_MAX_LENGTH = 48; + public static final String FLAG = "-"; + public static final String MULTIPLE_WHITE_SPACES = "\\s+"; + public static final String DUPLICATE_FLAGS = "Duplicate flags entered!"; + public static final String SIZE_FLAG = "-s"; + public static final String PORTS_FLAG = "-p"; + public static final String INDOOR_FLAG = "-i"; + public static final String NOT_INTEGER = "Argument used after size flag \"-s\" is not an integer"; + public static final String WRONG_FLAG_USAGE = "Flags indicated are wrongly used. Please enter \"help\" for the" + + " supported flags!"; + public static final String SPACE = " "; + public static final String WRONG_FLAG_ARGUMENT_POSITION = "Flags are to be used only after location"; + public static final String START_STUDY_AREA_SEARCH = "Please enter the location for your desired study area. " + + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" + + " location is entered. When you are done with the search, enter \"end\"."; + public static final String PROMPT_USER = "Please enter the location for your desired study area."; + public static final String FLAGS = "\t Here is a list of supported flags!\n\t -p for study areas with ports\n\t" + + " -i for study areas that are indoors\n\t -s {size} for maximum number of pax"; + public static final String AVAILABLE_STUDY_AREAS = "Here are the available study areas!"; + public static final String EMPTY_LIST = "Oops! Based on your criteria we were not able to find a compatible study" + + "area!"; + public static final String ONLY_FLAG = "Please enter the flag along with \"-\""; + public static final String INCONSISTENT_DATA_STORAGE = "Data is wrongly stored in locations.txt"; + public static final String END_COMMAND = "end"; + public static final String HELP_COMMAND = "help"; + public static final String TAB = "\t "; + public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; + public static final String END_MESSAGE = "Thank you for using our study area search service!"; + + /** + * This method ensures that the message printed is within the standard
+ * length. + * @param message is the String that we intend to format to a standard length
+ * per line.
+ * @param maxLength This is the standard length intended to be formatted. + * @return String of standard length per line + */ + + public static String formatMessage(String message, int maxLength) { + StringTokenizer token = new StringTokenizer(message, SPACE); + StringBuilder standardLengthMessage = new StringBuilder(message.length()); + int lineLength = 0; + while (token.hasMoreTokens()) { + String word = token.nextToken(); + if (lineLength + word.length() > maxLength) { + standardLengthMessage.append("\n\t "); + lineLength = 0; + } + standardLengthMessage.append(word).append(SPACE); + lineLength += word.length() + 1; + } + return TAB + standardLengthMessage.toString().stripTrailing(); + } } diff --git a/src/test/java/resourceloader/StudyAreaLoaderTest.java b/src/test/java/resourceloader/StudyAreaLoaderTest.java deleted file mode 100644 index a2d97de89..000000000 --- a/src/test/java/resourceloader/StudyAreaLoaderTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package resourceloader; - -import org.junit.jupiter.api.Test; -import studyarea.StudyArea; - -import java.io.File; -import java.io.FileNotFoundException; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class StudyAreaLoaderTest { - - StudyAreaLoader locationLoader = new StudyAreaLoader("library/locations.txt"); - - StudyAreaLoaderTest() throws FileNotFoundException { - } - - @Test - void getFile() throws FileNotFoundException { - locationLoader.loadFile(); - assertEquals(new File("library/locations.txt"), locationLoader.getFile()); - } -} \ No newline at end of file diff --git a/src/test/java/studyarea/StudyAreaListTest.java b/src/test/java/studyarea/StudyAreaListTest.java deleted file mode 100644 index 0f719a761..000000000 --- a/src/test/java/studyarea/StudyAreaListTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package studyarea; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class StudyAreaListTest { - StudyAreaList studyAreaList = new StudyAreaList(); - - StudyAreaListTest() throws Exception { - } - - @Test - void getStudyAreaList() throws Exception { - assertEquals(new StudyArea("OCBC","2 College Ave West, Stephen Riady Centre", - "-",true,false,2).getAddress(), - studyAreaList.getStudyAreaList().get(1).getAddress()); - } -} \ No newline at end of file From 6de0f609faa478322de74e3ae24853dfabca12fe Mon Sep 17 00:00:00 2001 From: hongquan448 Date: Mon, 9 Mar 2020 09:54:25 +0800 Subject: [PATCH 034/435] Refactor welcome message to ui, create Deadline and DeadlineList classes --- src/main/java/deadline/Deadline.java | 116 +++++++++++++++ src/main/java/deadline/DeadlineList.java | 173 +++++++++++++++++++++++ src/main/java/seedu/duke/Duke.java | 8 +- src/main/java/task/Tasklist.java | 7 + src/main/java/ui/Ui.java | 27 ++++ 5 files changed, 324 insertions(+), 7 deletions(-) create mode 100644 src/main/java/deadline/Deadline.java create mode 100644 src/main/java/deadline/DeadlineList.java create mode 100644 src/main/java/task/Tasklist.java diff --git a/src/main/java/deadline/Deadline.java b/src/main/java/deadline/Deadline.java new file mode 100644 index 000000000..0cb649257 --- /dev/null +++ b/src/main/java/deadline/Deadline.java @@ -0,0 +1,116 @@ +package deadline; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +/** + * Represents an deadline and contains the related functions. + */ +public class Deadline { + + private String description; + private LocalDate date; + private LocalTime dueTime; + private int priority; + + /** + * Constructor for Deadline + *Class. + * + * @param description Description of the deadline. + * @param date Date of specified Deadline + * @param dueTime Due time of specified deadline. + * @param priority Priority of specified deadline. + * @throws DateTimeParseException If wrong format is used for date, time fields. + */ + public Deadline(String description, String date, String dueTime, String priority) throws Exception{ + parseDescription(description); + parseDate(date); + parseDueTime(dueTime); + parsePriority(priority); + } + + private void parsePriority(String priority) throws Exception { + try { + this.priority = Integer.parseInt(priority.strip()); + } catch (NumberFormatException e) { + throw new Exception("Priority should be an integer"); + } + } + + private void parseDueTime(String dueTime) throws Exception { + try { + this.dueTime = LocalTime.parse(dueTime.strip()); + } catch (DateTimeParseException e) { + throw new Exception("Due time provided is invalid or in wrong format (Should be HH:MM)"); + } + } + + private void parseDate(String date) throws Exception { + try { + this.date = LocalDate.parse(date.strip()); + } catch (DateTimeParseException e) { + throw new Exception("Date provided is invalid or is in wrong format (Should be YYYY-MM-DD)"); + } + + } + + private void parseDescription(String description) { + this.description = description; + } + + /** + * Returns the information related to information in form of a string. + * + * @return deadlineInfo Contains information related to the deadline. + */ + public String getDeadlineInformation() { + String deadlineInfo = description + " on " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + " at " + + dueTime.toString(); + return deadlineInfo; + } + + /** + * Returns the priority of the specified deadline. + * + * @return Priority of deadline. + */ + public int getPriority() { + return priority; + } + + /** + * Returns the date of the deadline. + * + * @return Date of deadline. + */ + public LocalDate getDate() { + return date; + } + + /** + * Used to identify if the string contains the keyword specified in its description. + * + * @param keyword The keyword to be matched with the description. + * @return containsKeyword Indicates the presence/absence of keyword in the deadline's description. + */ + public boolean hasKeyword(String keyword) throws Exception { + if (keyword.equals("")) { + throw new Exception("Keyword is empty"); + } + boolean containsKeyword = description.contains(keyword); + return containsKeyword; + } + + /** + * Returns the deadline in the format used to store it in the data file. + * + * @return formattedDeadlineDetails Contains the deadline details in the required format. + */ + public String getFormattedDetails() { + String formattedDeadlineDetails = description + "#" + date + "#" + dueTime + "#" + priority; + return formattedDeadlineDetails; + } +} diff --git a/src/main/java/deadline/DeadlineList.java b/src/main/java/deadline/DeadlineList.java new file mode 100644 index 000000000..e6c0fd27f --- /dev/null +++ b/src/main/java/deadline/DeadlineList.java @@ -0,0 +1,173 @@ +package deadline; + +import java.time.format.DateTimeParseException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import ui.Ui; + +/** + * Handles all functions related to the list of deadlines. + */ +public class DeadlineList { + + Ui ui = new Ui(); + + /** Stores the deadline information. */ + public ArrayList deadlines; + + /** + * Constructor for the DeadlineList class. + */ + public DeadlineList() { + deadlines = new ArrayList(); + } + + public DeadlineList(ArrayList deadlines) { + this.deadlines = deadlines; + } + + /** + * Adds a new deadline to the list. + * + * @param newDeadline Deadline represents the new deadline tot be added. + */ + public void addDeadline(Deadline newDeadline) { + ui.printLine(); + deadlines.add(newDeadline); + ui.printWithIndentation("A new deadline with the following information has been added."); + ui.printWithIndentation(newDeadline.getDeadlineInformation()); + ui.printLine(); + } + + /** + * Displays the current list of deadlines. + */ + public void listDeadlines() { + ui.printLine(); + System.out.println("Here is the list of deadlines added so far:"); + int deadlineNumber = 1; + for (Deadline deadline: deadlines) { + ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + deadlineNumber++; + } + ui.printLine(); + } + + /** + * Deletes the deadline at the specified index. + * + * @param index The index (1-based) of the deadline to be deleted. + */ + public void deleteDeadline(int index) { + try { + deadlines.remove(index - 1); + ui.printLine(); + ui.printWithIndentation("The deadline at the mentioned index has been deleted"); + ui.printLine(); + } catch (IndexOutOfBoundsException e) { + ui.printLine(); + ui.printWithIndentation("Enter a valid index"); + ui.printLine(); + } + + } + + /** + * Clears all the deadlines currently stored. + */ + public void clearDeadlines() { + deadlines.clear(); + ui.printLine(); + ui.printWithIndentation("The list of deadlines is cleared."); + ui.printLine(); + } + + /** + * Lists all the tasks sorted by their priority. + */ + public void priorityView() { + ArrayList deadlinesSortedByPriority = deadlines; + deadlinesSortedByPriority.sort(Comparator.comparingInt(Deadline::getPriority)); + Collections.reverse(deadlinesSortedByPriority); + ui.printLine(); + int deadlineNumber = 1; + for (Deadline deadline:deadlinesSortedByPriority) { + ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + deadlineNumber++; + } + if (deadlineNumber == 1) { + ui.printWithIndentation("The list is empty."); + } + ui.printLine(); + } + + /** + * Lists all the tasks sorted by date along with the days remaining. + */ + public void countdownView() { + ArrayList deadlinesSortedByDate = deadlines; + deadlinesSortedByDate.sort(Comparator.comparing(Deadline::getDate)); + ui.printLine(); + int deadlineNumber = 1; + for (Deadline deadline:deadlinesSortedByDate) { + ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + deadlineNumber++; + } + if (deadlineNumber == 1) { + ui.printWithIndentation("The list is empty."); + } + ui.printLine(); + } + + /** + * Displays the list of deadlines containing the keyword. + * + * @param keyword The keyword to be searched for. + */ + public void searchDeadlines(String keyword) { + ui.printLine(); + int deadlineNumber = 1; + for (Deadline deadline:deadlines) { + try { + if (deadline.hasKeyword(keyword)) { + ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + deadlineNumber++; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + if (deadlineNumber == 1) { + ui.printWithIndentation("The list is empty."); + } + ui.printLine(); + } + + /** + * Adds a new deadline to the list by parsing information from the user given string + * and calling {@link #addDeadline(Deadline)} if the information is given in the correct format + * to add the deadline. + * + * @param deadlineDetails Contains all the information related to the deadline as provided by the user. + */ + public void add(String deadlineDetails) { + try { + String[] details = deadlineDetails.split(" ",2)[1].split("/"); + String description = details[0]; + String date = details[1].substring(2); + String dueTime = details[2].substring(2); + String priority = details[3].substring(2); + Deadline newDeadline = new Deadline(description,date,dueTime, priority); + addDeadline(newDeadline); + } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { + ui.printLine(); + ui.printWithIndentation("Wrong format to add deadlines"); + ui.printLine(); + } catch (Exception e) { + ui.printLine(); + ui.printWithIndentation(e.getMessage()); + ui.printLine(); + } + } +} diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 29d29d93d..cf022abd8 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -29,13 +29,7 @@ public class Duke { * Main entry-point for the java.duke.Duke application. */ public static void main(String[] args) throws Exception { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - System.out.println("What is your name?"); + ui.printWelcomeMessage(); Scanner in = new Scanner(System.in); System.out.println("Hello " + in.nextLine()); diff --git a/src/main/java/task/Tasklist.java b/src/main/java/task/Tasklist.java new file mode 100644 index 000000000..5134ecf7a --- /dev/null +++ b/src/main/java/task/Tasklist.java @@ -0,0 +1,7 @@ +package task; + +abstract public class TaskList { + abstract public void priorityView(); + abstract public void countdownView(); + abstract public void searchTasks(); +} diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 7a0c4d296..1b513879c 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -15,4 +15,31 @@ public void printLine() { public void printWithIndentation(String line) { System.out.println(" " + line); } + + public void printHelp() { + printLine(); + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + printLine(); + } + + public void printWelcomeMessage() { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); + System.out.println("What is your name?"); + } } From 6f723ca67caad12a53eebcdb1b71f7977a32107d Mon Sep 17 00:00:00 2001 From: hongquan448 Date: Mon, 9 Mar 2020 11:46:15 +0800 Subject: [PATCH 035/435] add printHelp method to ui --- src/main/java/task/Tasklist.java | 7 +++++++ src/main/java/ui/Ui.java | 27 +++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/task/Tasklist.java b/src/main/java/task/Tasklist.java index 5134ecf7a..36b2c6758 100644 --- a/src/main/java/task/Tasklist.java +++ b/src/main/java/task/Tasklist.java @@ -1,6 +1,13 @@ package task; abstract public class TaskList { + /** + * Tasklist is an abstract class that oversees all task-related classes. + * The current task-related classes are events, deadlines, assignments + * TaskList stores all tasks in one large array, allowing the user to access the priorityView and countdownView of all tasks + */ + + abstract public void priorityView(); abstract public void countdownView(); abstract public void searchTasks(); diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 1b513879c..ca1faf6fb 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -18,18 +18,21 @@ public void printWithIndentation(String line) { public void printHelp() { printLine(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(); - System.out.println(); + System.out.println("OrgaNice! Supports the following commands"); + System.out.println("Please enter the keywords followed by the information shown in the brackets"); + System.out.println("add /d /s /e /p "); + System.out.println("------------------------------------------- Create a new event"); + System.out.println("view -------------------------------------- View existing events"); + System.out.println("priority_view ----------------------------- View existing events based on priority"); + System.out.println("countdown --------------------------------- View existing events based on days left"); + System.out.println("clear ------------------------------------- Delete all events"); + System.out.println("search ----------- View existing events that contains the keyword"); + System.out.println("delete ------------ Delete the event"); + System.out.println("bye --------------------------------------- Terminate program"); + System.out.println("Notes:"); + System.out.println("*All dates should follow YYYY-MM-DD format"); + System.out.println("*All timing should follow 24 hour clock"); + System.out.println("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the least urgent"); printLine(); } From b5d3e5cbdbe9f868f7eff921fca3fe117690a3fc Mon Sep 17 00:00:00 2001 From: Mohamed Nizar <34931736+NizarMohd@users.noreply.github.com> Date: Mon, 9 Mar 2020 16:05:43 +0800 Subject: [PATCH 036/435] Delete Utility.java --- src/main/java/studyarea/Utility.java | 68 ---------------------------- 1 file changed, 68 deletions(-) delete mode 100644 src/main/java/studyarea/Utility.java diff --git a/src/main/java/studyarea/Utility.java b/src/main/java/studyarea/Utility.java deleted file mode 100644 index c0b97c890..000000000 --- a/src/main/java/studyarea/Utility.java +++ /dev/null @@ -1,68 +0,0 @@ -package studyarea; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.StringTokenizer; - -/** - * This class holds all the Utilities required for the Study Area related classes. - */ - -public class Utility { - public static final int MAX_LINE_LENGTH = 55; - public static final int ADDRESS_MAX_LENGTH = 48; - public static final String FLAG = "-"; - public static final String MULTIPLE_WHITE_SPACES = "\\s+"; - public static final String DUPLICATE_FLAGS = "Duplicate flags entered!"; - public static final String SIZE_FLAG = "-s"; - public static final String PORTS_FLAG = "-p"; - public static final String INDOOR_FLAG = "-i"; - public static final String NOT_INTEGER = "Argument used after size flag \"-s\" is not an integer"; - public static final String WRONG_FLAG_USAGE = "Flags indicated are wrongly used. Please enter \"help\" for the" - + " supported flags!"; - public static final String SPACE = " "; - public static final String WRONG_FLAG_ARGUMENT_POSITION = "Flags are to be used only after location"; - public static final String START_STUDY_AREA_SEARCH = "Please enter the location for your desired study area. " - + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" - + " location is entered. When you are done with the search, enter \"end\"."; - public static final String PROMPT_USER = "Please enter the location for your desired study area."; - public static final String FLAGS = "\t Here is a list of supported flags!\n\t -p for study areas with ports\n\t" - + " -i for study areas that are indoors\n\t -s {size} for maximum number of pax"; - public static final String AVAILABLE_STUDY_AREAS = "Here are the available study areas!"; - public static final String EMPTY_LIST = "Oops! Based on your criteria we were not able to find a compatible study" - + "area!"; - public static final String ONLY_FLAG = "Please enter the flag along with \"-\""; - public static final String INCONSISTENT_DATA_STORAGE = "Data is wrongly stored in locations.txt"; - public static final String END_COMMAND = "end"; - public static final String HELP_COMMAND = "help"; - public static final String TAB = "\t "; - public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; - public static final String END_MESSAGE = "Thank you for using our study area search service!"; - public static final String EMPTY_COMMAND = "Command entered is empty!"; - - /** - * This method ensures that the message printed is within the standard
- * length. - * @param message is the String that we intend to format to a standard length
- * per line.
- * @param maxLength This is the standard length intended to be formatted. - * @return String of standard length per line - */ - - public static String formatMessage(String message, int maxLength) { - StringTokenizer token = new StringTokenizer(message, SPACE); - StringBuilder standardLengthMessage = new StringBuilder(message.length()); - int lineLength = 0; - while (token.hasMoreTokens()) { - String word = token.nextToken(); - if (lineLength + word.length() > maxLength) { - standardLengthMessage.append("\n\t "); - lineLength = 0; - } - standardLengthMessage.append(word).append(SPACE); - lineLength += word.length() + 1; - } - return TAB + standardLengthMessage.toString().stripTrailing(); - } - -} From 4fb1d7b6865625dab8e25858f99766a9ef2cf495 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Mon, 9 Mar 2020 16:10:11 +0800 Subject: [PATCH 037/435] add exception --- src/main/java/seedu/duke/Duke.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index abff383f5..ad8013c70 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,6 +1,9 @@ package seedu.duke; import driver.Driver; +import studyarea.IllegalStudyAreaException; + +import java.io.FileNotFoundException; import java.util.Scanner; public class Duke { @@ -9,7 +12,7 @@ public class Duke { * Main entry-point for the java.duke.Duke application. * @param args this is an optional argument. */ - public static void main(String[] args) { + public static void main(String[] args) throws FileNotFoundException, IllegalStudyAreaException { String logo = "_______/\\\\\\\\\\_____________________________________________________/\\\\\\\\\\_____/\\\\\\__" + "__________________________________________/\\\\\\____________\n" + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" From cd3a377d912b13cc86d3f858aa3e4a2a5c676ed3 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Mon, 9 Mar 2020 22:29:29 +0800 Subject: [PATCH 038/435] Refactor IO stream and Change Logo --- library/eventList.txt | 1 + src/main/java/command/EventCommand.java | 37 ++--- src/main/java/command/StudyAreaCommand.java | 17 +- src/main/java/driver/Driver.java | 6 +- src/main/java/event/EventList.java | 81 +++++----- src/main/java/resourceloader/EventLoader.java | 2 +- src/main/java/seedu/duke/Duke.java | 100 ++++++------ src/main/java/ui/Ui.java | 147 ++++++++++++++++-- 8 files changed, 253 insertions(+), 138 deletions(-) diff --git a/library/eventList.txt b/library/eventList.txt index e69de29bb..afc4e3d14 100644 --- a/library/eventList.txt +++ b/library/eventList.txt @@ -0,0 +1 @@ +read this #2020-12-12#14:00#15:00#1 \ No newline at end of file diff --git a/src/main/java/command/EventCommand.java b/src/main/java/command/EventCommand.java index 9e9c98ef9..d19e388d1 100644 --- a/src/main/java/command/EventCommand.java +++ b/src/main/java/command/EventCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import resourceloader.EventLoader; import ui.Ui; import java.util.Scanner; @@ -12,52 +13,52 @@ public class EventCommand { * * @param eventList evenList */ - public static void runCommands(EventList eventList) { + public static void runCommands(EventList eventList, Ui ui, EventLoader eventLoader) { Scanner in = new Scanner(System.in); String command; + ui.printLine(); command = in.nextLine(); while (!command.equals(Ui.BYE_COMMAND)) { + ui.printLine(); try { String commandType = command.split(" ")[0]; switch (commandType) { case Ui.ADD_COMMAND: - eventList.add(command); + eventList.add(command, ui); break; case Ui.VIEW_COMMAND: - eventList.listEvents(); + eventList.listEvents(ui); break; case Ui.PRIORITY_VIEW_COMMAND: - eventList.priorityView(); + eventList.priorityView(ui); break; case Ui.COUNTDOWN_VIEW_COMMAND: - eventList.countdownView(); + eventList.countdownView(ui); break; case Ui.CLEAR_COMMAND: - eventList.clearEvents(); + eventList.clearEvents(ui); break; case Ui.SEARCH_COMMAND: - eventList.searchEvents(command.split(" ", 2)[1]); + eventList.searchEvents(command.split(" ", 2)[1], ui); break; case Ui.DELETE_COMMAND: - eventList.deleteEvent(Integer.parseInt(command.split(" ", 2)[1])); + eventList.deleteEvent(Integer.parseInt(command.split(" ", 2)[1]), ui); break; default: - Ui.printLine(); - System.out.println(Ui.INVALID_COMMAND_MESSAGE); - Ui.printLine(); + ui.printMessage(Ui.INVALID_COMMAND_MESSAGE); break; } } catch (NumberFormatException e) { - Ui.printLine(); - System.out.println(Ui.INVALID_INDEX_MESSAGE); - Ui.printLine(); + ui.printMessage(Ui.INVALID_INDEX_MESSAGE); } catch (IndexOutOfBoundsException e) { - Ui.printLine(); - System.out.println(Ui.INVALID_COMMAND_MESSAGE); - Ui.printLine(); + ui.printMessage(Ui.INVALID_COMMAND_MESSAGE); } + ui.printLine(); + eventLoader.saveEvents(eventList.events); command = in.nextLine(); } - System.out.println(Ui.BYE_MESSAGE); + ui.printLine(); + ui.printMessage(Ui.BYE_MESSAGE); + ui.printLine(); } } diff --git a/src/main/java/command/StudyAreaCommand.java b/src/main/java/command/StudyAreaCommand.java index be6c63ff0..251abe858 100644 --- a/src/main/java/command/StudyAreaCommand.java +++ b/src/main/java/command/StudyAreaCommand.java @@ -40,7 +40,7 @@ public static void printList(ArrayList availStudyAreas) { public static boolean filterCommand(String command, StudyAreaList studyAreaList) { switch (command) { - case Ui.END_COMMAND : + case Ui.BYE_COMMAND : System.out.println(Ui.formatMessage(Ui.END_MESSAGE, Ui.MAX_LINE_LENGTH)); return false; case Ui.HELP_COMMAND : @@ -62,19 +62,16 @@ public static boolean filterCommand(String command, StudyAreaList studyAreaList) * Executes the Study Area search feature. * @param studyAreaList studyAreaList object that holds information on studyAreas available. */ - public static void runCommands(StudyAreaList studyAreaList) { - - Ui ui = new Ui(); + public static void runCommands(StudyAreaList studyAreaList, Ui ui) { ui.printLine(); - System.out.println(Ui.formatMessage(Ui.START_STUDY_AREA_SEARCH, Ui.MAX_LINE_LENGTH)); - Scanner in = new Scanner(System.in); + ui.printMessage(Ui.START_STUDY_AREA_SEARCH); boolean status = true; while (status) { - Ui.printLine(); - String command = in.nextLine(); - Ui.printLine(); + ui.printLine(); + String command = ui.getUserIn(); + ui.printLine(); status = filterCommand(command, studyAreaList); } - Ui.printLine(); + ui.printLine(); } } diff --git a/src/main/java/driver/Driver.java b/src/main/java/driver/Driver.java index a09b7c01a..60d6528f0 100644 --- a/src/main/java/driver/Driver.java +++ b/src/main/java/driver/Driver.java @@ -30,14 +30,14 @@ public Driver(int mode) throws FileNotFoundException, IllegalStudyAreaException studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); StudyAreaList studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); - + Ui ui = new Ui(); if (mode == 1) { EventCommand eventCommand = new EventCommand(); - eventCommand.runCommands(eventList); + eventCommand.runCommands(eventList, ui, eventLoader); eventLoader.saveEvents(eventList.events); } else { StudyAreaCommand studyAreaCommand = new StudyAreaCommand(); - studyAreaCommand.runCommands(studyAreaList); + studyAreaCommand.runCommands(studyAreaList, ui); } } } diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index 947d606da..1684a9748 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -11,7 +11,6 @@ */ public class EventList { - Ui ui = new Ui(); /** Stores the event information. */ public ArrayList events; @@ -30,108 +29,104 @@ public EventList(ArrayList events) { /** * Adds a new event to the list. * + * @param ui This allows Event List class to interact with User. * @param newEvent Event represents the new event tot be added. */ - public void addEvent(Event newEvent) { - ui.printLine(); + public void addEvent(Event newEvent, Ui ui) { events.add(newEvent); - ui.printWithIndentation("A new event with the following information has been added."); - ui.printWithIndentation(newEvent.getEventInformation()); - ui.printLine(); + ui.printMessage("A new event with the following information has been added."); + ui.printMessage(newEvent.getEventInformation()); } /** * Displays the current list of events. + * + * @param ui This allows Event List class to interact with User. */ - public void listEvents() { - ui.printLine(); - System.out.println("Here is the list of events added so far:"); + public void listEvents(Ui ui) { + ui.printMessage("Here is the list of events added so far:"); int eventNumber = 1; for (Event event: events) { - ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); + ui.printMessage(eventNumber + ") " + event.getEventInformation()); eventNumber++; } - ui.printLine(); } /** * Deletes the event at the specified index. * + * @param ui This allows Event List class to interact with User. * @param index The index (1-based) of the event to be deleted. */ - public void deleteEvent(int index) { + public void deleteEvent(int index, Ui ui) { try { events.remove(index - 1); - ui.printLine(); - ui.printWithIndentation("The event at the mentioned index has been deleted"); - ui.printLine(); + ui.printMessage("The event at the mentioned index has been deleted"); } catch (IndexOutOfBoundsException e) { - ui.printLine(); - ui.printWithIndentation("Enter a valid index"); - ui.printLine(); + ui.printMessage("Enter a valid index"); } } /** * Clears all the events currently stored. + * + * @param ui This allows Event List class to interact with User. */ - public void clearEvents() { + public void clearEvents(Ui ui) { events.clear(); - ui.printLine(); - ui.printWithIndentation("The list of events is cleared."); - ui.printLine(); + ui.printMessage("The list of events is cleared."); } /** * Lists all the tasks sorted by their priority. + * + * @param ui This allows Event List class to interact with User. */ - public void priorityView() { + public void priorityView(Ui ui) { ArrayList eventsSortedByPriority = events; eventsSortedByPriority.sort(Comparator.comparingInt(Event::getPriority)); Collections.reverse(eventsSortedByPriority); - ui.printLine(); int eventNumber = 1; for (Event event:eventsSortedByPriority) { - ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); + ui.printMessage(eventNumber + ") " + event.getEventInformation()); eventNumber++; } if (eventNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } - ui.printLine(); } /** * Lists all the tasks sorted by date along with the days remaining. + * + * @param ui This allows Event List class to interact with User. */ - public void countdownView() { + public void countdownView(Ui ui) { ArrayList eventsSortedByDate = events; eventsSortedByDate.sort(Comparator.comparing(Event::getDate)); - ui.printLine(); int eventNumber = 1; for (Event event:eventsSortedByDate) { - ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); + ui.printMessage(eventNumber + ") " + event.getEventInformation()); eventNumber++; } if (eventNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } - ui.printLine(); } /** * Displays the list of events containing the keyword. * + * @param ui This allows Event List class to interact with User. * @param keyword The keyword to be searched for. */ - public void searchEvents(String keyword) { - ui.printLine(); + public void searchEvents(String keyword, Ui ui) { int eventNumber = 1; for (Event event:events) { try { if (event.hasKeyword(keyword)) { - ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); + ui.printMessage(eventNumber + ") " + event.getEventInformation()); eventNumber++; } } catch (Exception e) { @@ -139,9 +134,8 @@ public void searchEvents(String keyword) { } } if (eventNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } - ui.printLine(); } /** @@ -149,9 +143,10 @@ public void searchEvents(String keyword) { * and calling {@link #addEvent(Event)} if the information is given in the correct format * to add the event. * + * @param ui This allows Event List class to interact with User. * @param eventDetails Contains all the information related to the event as provided by the user. */ - public void add(String eventDetails) { + public void add(String eventDetails, Ui ui) { try { String[] details = eventDetails.split(" ",2)[1].split("/"); String description = details[0]; @@ -160,15 +155,11 @@ public void add(String eventDetails) { String endTime = details[3].substring(2); String priority = details[4].substring(2); Event newEvent = new Event(description,date,startTime,endTime,priority); - addEvent(newEvent); + addEvent(newEvent, ui); } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { - ui.printLine(); - ui.printWithIndentation("Wrong format to add events"); - ui.printLine(); + ui.printMessage("Wrong format to add events"); } catch (Exception e) { - ui.printLine(); - ui.printWithIndentation(e.getMessage()); - ui.printLine(); + ui.printMessage(e.getMessage()); } } } diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java index 9326382c0..c1f81376a 100644 --- a/src/main/java/resourceloader/EventLoader.java +++ b/src/main/java/resourceloader/EventLoader.java @@ -58,7 +58,7 @@ public ArrayList loadFile() { createNewDataFile(); } catch (Exception e) { ui.printLine(); - ui.printWithIndentation(e.getMessage()); + ui.printMessage(e.getMessage()); ui.printLine(); } return events; diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index ad8013c70..86f6fb998 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,59 +1,67 @@ package seedu.duke; -import driver.Driver; +import command.EventCommand; +import command.StudyAreaCommand; +import event.EventList; +import resourceloader.EventLoader; +import resourceloader.StudyAreaLoader; import studyarea.IllegalStudyAreaException; - +import studyarea.StudyAreaList; +import ui.Ui; import java.io.FileNotFoundException; -import java.util.Scanner; public class Duke { + private static EventLoader eventLoader; + protected static StudyAreaLoader studyAreaLoader; + private static EventList eventList; + private static StudyAreaList studyAreaList; + + public Duke() { + try { + eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); + eventList = new EventList(eventLoader.loadFile()); + studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); + studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); + } catch (FileNotFoundException | IllegalStudyAreaException e){ + Ui ui = new Ui(); + ui.printMessage(e.getMessage()); + ui.close(); + } + } + + public void run() { + Ui ui = new Ui(); + ui.printWelcomeMessage(); + boolean status = true; + while (status) { + int mode = ui.getMode(); + switch (mode) { + case -1: + status = false; + break; + case 0: + ui.printMessage(Ui.WRONG_INPUT); + break; + case 1: + EventCommand.runCommands(eventList, ui, eventLoader); + eventLoader.saveEvents(eventList.events); + break; + case 2: + StudyAreaCommand.runCommands(studyAreaList, ui); + break; + } + ui.printMessage(Ui.INTERMEDIATE_MESSAGE); + ui.printLine(); + } + ui.printMessage(Ui.GOODBYE_MESSAGE + Ui.DAB); + ui.close(); + } /** * Main entry-point for the java.duke.Duke application. * @param args this is an optional argument. */ - public static void main(String[] args) throws FileNotFoundException, IllegalStudyAreaException { - String logo = "_______/\\\\\\\\\\_____________________________________________________/\\\\\\\\\\_____/\\\\\\__" - + "__________________________________________/\\\\\\____________\n" - + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" - + "_________________________________________/\\\\\\\\\\\\\\_________\n" - + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" - + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______\n" - + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" - + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" - + "_\\//\\\\\\\\\\\\\\_______\n" - + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" - + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" - + "___\n" - + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" - + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" - + "_____\n" - + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" - + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______\n" - + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" - + "_\\//\\\\\\\\\\\\\\\\/\\\\" - + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" - + "_/\\\\\\_____\n" - + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" - + "_\\///______\\////////_____\\//////////______\\///_____"; - System.out.println("Hello from\n" + logo); - System.out.println("What is your name?"); - - Scanner in = new Scanner(System.in); - System.out.println("Hello " + in.nextLine()); - - /** - * To run: - * events: enter 1 - * study areas: enter 0 - * To end events loop: enter bye in events prog - * To end study areas loop: enter end in study area loop - * To end overall prog, enter ctrl+c or ctrl+z - * Take note: this is still temporary - */ - while (true) { - Scanner mode = new Scanner(System.in); - Driver driver = new Driver(mode.nextInt()); - } + public static void main(String[] args) { + new Duke().run(); } } diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 5230437b1..06466a359 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -1,15 +1,24 @@ package ui; +import studyarea.IllegalStudyAreaException; + import java.io.File; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.Scanner; import java.util.StringTokenizer; +import static java.lang.System.lineSeparator; + /** * Contains functions used to interact with the user. */ public class Ui { + private final Scanner in; + private final PrintStream out; + public static final String FILE_PATH_EVENTS = "library" + File.separator + "eventList.txt"; public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; - public static final String ADD_COMMAND = "add"; public static final String VIEW_COMMAND = "view"; public static final String PRIORITY_VIEW_COMMAND = "priority_view"; @@ -21,18 +30,8 @@ public class Ui { public static final String INVALID_COMMAND_MESSAGE = "Enter a valid command"; public static final String BYE_COMMAND = "bye"; public static final String BYE_MESSAGE = "Bye!!!!!!"; - - /** - * Prints a line made up of '_'. - */ - public static void printLine() { - System.out.println("____________________________________________________________________________________"); - } - - public static void printWithIndentation(String line) { - System.out.println(" " + line); - } - + public static final String LINE = "_______________________________________________________________________________" + + "_____"; public static final int MAX_LINE_LENGTH = 55; public static final int ADDRESS_MAX_LENGTH = 48; public static final String FLAG = "-"; @@ -48,7 +47,7 @@ public static void printWithIndentation(String line) { public static final String WRONG_FLAG_ARGUMENT_POSITION = "Flags are to be used only after location"; public static final String START_STUDY_AREA_SEARCH = "Please enter the location for your desired study area. " + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" - + " location is entered. When you are done with the search, enter \"end\"."; + + " location is entered. When you are done with the search, enter \"bye\"."; public static final String PROMPT_USER = "Please enter the location for your desired study area."; public static final String FLAGS = "\t Here is a list of supported flags!\n\t -p for study areas with ports\n\t" + " -i for study areas that are indoors\n\t -s {size} for maximum number of pax"; @@ -57,12 +56,93 @@ public static void printWithIndentation(String line) { + "area!"; public static final String ONLY_FLAG = "Please enter the flag along with \"-\""; public static final String INCONSISTENT_DATA_STORAGE = "Data is wrongly stored in locations.txt"; - public static final String END_COMMAND = "end"; public static final String HELP_COMMAND = "help"; public static final String TAB = "\t "; public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; + public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"event\" to start your event" + + " list! If you are in the mood to mug and you want to start your study area list, enter \"study\" !" + + "If you want to exit, enter \"bye\" !"; + public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; + public static final String EVENT_COMMAND = "event"; + public static final String STUDY_COMMAND = "study"; + public static final String GOODBYE_MESSAGE = "Goodbye! Hope to see you again!"; + public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or" + + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; + public static final String DAB = "\t ``````````````````````````````````````````````````````````\n" + + "\t ````````````````````````````````:v(v'`````````````````````\n" + + "\t ```````````````````````````,)4|ex` `L}````````````````````\n" + + "\t `````````````````````````!s\"'h `M: ^z_;)T```````````````\n" + + "\t `````````````````````````Z u|}Z: \"}``````````````\n" + + "\t ``````````````````````:=?) 'B?L'```````````\n" + + "\t `````````````````````'Z ;Yp\"```````````\n" + + "\t `````````````````````.e ?_```````````\n" + + "\t ```````````````````'QDGH .5````````````\n" + + "\t ````````````````````I#g' '_` ||````````````\n" + + "\t ```````````:mX_``````YhL` `'q!` ? h````````````\n" + + "\t ```````````'Qbs)|L=_V\" 'Y} ^'q@&b=c=_` ,Z````````````\n" + + "\t ````````````q> 'T, ,o\" ;\"@c. .sVx~`````````````\n" + + "\t ````````````c! \"bh` `,p z:``````````````\n" + + "\t `````````````q. ngDQmh8s X'``````````````\n" + + "\t ``````````````LY\" :n}>``b; _V```````````````\n" + + "\t ````````````````q?, ?; \"V````````````````\n" + + "\t ``````````````KvR ' )x_`````````````````\n" + + "\t ``````````````zjL GLY\"```````````````````\n" + + "\t ```````````````M .I)``````````````````````\n" + + "\t ```````````````Lz `D:``````````````````````\n" + + "\t ``````````````vu` (I)_;\"\". P.`````````````````````\n" + + "\t ``````````````p :X.':^,\"=n \"q``````````````````````\n" + + "\t `````````````)0X?^:)I````````m' :j``````````````````````\n" + + "\t `````````````.IGD8k'`````````<&G55M```````````````````````\n" + + "\t ``````````````````````````````````````````````````````````"; + + + public Ui() { + this(System.in, System.out); + } + + public Ui(InputStream in, PrintStream out) { + this.in = new Scanner(in); + this.out = out; + } + + public int getMode() { + String userIn = this.in.nextLine().toLowerCase(); + switch (userIn) { + case EVENT_COMMAND : + return 1; + case STUDY_COMMAND : + return 2; + case BYE_COMMAND : + return -1; + default : + return 0; + } + } + + public String getUserIn(){ + return this.in.nextLine(); + } + + public void close() { + this.in.close(); + } + + public void printMessage(String message){ + if(message.equals(GOODBYE_MESSAGE+DAB)){ + this.out.println(formatMessage(GOODBYE_MESSAGE, MAX_LINE_LENGTH)); + this.out.println(DAB); + }else { + this.out.println(formatMessage(message, MAX_LINE_LENGTH)); + } + } + /** + * Prints a line made up of '_'. + */ + public void printLine() { + System.out.println(LINE); + } /** * This method ensures that the message printed is within the standard
* length. @@ -87,4 +167,41 @@ public static String formatMessage(String message, int maxLength) { } return TAB + standardLengthMessage.toString().stripTrailing(); } + + /** + * Prints the welcome message and starts interaction with user. + */ + public void printWelcomeMessage(){ + String logo = "_______/\\\\\\\\\\_____________________________________________________/\\\\\\\\\\_____/\\\\\\__" + + "__________________________________________/\\\\\\____________\n" + + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" + + "_________________________________________/\\\\\\\\\\\\\\_________\n" + + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" + + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______\n" + + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" + + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\_______\n" + + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" + + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" + + "___\n" + + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" + + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" + + "_____\n" + + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" + + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______\n" + + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\\\/\\\\" + + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" + + "_/\\\\\\_____\n" + + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" + + "_\\///______\\////////_____\\//////////______\\///_____"; + this.out.println("Hello from\n" + logo); + this.out.println("What is your name?"); + printLine(); + String name = this.in.nextLine(); + printLine(); + this.out.println(TAB + "Hello " + name + "!"); + this.out.println(formatMessage(START_MESSAGE, MAX_LINE_LENGTH)); + printLine(); + } } From 994e6c0b1477d82e87854e62b99041b4189bfae0 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Tue, 10 Mar 2020 01:17:26 +0800 Subject: [PATCH 039/435] Edit Javadoc, Add credits, add exception handling --- library/eventList.txt | 2 +- src/main/java/command/EventCommand.java | 4 +- src/main/java/command/StudyAreaCommand.java | 69 +++++---- src/main/java/event/Event.java | 1 + src/main/java/event/EventList.java | 2 +- src/main/java/seedu/duke/Duke.java | 20 ++- .../studyarea/IllegalStudyAreaException.java | 2 +- src/main/java/studyarea/StudyArea.java | 42 ++++- src/main/java/studyarea/StudyAreaList.java | 1 + src/main/java/ui/Ui.java | 146 ++++++++++++------ 10 files changed, 203 insertions(+), 86 deletions(-) diff --git a/library/eventList.txt b/library/eventList.txt index afc4e3d14..26a6edc21 100644 --- a/library/eventList.txt +++ b/library/eventList.txt @@ -1 +1 @@ -read this #2020-12-12#14:00#15:00#1 \ No newline at end of file +this event #2020-12-12#13:00#15:00#1 \ No newline at end of file diff --git a/src/main/java/command/EventCommand.java b/src/main/java/command/EventCommand.java index d19e388d1..bd4b8ecd4 100644 --- a/src/main/java/command/EventCommand.java +++ b/src/main/java/command/EventCommand.java @@ -11,7 +11,9 @@ public class EventCommand { /** * Commands for Events. * - * @param eventList evenList + * @param eventList this is the evenList. + * @param ui allows for interaction with the User. + * @param eventLoader allows for saving of data after every execution of commands. */ public static void runCommands(EventList eventList, Ui ui, EventLoader eventLoader) { Scanner in = new Scanner(System.in); diff --git a/src/main/java/command/StudyAreaCommand.java b/src/main/java/command/StudyAreaCommand.java index 251abe858..a9fd8df49 100644 --- a/src/main/java/command/StudyAreaCommand.java +++ b/src/main/java/command/StudyAreaCommand.java @@ -4,28 +4,26 @@ import studyarea.StudyArea; import studyarea.StudyAreaList; import ui.Ui; - -import java.io.FileNotFoundException; import java.util.ArrayList; -import java.util.Scanner; /** - * This is the Study Area Command class. It executes the Study Area Search function and interact with Users accordingly. + * This is the StudyAreaCommand class. It executes the StudyArea Search function and interact with Users accordingly. */ public class StudyAreaCommand { /** - * List out all the study areas that match with User's preference. + * List out all the StudyAreas that match with User's preference. + * @param ui This allows for StudyAreaCommand to interact with Users. * @param availStudyAreas this is the list of all study areas in location.txt. */ - public static void printList(ArrayList availStudyAreas) { + public static void printList(ArrayList availStudyAreas, Ui ui) { if (availStudyAreas.isEmpty()) { - System.out.println(Ui.formatMessage(Ui.EMPTY_LIST, Ui.MAX_LINE_LENGTH)); + ui.printMessage(Ui.EMPTY_LIST); } else { - System.out.println(Ui.formatMessage(Ui.AVAILABLE_STUDY_AREAS, Ui.MAX_LINE_LENGTH)); + ui.printMessage(Ui.AVAILABLE_STUDY_AREAS); for (StudyArea studyArea : availStudyAreas) { - System.out.println(studyArea.toString()); + ui.printStudyArea(studyArea); } } } @@ -34,35 +32,46 @@ public static void printList(ArrayList availStudyAreas) { /** * Filters command based on User Input. * @param command This is the command entered by User. - * @param studyAreaList This is the list of all Study Areas in location.txt. + * @param studyAreaList This is the list of all StudyAreas in location.txt. + * @param ui This allows for StudyAreaCommand to interact with Users. * @return boolean status. False if User enters "end" , else will always return true; + * @throws IllegalStudyAreaException if User enters invalid commands. */ - public static boolean filterCommand(String command, StudyAreaList studyAreaList) { - switch (command) { - case Ui.BYE_COMMAND : - System.out.println(Ui.formatMessage(Ui.END_MESSAGE, Ui.MAX_LINE_LENGTH)); - return false; - case Ui.HELP_COMMAND : - System.out.println(Ui.FLAGS); - break; - default: - try { - ArrayList availStudyAreas = studyAreaList.searchList(command); - printList(availStudyAreas); - System.out.println(Ui.formatMessage(Ui.PROMPT_USER, Ui.MAX_LINE_LENGTH)); - } catch (IllegalStudyAreaException e) { - System.out.println(Ui.formatMessage(e.getMessage(), Ui.MAX_LINE_LENGTH)); + public static boolean filterCommand(String command, StudyAreaList studyAreaList, Ui ui) throws + IllegalStudyAreaException { + + command = command.trim(); + if (command.isBlank()) { + throw new IllegalStudyAreaException(Ui.EMPTY_LOCATION); + } else { + switch (command) { + case Ui.BYE_COMMAND: + ui.printMessage(Ui.END_MESSAGE); + return false; + case Ui.HELP_COMMAND: + ui.printMessage(Ui.FLAGS); + break; + default: + try { + ArrayList availStudyAreas = studyAreaList.searchList(command); + printList(availStudyAreas, ui); + ui.printMessage(Ui.PROMPT_USER); + } catch (IllegalStudyAreaException e) { + ui.printMessage(e.getMessage()); + } + break; } } return true; } /** - * Executes the Study Area search feature. + * Executes the StudyArea search feature. + * @param ui This allows for StudyAreaCommand to interact with Users. * @param studyAreaList studyAreaList object that holds information on studyAreas available. */ - public static void runCommands(StudyAreaList studyAreaList, Ui ui) { + public static void runCommands(StudyAreaList studyAreaList, Ui ui) { ui.printLine(); ui.printMessage(Ui.START_STUDY_AREA_SEARCH); boolean status = true; @@ -70,7 +79,11 @@ public static void runCommands(StudyAreaList studyAreaList, Ui ui) { ui.printLine(); String command = ui.getUserIn(); ui.printLine(); - status = filterCommand(command, studyAreaList); + try { + status = filterCommand(command, studyAreaList, ui); + } catch (IllegalStudyAreaException e) { + ui.printMessage(e.getMessage()); + } } ui.printLine(); } diff --git a/src/main/java/event/Event.java b/src/main/java/event/Event.java index 487c48845..1a1002eea 100644 --- a/src/main/java/event/Event.java +++ b/src/main/java/event/Event.java @@ -112,6 +112,7 @@ public LocalDate getDate() { * * @param keyword The keyword to be matched with the description. * @return containsKeyword Indicates the presence/absence of keyword in the event's description. + * @throws Exception to be edited */ public boolean hasKeyword(String keyword) throws Exception { if (keyword.equals("")) { diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index 1684a9748..c6be85b54 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -140,7 +140,7 @@ public void searchEvents(String keyword, Ui ui) { /** * Adds a new event to the list by parsing information from the user given string - * and calling {@link #addEvent(Event)} if the information is given in the correct format + * and calling {@link #addEvent(Event, Ui)} if the information is given in the correct format * to add the event. * * @param ui This allows Event List class to interact with User. diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 86f6fb998..f8d7aac77 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -10,25 +10,34 @@ import ui.Ui; import java.io.FileNotFoundException; +/** + * This is Duke class, which forms the main class of the program. + */ public class Duke { private static EventLoader eventLoader; protected static StudyAreaLoader studyAreaLoader; private static EventList eventList; private static StudyAreaList studyAreaList; + /** + * This is the constructor to create a new Duke program every time user runs the main loop. + */ public Duke() { try { eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); eventList = new EventList(eventLoader.loadFile()); studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); - } catch (FileNotFoundException | IllegalStudyAreaException e){ + } catch (FileNotFoundException | IllegalStudyAreaException e) { Ui ui = new Ui(); ui.printMessage(e.getMessage()); ui.close(); } } + /** + * This method runs the program. + */ public void run() { Ui ui = new Ui(); ui.printWelcomeMessage(); @@ -39,9 +48,6 @@ public void run() { case -1: status = false; break; - case 0: - ui.printMessage(Ui.WRONG_INPUT); - break; case 1: EventCommand.runCommands(eventList, ui, eventLoader); eventLoader.saveEvents(eventList.events); @@ -49,6 +55,10 @@ public void run() { case 2: StudyAreaCommand.runCommands(studyAreaList, ui); break; + default: + ui.printLine(); + ui.printMessage(Ui.WRONG_INPUT); + break; } ui.printMessage(Ui.INTERMEDIATE_MESSAGE); ui.printLine(); @@ -61,7 +71,7 @@ public void run() { * Main entry-point for the java.duke.Duke application. * @param args this is an optional argument. */ - public static void main(String[] args) { + public static void main(String[] args) { new Duke().run(); } } diff --git a/src/main/java/studyarea/IllegalStudyAreaException.java b/src/main/java/studyarea/IllegalStudyAreaException.java index f7dabc5a2..b34d9e966 100644 --- a/src/main/java/studyarea/IllegalStudyAreaException.java +++ b/src/main/java/studyarea/IllegalStudyAreaException.java @@ -1,7 +1,7 @@ package studyarea; /** - * This is an extension of the Exception class that exist only for Study Area related modules. + * This is an extension of the Exception class that exist only for StudyArea related modules. */ public class IllegalStudyAreaException extends Exception { diff --git a/src/main/java/studyarea/StudyArea.java b/src/main/java/studyarea/StudyArea.java index b6eb7895f..433db8092 100644 --- a/src/main/java/studyarea/StudyArea.java +++ b/src/main/java/studyarea/StudyArea.java @@ -6,7 +6,7 @@ /** - * This is the Study Area class. All study area is stored as a Study Area object. + * This is the StudyArea class. All study area is stored as a Study Area object. */ public class StudyArea { @@ -18,15 +18,15 @@ public class StudyArea { private int maxPax; /** - * Constructs a Location class for a study area location with its information + * Constructs a StudyArea class for a study area with its information * Precondition: 'All variables have to be filled. * - * @param name name of study location - * @param address address of study location - * @param faculty faculty of study location + * @param name name of StudyArea + * @param address address of StudyArea + * @param faculty faculty of StudyArea * @param hasPort true for availability of ports, else false * @param isIndoor true for indoor, else false - * @param maxPax maximum number of seats for this study area + * @param maxPax maximum number of seats for this StudyArea */ public StudyArea(String name, String address, String faculty, boolean hasPort, @@ -39,26 +39,56 @@ public StudyArea(String name, String address, String faculty, boolean hasPort, this.maxPax = maxPax; } + /** + * This is the getter for the name attribute. + * + * @return general name of the StudyArea. + */ public String getName() { return this.name; } + /** + * This is the getter for the address attribute. + * + * @return physical address of the StudyArea. + */ public String getAddress() { return this.address; } + /** + * This is the getter for the faculty attribute. + * + * @return the name of the faculty that the StudyArea is located at. + */ public String getFaculty() { return this.faculty; } + /** + * This is the getter for the hasPort attribute. + * + * @return true if the StudyArea has ports and false if otherwise. + */ public boolean hasPort() { return this.hasPort; } + /** + * This is the getter for the isIndoor attribute. + * + * @return true if StudyArea is indoors and false if otherwise. + */ public boolean isIndoor() { return this.isIndoor; } + /** + * This is the getter for the maxPax attribute. + * + * @return maximum number of pax the StudyArea can hold. + */ public Integer getMaxPax() { return this.maxPax; } diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 2f36b914c..812f8e4ff 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -110,6 +110,7 @@ public static boolean containsKey(String name, String faculty, String key) { * * @param userIn This is the requirement entered by User * @return ArrayList of StudyAreas + * @throws IllegalStudyAreaException if User enters invalid commands. */ public ArrayList searchList(String userIn) throws IllegalStudyAreaException { diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 06466a359..50d9d3ef4 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -1,6 +1,7 @@ package ui; import studyarea.IllegalStudyAreaException; +import studyarea.StudyArea; import java.io.File; import java.io.InputStream; @@ -12,6 +13,7 @@ /** * Contains functions used to interact with the user. + * */ public class Ui { private final Scanner in; @@ -67,83 +69,130 @@ public class Ui { public static final String EVENT_COMMAND = "event"; public static final String STUDY_COMMAND = "study"; public static final String GOODBYE_MESSAGE = "Goodbye! Hope to see you again!"; - public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or" + - " \"study\" to continue with your study area list. To leave, enter \"bye\"."; - public static final String DAB = "\t ``````````````````````````````````````````````````````````\n" + - "\t ````````````````````````````````:v(v'`````````````````````\n" + - "\t ```````````````````````````,)4|ex` `L}````````````````````\n" + - "\t `````````````````````````!s\"'h `M: ^z_;)T```````````````\n" + - "\t `````````````````````````Z u|}Z: \"}``````````````\n" + - "\t ``````````````````````:=?) 'B?L'```````````\n" + - "\t `````````````````````'Z ;Yp\"```````````\n" + - "\t `````````````````````.e ?_```````````\n" + - "\t ```````````````````'QDGH .5````````````\n" + - "\t ````````````````````I#g' '_` ||````````````\n" + - "\t ```````````:mX_``````YhL` `'q!` ? h````````````\n" + - "\t ```````````'Qbs)|L=_V\" 'Y} ^'q@&b=c=_` ,Z````````````\n" + - "\t ````````````q> 'T, ,o\" ;\"@c. .sVx~`````````````\n" + - "\t ````````````c! \"bh` `,p z:``````````````\n" + - "\t `````````````q. ngDQmh8s X'``````````````\n" + - "\t ``````````````LY\" :n}>``b; _V```````````````\n" + - "\t ````````````````q?, ?; \"V````````````````\n" + - "\t ``````````````KvR ' )x_`````````````````\n" + - "\t ``````````````zjL GLY\"```````````````````\n" + - "\t ```````````````M .I)``````````````````````\n" + - "\t ```````````````Lz `D:``````````````````````\n" + - "\t ``````````````vu` (I)_;\"\". P.`````````````````````\n" + - "\t ``````````````p :X.':^,\"=n \"q``````````````````````\n" + - "\t `````````````)0X?^:)I````````m' :j``````````````````````\n" + - "\t `````````````.IGD8k'`````````<&G55M```````````````````````\n" + - "\t ``````````````````````````````````````````````````````````"; + public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or" + + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; + public static final String EMPTY_LOCATION = "Location entered is empty! Please type a location to search for " + + "StudyAreas!"; + //@@author NizarMohd-reused + //Reused from https://www.netclipart.com/isee/iRwmhJb_bt21-rj-transparent-background/ and https://asciiart.club/ + //Image for public static final String DAB is obtained from the first link and then generated in second link. + public static final String DAB = "\t ``````````````````````````````````````````````````````````\n" + + "\t ````````````````````````````````:v(v'`````````````````````\n" + + "\t ```````````````````````````,)4|ex` `L}````````````````````\n" + + "\t `````````````````````````!s\"'h `M: ^z_;)T```````````````\n" + + "\t `````````````````````````Z u|}Z: \"}``````````````\n" + + "\t ``````````````````````:=?) 'B?L'```````````\n" + + "\t `````````````````````'Z ;Yp\"```````````\n" + + "\t `````````````````````.e ?_```````````\n" + + "\t ```````````````````'QDGH .5````````````\n" + + "\t ````````````````````I#g' '_` ||````````````\n" + + "\t ```````````:mX_``````YhL` `'q!` ? h````````````\n" + + "\t ```````````'Qbs)|L=_V\" 'Y} ^'q@&b=c=_` ,Z````````````\n" + + "\t ````````````q> 'T, ,o\" ;\"@c. .sVx~`````````````\n" + + "\t ````````````c! \"bh` `,p z:``````````````\n" + + "\t `````````````q. ngDQmh8s X'``````````````\n" + + "\t ``````````````LY\" :n}>``b; _V```````````````\n" + + "\t ````````````````q?, ?; \"V````````````````\n" + + "\t ``````````````KvR ' )x_`````````````````\n" + + "\t ``````````````zjL GLY\"```````````````````\n" + + "\t ```````````````M .I)``````````````````````\n" + + "\t ```````````````Lz `D:``````````````````````\n" + + "\t ``````````````vu` (I)_;\"\". P.`````````````````````\n" + + "\t ``````````````p :X.':^,\"=n \"q``````````````````````\n" + + "\t `````````````)0X?^:)I````````m' :j``````````````````````\n" + + "\t `````````````.IGD8k'`````````<&G55M```````````````````````\n" + + "\t ``````````````````````````````````````````````````````````"; + //@@author + + /** + * This is the constructor used to create the Ui class in Duke.run(). + */ public Ui() { this(System.in, System.out); } + /** + * This constructor assigns IO stream to the attributes of Ui. + * + * @param in This is the Input Stream for Ui. + * @param out This is the Output Stream for Ui. + */ public Ui(InputStream in, PrintStream out) { this.in = new Scanner(in); this.out = out; } + /** + * Returns the mode (event features or StudyArea features or exit) based on User input. + * + * @return an integer which is assigned to each mode. + */ public int getMode() { String userIn = this.in.nextLine().toLowerCase(); - switch (userIn) { - case EVENT_COMMAND : - return 1; - case STUDY_COMMAND : - return 2; - case BYE_COMMAND : - return -1; - default : - return 0; - } + switch (userIn) { + case EVENT_COMMAND : + return 1; + case STUDY_COMMAND : + return 2; + case BYE_COMMAND : + return -1; + default : + return 0; + } } - public String getUserIn(){ + /** + * This method allows for other class to get User input. + * + * @return String input from User. + */ + public String getUserIn() { return this.in.nextLine(); } + /** + * This method closes the Input Stream after usage is completed. + */ public void close() { this.in.close(); } - public void printMessage(String message){ - if(message.equals(GOODBYE_MESSAGE+DAB)){ + /** + * This method allows other classes to print messages to interact with User. + * + * @param message This is the message that is intended to be printed to Users. + */ + public void printMessage(String message) { + if (message.equals(GOODBYE_MESSAGE + DAB)) { this.out.println(formatMessage(GOODBYE_MESSAGE, MAX_LINE_LENGTH)); this.out.println(DAB); - }else { + } else { this.out.println(formatMessage(message, MAX_LINE_LENGTH)); } } + /** + * This method allows for StudyAreaCommand to print StudyArea based on its actual format, + * so that formatMessage method does not interfere with the initial format. + * + * @param studyArea This is the StudyArea to be printed. + */ + public void printStudyArea(StudyArea studyArea) { + this.out.println(studyArea.toString()); + } + /** * Prints a line made up of '_'. */ public void printLine() { System.out.println(LINE); } + /** + * This is a modification of a code from Stack Overflow to format strings into a standard length. Minor edition is + * made to ensure suitability with the program. * This method ensures that the message printed is within the standard
* length. * @param message is the String that we intend to format to a standard length
@@ -152,6 +201,9 @@ public void printLine() { * @return String of standard length per line */ + //@@author NizarMohd-reused + //Reused from https://stackoverflow.com/questions/7528045/large-string-split-into-lines-with-maximum-length-in-java + // with minor modification. public static String formatMessage(String message, int maxLength) { StringTokenizer token = new StringTokenizer(message, SPACE); StringBuilder standardLengthMessage = new StringBuilder(message.length()); @@ -167,11 +219,17 @@ public static String formatMessage(String message, int maxLength) { } return TAB + standardLengthMessage.toString().stripTrailing(); } + //@@author /** * Prints the welcome message and starts interaction with user. */ - public void printWelcomeMessage(){ + public void printWelcomeMessage() { + + //@@author NizarMohd-reused + //Reused logo from http://patorjk.com/software/taag/#p=display&f=Graffiti&t=TypeSomething with minor + // modifications. The website above allows for generation of fonts in ascii format. Therefore, logo is + // generated from the service provided by the website. String logo = "_______/\\\\\\\\\\_____________________________________________________/\\\\\\\\\\_____/\\\\\\__" + "__________________________________________/\\\\\\____________\n" + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" @@ -195,6 +253,7 @@ public void printWelcomeMessage(){ + "_/\\\\\\_____\n" + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" + "_\\///______\\////////_____\\//////////______\\///_____"; + //@@author this.out.println("Hello from\n" + logo); this.out.println("What is your name?"); printLine(); @@ -204,4 +263,5 @@ public void printWelcomeMessage(){ this.out.println(formatMessage(START_MESSAGE, MAX_LINE_LENGTH)); printLine(); } + } From b6213a1683d6351d1d7ce401d12543732de978b5 Mon Sep 17 00:00:00 2001 From: hongquan448 Date: Tue, 10 Mar 2020 13:53:57 +0800 Subject: [PATCH 040/435] refactor constants to ui --- src/main/java/seedu/duke/Duke.java | 4 ++++ src/main/java/task/{Tasklist.java => TaskList.java} | 2 +- src/main/java/ui/Ui.java | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) rename src/main/java/task/{Tasklist.java => TaskList.java} (86%) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index e9364ac46..63e266e78 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,10 +1,14 @@ package seedu.duke; import driver.Driver; +import ui.Ui; + import java.util.Scanner; + public class Duke { + private static Ui ui = new Ui(); /** * Main entry-point for the java.duke.Duke application. */ diff --git a/src/main/java/task/Tasklist.java b/src/main/java/task/TaskList.java similarity index 86% rename from src/main/java/task/Tasklist.java rename to src/main/java/task/TaskList.java index 36b2c6758..30f897eef 100644 --- a/src/main/java/task/Tasklist.java +++ b/src/main/java/task/TaskList.java @@ -2,7 +2,7 @@ abstract public class TaskList { /** - * Tasklist is an abstract class that oversees all task-related classes. + * TaskList is an abstract class that oversees all task-related classes. * The current task-related classes are events, deadlines, assignments * TaskList stores all tasks in one large array, allowing the user to access the priorityView and countdownView of all tasks */ diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index c25f51142..0fcb7c1b8 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -86,6 +86,7 @@ public static String formatMessage(String message, int maxLength) { lineLength += word.length() + 1; } return TAB + standardLengthMessage.toString().stripTrailing(); + } public void printHelp() { printLine(); From 6466686c0943d85d91ea5db0fe96839cb7188946 Mon Sep 17 00:00:00 2001 From: hongquan448 Date: Tue, 10 Mar 2020 14:22:08 +0800 Subject: [PATCH 041/435] Refactor ui --- src/main/java/deadline/Deadline.java | 5 +++-- src/main/java/seedu/duke/Duke.java | 2 ++ src/main/java/task/TaskList.java | 13 ++++++++----- src/main/java/ui/Ui.java | 18 ++++++++++++------ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/deadline/Deadline.java b/src/main/java/deadline/Deadline.java index 0cb649257..9ea998dd5 100644 --- a/src/main/java/deadline/Deadline.java +++ b/src/main/java/deadline/Deadline.java @@ -23,9 +23,9 @@ public class Deadline { * @param date Date of specified Deadline * @param dueTime Due time of specified deadline. * @param priority Priority of specified deadline. - * @throws DateTimeParseException If wrong format is used for date, time fields. + * @throws Exception If wrong format is used for date, time fields. */ - public Deadline(String description, String date, String dueTime, String priority) throws Exception{ + public Deadline(String description, String date, String dueTime, String priority) throws Exception { parseDescription(description); parseDate(date); parseDueTime(dueTime); @@ -95,6 +95,7 @@ public LocalDate getDate() { * * @param keyword The keyword to be matched with the description. * @return containsKeyword Indicates the presence/absence of keyword in the deadline's description. + * @throws Exception If no keyword is entered. */ public boolean hasKeyword(String keyword) throws Exception { if (keyword.equals("")) { diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 63e266e78..1abec50a5 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -9,8 +9,10 @@ public class Duke { private static Ui ui = new Ui(); + /** * Main entry-point for the java.duke.Duke application. + * @param args */ public static void main(String[] args) throws Exception { ui.printWelcomeMessage(); diff --git a/src/main/java/task/TaskList.java b/src/main/java/task/TaskList.java index 30f897eef..fdc71eef5 100644 --- a/src/main/java/task/TaskList.java +++ b/src/main/java/task/TaskList.java @@ -1,14 +1,17 @@ package task; -abstract public class TaskList { +public abstract class TaskList { /** * TaskList is an abstract class that oversees all task-related classes. * The current task-related classes are events, deadlines, assignments - * TaskList stores all tasks in one large array, allowing the user to access the priorityView and countdownView of all tasks + * TaskList stores all tasks in one large array, allowing the user to access the priorityView and countdownView of + * all tasks */ - abstract public void priorityView(); - abstract public void countdownView(); - abstract public void searchTasks(); + public abstract void priorityView(); + + public abstract void countdownView(); + + public abstract void searchTasks(); } diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 0fcb7c1b8..89e7aee57 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -64,10 +64,8 @@ public static void printWithIndentation(String line) { public static final String END_MESSAGE = "Thank you for using our study area search service!"; /** - * This method ensures that the message printed is within the standard
- * length. - * @param message is the String that we intend to format to a standard length
- * per line.
+ * This method ensures that the message printed is within the standard length. + * @param message is the String that we intend to format to a standard length per line. * @param maxLength This is the standard length intended to be formatted. * @return String of standard length per line */ @@ -88,6 +86,9 @@ public static String formatMessage(String message, int maxLength) { return TAB + standardLengthMessage.toString().stripTrailing(); } + /** + * Display the list of supported commands. + */ public void printHelp() { printLine(); System.out.println("OrgaNice! Supports the following commands"); @@ -98,16 +99,21 @@ public void printHelp() { System.out.println("priority_view ----------------------------- View existing events based on priority"); System.out.println("countdown --------------------------------- View existing events based on days left"); System.out.println("clear ------------------------------------- Delete all events"); - System.out.println("search ----------- View existing events that contains the keyword"); + System.out.println("search ----------- View existing events that contains " + + "the keyword"); System.out.println("delete ------------ Delete the event"); System.out.println("bye --------------------------------------- Terminate program"); System.out.println("Notes:"); System.out.println("*All dates should follow YYYY-MM-DD format"); System.out.println("*All timing should follow 24 hour clock"); - System.out.println("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the least urgent"); + System.out.println("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " + + "least urgent"); printLine(); } + /** + * Display welcome message. + */ public void printWelcomeMessage() { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" From 89094c699c189533bcb7d4fb8ace6241cd30dca3 Mon Sep 17 00:00:00 2001 From: hongquan448 Date: Tue, 10 Mar 2020 14:28:42 +0800 Subject: [PATCH 042/435] Refactor ui --- src/main/java/seedu/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 1abec50a5..1fa01f6b9 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -12,7 +12,7 @@ public class Duke { /** * Main entry-point for the java.duke.Duke application. - * @param args + * @param args Commandline argument */ public static void main(String[] args) throws Exception { ui.printWelcomeMessage(); From 3b6083b5ad30530cdb9850b7d77f13d733e0f6ae Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Tue, 10 Mar 2020 19:15:18 +0800 Subject: [PATCH 043/435] Revert "Refactor Ui IO stream, Change Logo, Add credits." --- library/eventList.txt | 1 - src/main/java/command/EventCommand.java | 41 +++++---- src/main/java/command/StudyAreaCommand.java | 82 ++++++++---------- src/main/java/driver/Driver.java | 6 +- src/main/java/event/Event.java | 1 - src/main/java/event/EventList.java | 83 ++++++++++--------- src/main/java/resourceloader/EventLoader.java | 2 +- .../java/resourceloader/StudyAreaLoader.java | 1 - src/main/java/seedu/duke/Duke.java | 63 ++++++-------- .../studyarea/IllegalStudyAreaException.java | 2 +- src/main/java/studyarea/StudyArea.java | 42 ++-------- src/main/java/studyarea/StudyAreaList.java | 1 - src/main/java/ui/Ui.java | 78 ++++------------- 13 files changed, 153 insertions(+), 250 deletions(-) diff --git a/library/eventList.txt b/library/eventList.txt index 26a6edc21..e69de29bb 100644 --- a/library/eventList.txt +++ b/library/eventList.txt @@ -1 +0,0 @@ -this event #2020-12-12#13:00#15:00#1 \ No newline at end of file diff --git a/src/main/java/command/EventCommand.java b/src/main/java/command/EventCommand.java index bd4b8ecd4..9e9c98ef9 100644 --- a/src/main/java/command/EventCommand.java +++ b/src/main/java/command/EventCommand.java @@ -1,7 +1,6 @@ package command; import event.EventList; -import resourceloader.EventLoader; import ui.Ui; import java.util.Scanner; @@ -11,56 +10,54 @@ public class EventCommand { /** * Commands for Events. * - * @param eventList this is the evenList. - * @param ui allows for interaction with the User. - * @param eventLoader allows for saving of data after every execution of commands. + * @param eventList evenList */ - public static void runCommands(EventList eventList, Ui ui, EventLoader eventLoader) { + public static void runCommands(EventList eventList) { Scanner in = new Scanner(System.in); String command; - ui.printLine(); command = in.nextLine(); while (!command.equals(Ui.BYE_COMMAND)) { - ui.printLine(); try { String commandType = command.split(" ")[0]; switch (commandType) { case Ui.ADD_COMMAND: - eventList.add(command, ui); + eventList.add(command); break; case Ui.VIEW_COMMAND: - eventList.listEvents(ui); + eventList.listEvents(); break; case Ui.PRIORITY_VIEW_COMMAND: - eventList.priorityView(ui); + eventList.priorityView(); break; case Ui.COUNTDOWN_VIEW_COMMAND: - eventList.countdownView(ui); + eventList.countdownView(); break; case Ui.CLEAR_COMMAND: - eventList.clearEvents(ui); + eventList.clearEvents(); break; case Ui.SEARCH_COMMAND: - eventList.searchEvents(command.split(" ", 2)[1], ui); + eventList.searchEvents(command.split(" ", 2)[1]); break; case Ui.DELETE_COMMAND: - eventList.deleteEvent(Integer.parseInt(command.split(" ", 2)[1]), ui); + eventList.deleteEvent(Integer.parseInt(command.split(" ", 2)[1])); break; default: - ui.printMessage(Ui.INVALID_COMMAND_MESSAGE); + Ui.printLine(); + System.out.println(Ui.INVALID_COMMAND_MESSAGE); + Ui.printLine(); break; } } catch (NumberFormatException e) { - ui.printMessage(Ui.INVALID_INDEX_MESSAGE); + Ui.printLine(); + System.out.println(Ui.INVALID_INDEX_MESSAGE); + Ui.printLine(); } catch (IndexOutOfBoundsException e) { - ui.printMessage(Ui.INVALID_COMMAND_MESSAGE); + Ui.printLine(); + System.out.println(Ui.INVALID_COMMAND_MESSAGE); + Ui.printLine(); } - ui.printLine(); - eventLoader.saveEvents(eventList.events); command = in.nextLine(); } - ui.printLine(); - ui.printMessage(Ui.BYE_MESSAGE); - ui.printLine(); + System.out.println(Ui.BYE_MESSAGE); } } diff --git a/src/main/java/command/StudyAreaCommand.java b/src/main/java/command/StudyAreaCommand.java index a9fd8df49..be6c63ff0 100644 --- a/src/main/java/command/StudyAreaCommand.java +++ b/src/main/java/command/StudyAreaCommand.java @@ -4,26 +4,28 @@ import studyarea.StudyArea; import studyarea.StudyAreaList; import ui.Ui; + +import java.io.FileNotFoundException; import java.util.ArrayList; +import java.util.Scanner; /** - * This is the StudyAreaCommand class. It executes the StudyArea Search function and interact with Users accordingly. + * This is the Study Area Command class. It executes the Study Area Search function and interact with Users accordingly. */ public class StudyAreaCommand { /** - * List out all the StudyAreas that match with User's preference. - * @param ui This allows for StudyAreaCommand to interact with Users. + * List out all the study areas that match with User's preference. * @param availStudyAreas this is the list of all study areas in location.txt. */ - public static void printList(ArrayList availStudyAreas, Ui ui) { + public static void printList(ArrayList availStudyAreas) { if (availStudyAreas.isEmpty()) { - ui.printMessage(Ui.EMPTY_LIST); + System.out.println(Ui.formatMessage(Ui.EMPTY_LIST, Ui.MAX_LINE_LENGTH)); } else { - ui.printMessage(Ui.AVAILABLE_STUDY_AREAS); + System.out.println(Ui.formatMessage(Ui.AVAILABLE_STUDY_AREAS, Ui.MAX_LINE_LENGTH)); for (StudyArea studyArea : availStudyAreas) { - ui.printStudyArea(studyArea); + System.out.println(studyArea.toString()); } } } @@ -32,59 +34,47 @@ public static void printList(ArrayList availStudyAreas, Ui ui) { /** * Filters command based on User Input. * @param command This is the command entered by User. - * @param studyAreaList This is the list of all StudyAreas in location.txt. - * @param ui This allows for StudyAreaCommand to interact with Users. + * @param studyAreaList This is the list of all Study Areas in location.txt. * @return boolean status. False if User enters "end" , else will always return true; - * @throws IllegalStudyAreaException if User enters invalid commands. */ - public static boolean filterCommand(String command, StudyAreaList studyAreaList, Ui ui) throws - IllegalStudyAreaException { - - command = command.trim(); - if (command.isBlank()) { - throw new IllegalStudyAreaException(Ui.EMPTY_LOCATION); - } else { - switch (command) { - case Ui.BYE_COMMAND: - ui.printMessage(Ui.END_MESSAGE); - return false; - case Ui.HELP_COMMAND: - ui.printMessage(Ui.FLAGS); - break; - default: - try { - ArrayList availStudyAreas = studyAreaList.searchList(command); - printList(availStudyAreas, ui); - ui.printMessage(Ui.PROMPT_USER); - } catch (IllegalStudyAreaException e) { - ui.printMessage(e.getMessage()); - } - break; + public static boolean filterCommand(String command, StudyAreaList studyAreaList) { + switch (command) { + case Ui.END_COMMAND : + System.out.println(Ui.formatMessage(Ui.END_MESSAGE, Ui.MAX_LINE_LENGTH)); + return false; + case Ui.HELP_COMMAND : + System.out.println(Ui.FLAGS); + break; + default: + try { + ArrayList availStudyAreas = studyAreaList.searchList(command); + printList(availStudyAreas); + System.out.println(Ui.formatMessage(Ui.PROMPT_USER, Ui.MAX_LINE_LENGTH)); + } catch (IllegalStudyAreaException e) { + System.out.println(Ui.formatMessage(e.getMessage(), Ui.MAX_LINE_LENGTH)); } } return true; } /** - * Executes the StudyArea search feature. - * @param ui This allows for StudyAreaCommand to interact with Users. + * Executes the Study Area search feature. * @param studyAreaList studyAreaList object that holds information on studyAreas available. */ - public static void runCommands(StudyAreaList studyAreaList, Ui ui) { + public static void runCommands(StudyAreaList studyAreaList) { + + Ui ui = new Ui(); ui.printLine(); - ui.printMessage(Ui.START_STUDY_AREA_SEARCH); + System.out.println(Ui.formatMessage(Ui.START_STUDY_AREA_SEARCH, Ui.MAX_LINE_LENGTH)); + Scanner in = new Scanner(System.in); boolean status = true; while (status) { - ui.printLine(); - String command = ui.getUserIn(); - ui.printLine(); - try { - status = filterCommand(command, studyAreaList, ui); - } catch (IllegalStudyAreaException e) { - ui.printMessage(e.getMessage()); - } + Ui.printLine(); + String command = in.nextLine(); + Ui.printLine(); + status = filterCommand(command, studyAreaList); } - ui.printLine(); + Ui.printLine(); } } diff --git a/src/main/java/driver/Driver.java b/src/main/java/driver/Driver.java index 60d6528f0..a09b7c01a 100644 --- a/src/main/java/driver/Driver.java +++ b/src/main/java/driver/Driver.java @@ -30,14 +30,14 @@ public Driver(int mode) throws FileNotFoundException, IllegalStudyAreaException studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); StudyAreaList studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); - Ui ui = new Ui(); + if (mode == 1) { EventCommand eventCommand = new EventCommand(); - eventCommand.runCommands(eventList, ui, eventLoader); + eventCommand.runCommands(eventList); eventLoader.saveEvents(eventList.events); } else { StudyAreaCommand studyAreaCommand = new StudyAreaCommand(); - studyAreaCommand.runCommands(studyAreaList, ui); + studyAreaCommand.runCommands(studyAreaList); } } } diff --git a/src/main/java/event/Event.java b/src/main/java/event/Event.java index 1a1002eea..487c48845 100644 --- a/src/main/java/event/Event.java +++ b/src/main/java/event/Event.java @@ -112,7 +112,6 @@ public LocalDate getDate() { * * @param keyword The keyword to be matched with the description. * @return containsKeyword Indicates the presence/absence of keyword in the event's description. - * @throws Exception to be edited */ public boolean hasKeyword(String keyword) throws Exception { if (keyword.equals("")) { diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index c6be85b54..947d606da 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -11,6 +11,7 @@ */ public class EventList { + Ui ui = new Ui(); /** Stores the event information. */ public ArrayList events; @@ -29,104 +30,108 @@ public EventList(ArrayList events) { /** * Adds a new event to the list. * - * @param ui This allows Event List class to interact with User. * @param newEvent Event represents the new event tot be added. */ - public void addEvent(Event newEvent, Ui ui) { + public void addEvent(Event newEvent) { + ui.printLine(); events.add(newEvent); - ui.printMessage("A new event with the following information has been added."); - ui.printMessage(newEvent.getEventInformation()); + ui.printWithIndentation("A new event with the following information has been added."); + ui.printWithIndentation(newEvent.getEventInformation()); + ui.printLine(); } /** * Displays the current list of events. - * - * @param ui This allows Event List class to interact with User. */ - public void listEvents(Ui ui) { - ui.printMessage("Here is the list of events added so far:"); + public void listEvents() { + ui.printLine(); + System.out.println("Here is the list of events added so far:"); int eventNumber = 1; for (Event event: events) { - ui.printMessage(eventNumber + ") " + event.getEventInformation()); + ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); eventNumber++; } + ui.printLine(); } /** * Deletes the event at the specified index. * - * @param ui This allows Event List class to interact with User. * @param index The index (1-based) of the event to be deleted. */ - public void deleteEvent(int index, Ui ui) { + public void deleteEvent(int index) { try { events.remove(index - 1); - ui.printMessage("The event at the mentioned index has been deleted"); + ui.printLine(); + ui.printWithIndentation("The event at the mentioned index has been deleted"); + ui.printLine(); } catch (IndexOutOfBoundsException e) { - ui.printMessage("Enter a valid index"); + ui.printLine(); + ui.printWithIndentation("Enter a valid index"); + ui.printLine(); } } /** * Clears all the events currently stored. - * - * @param ui This allows Event List class to interact with User. */ - public void clearEvents(Ui ui) { + public void clearEvents() { events.clear(); - ui.printMessage("The list of events is cleared."); + ui.printLine(); + ui.printWithIndentation("The list of events is cleared."); + ui.printLine(); } /** * Lists all the tasks sorted by their priority. - * - * @param ui This allows Event List class to interact with User. */ - public void priorityView(Ui ui) { + public void priorityView() { ArrayList eventsSortedByPriority = events; eventsSortedByPriority.sort(Comparator.comparingInt(Event::getPriority)); Collections.reverse(eventsSortedByPriority); + ui.printLine(); int eventNumber = 1; for (Event event:eventsSortedByPriority) { - ui.printMessage(eventNumber + ") " + event.getEventInformation()); + ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); eventNumber++; } if (eventNumber == 1) { - ui.printMessage("The list is empty."); + ui.printWithIndentation("The list is empty."); } + ui.printLine(); } /** * Lists all the tasks sorted by date along with the days remaining. - * - * @param ui This allows Event List class to interact with User. */ - public void countdownView(Ui ui) { + public void countdownView() { ArrayList eventsSortedByDate = events; eventsSortedByDate.sort(Comparator.comparing(Event::getDate)); + ui.printLine(); int eventNumber = 1; for (Event event:eventsSortedByDate) { - ui.printMessage(eventNumber + ") " + event.getEventInformation()); + ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); eventNumber++; } if (eventNumber == 1) { - ui.printMessage("The list is empty."); + ui.printWithIndentation("The list is empty."); } + ui.printLine(); } /** * Displays the list of events containing the keyword. * - * @param ui This allows Event List class to interact with User. * @param keyword The keyword to be searched for. */ - public void searchEvents(String keyword, Ui ui) { + public void searchEvents(String keyword) { + ui.printLine(); int eventNumber = 1; for (Event event:events) { try { if (event.hasKeyword(keyword)) { - ui.printMessage(eventNumber + ") " + event.getEventInformation()); + ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); eventNumber++; } } catch (Exception e) { @@ -134,19 +139,19 @@ public void searchEvents(String keyword, Ui ui) { } } if (eventNumber == 1) { - ui.printMessage("The list is empty."); + ui.printWithIndentation("The list is empty."); } + ui.printLine(); } /** * Adds a new event to the list by parsing information from the user given string - * and calling {@link #addEvent(Event, Ui)} if the information is given in the correct format + * and calling {@link #addEvent(Event)} if the information is given in the correct format * to add the event. * - * @param ui This allows Event List class to interact with User. * @param eventDetails Contains all the information related to the event as provided by the user. */ - public void add(String eventDetails, Ui ui) { + public void add(String eventDetails) { try { String[] details = eventDetails.split(" ",2)[1].split("/"); String description = details[0]; @@ -155,11 +160,15 @@ public void add(String eventDetails, Ui ui) { String endTime = details[3].substring(2); String priority = details[4].substring(2); Event newEvent = new Event(description,date,startTime,endTime,priority); - addEvent(newEvent, ui); + addEvent(newEvent); } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { - ui.printMessage("Wrong format to add events"); + ui.printLine(); + ui.printWithIndentation("Wrong format to add events"); + ui.printLine(); } catch (Exception e) { - ui.printMessage(e.getMessage()); + ui.printLine(); + ui.printWithIndentation(e.getMessage()); + ui.printLine(); } } } diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java index c1f81376a..9326382c0 100644 --- a/src/main/java/resourceloader/EventLoader.java +++ b/src/main/java/resourceloader/EventLoader.java @@ -58,7 +58,7 @@ public ArrayList loadFile() { createNewDataFile(); } catch (Exception e) { ui.printLine(); - ui.printMessage(e.getMessage()); + ui.printWithIndentation(e.getMessage()); ui.printLine(); } return events; diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index c26dd4f69..0cee4dcc5 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -42,7 +42,6 @@ public void loadFile() throws FileNotFoundException { * * @return buffer ArrayList of Location from study area file * @throws FileNotFoundException if location.txt does not exist. - * @throws IllegalStudyAreaException if data stored is inconsistent */ public ArrayList pushToDatabase() throws FileNotFoundException, IllegalStudyAreaException { diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 9b09c3fe7..1fa01f6b9 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,50 +1,37 @@ package seedu.duke; +import driver.Driver; +import ui.Ui; + +import java.util.Scanner; + + public class Duke { - private static EventLoader eventLoader; - protected static StudyAreaLoader studyAreaLoader; - private static EventList eventList; - private static StudyAreaList studyAreaList; private static Ui ui = new Ui(); /** - * This method runs the program. + * Main entry-point for the java.duke.Duke application. + * @param args Commandline argument */ - public void run() { - Ui ui = new Ui(); + public static void main(String[] args) throws Exception { ui.printWelcomeMessage(); - boolean status = true; - while (status) { - int mode = ui.getMode(); - switch (mode) { - case -1: - status = false; - break; - case 1: - EventCommand.runCommands(eventList, ui, eventLoader); - eventLoader.saveEvents(eventList.events); - break; - case 2: - StudyAreaCommand.runCommands(studyAreaList, ui); - break; - default: - ui.printLine(); - ui.printMessage(Ui.WRONG_INPUT); - break; - } - ui.printMessage(Ui.INTERMEDIATE_MESSAGE); - ui.printLine(); - } - ui.printMessage(Ui.GOODBYE_MESSAGE + Ui.DAB); - ui.close(); - } - /** - * Main entry-point for the java.duke.Duke application. - * @param args this is an optional argument. - */ - public static void main(String[] args) { - new Duke().run(); + Scanner in = new Scanner(System.in); + System.out.println("Hello " + in.nextLine()); + + /** + * To run: + * events: enter 1 + * study areas: enter 0 + * To end events loop: enter bye in events prog + * To end study areas loop: enter end in study area loop + * To end overall prog, enter ctrl+c or ctrl+z + * Take note: this is still temporary + */ + while (true) { + Scanner mode = new Scanner(System.in); + Driver driver = new Driver(mode.nextInt()); + } } } diff --git a/src/main/java/studyarea/IllegalStudyAreaException.java b/src/main/java/studyarea/IllegalStudyAreaException.java index b34d9e966..f7dabc5a2 100644 --- a/src/main/java/studyarea/IllegalStudyAreaException.java +++ b/src/main/java/studyarea/IllegalStudyAreaException.java @@ -1,7 +1,7 @@ package studyarea; /** - * This is an extension of the Exception class that exist only for StudyArea related modules. + * This is an extension of the Exception class that exist only for Study Area related modules. */ public class IllegalStudyAreaException extends Exception { diff --git a/src/main/java/studyarea/StudyArea.java b/src/main/java/studyarea/StudyArea.java index 433db8092..b6eb7895f 100644 --- a/src/main/java/studyarea/StudyArea.java +++ b/src/main/java/studyarea/StudyArea.java @@ -6,7 +6,7 @@ /** - * This is the StudyArea class. All study area is stored as a Study Area object. + * This is the Study Area class. All study area is stored as a Study Area object. */ public class StudyArea { @@ -18,15 +18,15 @@ public class StudyArea { private int maxPax; /** - * Constructs a StudyArea class for a study area with its information + * Constructs a Location class for a study area location with its information * Precondition: 'All variables have to be filled. * - * @param name name of StudyArea - * @param address address of StudyArea - * @param faculty faculty of StudyArea + * @param name name of study location + * @param address address of study location + * @param faculty faculty of study location * @param hasPort true for availability of ports, else false * @param isIndoor true for indoor, else false - * @param maxPax maximum number of seats for this StudyArea + * @param maxPax maximum number of seats for this study area */ public StudyArea(String name, String address, String faculty, boolean hasPort, @@ -39,56 +39,26 @@ public StudyArea(String name, String address, String faculty, boolean hasPort, this.maxPax = maxPax; } - /** - * This is the getter for the name attribute. - * - * @return general name of the StudyArea. - */ public String getName() { return this.name; } - /** - * This is the getter for the address attribute. - * - * @return physical address of the StudyArea. - */ public String getAddress() { return this.address; } - /** - * This is the getter for the faculty attribute. - * - * @return the name of the faculty that the StudyArea is located at. - */ public String getFaculty() { return this.faculty; } - /** - * This is the getter for the hasPort attribute. - * - * @return true if the StudyArea has ports and false if otherwise. - */ public boolean hasPort() { return this.hasPort; } - /** - * This is the getter for the isIndoor attribute. - * - * @return true if StudyArea is indoors and false if otherwise. - */ public boolean isIndoor() { return this.isIndoor; } - /** - * This is the getter for the maxPax attribute. - * - * @return maximum number of pax the StudyArea can hold. - */ public Integer getMaxPax() { return this.maxPax; } diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 812f8e4ff..2f36b914c 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -110,7 +110,6 @@ public static boolean containsKey(String name, String faculty, String key) { * * @param userIn This is the requirement entered by User * @return ArrayList of StudyAreas - * @throws IllegalStudyAreaException if User enters invalid commands. */ public ArrayList searchList(String userIn) throws IllegalStudyAreaException { diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index e7602f670..89e7aee57 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -1,26 +1,15 @@ package ui; -import studyarea.IllegalStudyAreaException; -import studyarea.StudyArea; - import java.io.File; -import java.io.InputStream; -import java.io.PrintStream; -import java.util.Scanner; import java.util.StringTokenizer; -import static java.lang.System.lineSeparator; - /** * Contains functions used to interact with the user. - * */ public class Ui { - private final Scanner in; - private final PrintStream out; - public static final String FILE_PATH_EVENTS = "library" + File.separator + "eventList.txt"; public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; + public static final String ADD_COMMAND = "add"; public static final String VIEW_COMMAND = "view"; public static final String PRIORITY_VIEW_COMMAND = "priority_view"; @@ -32,8 +21,18 @@ public class Ui { public static final String INVALID_COMMAND_MESSAGE = "Enter a valid command"; public static final String BYE_COMMAND = "bye"; public static final String BYE_MESSAGE = "Bye!!!!!!"; - public static final String LINE = "_______________________________________________________________________________" - + "_____"; + + /** + * Prints a line made up of '_'. + */ + public static void printLine() { + System.out.println("____________________________________________________________________________________"); + } + + public static void printWithIndentation(String line) { + System.out.println(" " + line); + } + public static final int MAX_LINE_LENGTH = 55; public static final int ADDRESS_MAX_LENGTH = 48; public static final String FLAG = "-"; @@ -49,7 +48,7 @@ public class Ui { public static final String WRONG_FLAG_ARGUMENT_POSITION = "Flags are to be used only after location"; public static final String START_STUDY_AREA_SEARCH = "Please enter the location for your desired study area. " + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" - + " location is entered. When you are done with the search, enter \"bye\"."; + + " location is entered. When you are done with the search, enter \"end\"."; public static final String PROMPT_USER = "Please enter the location for your desired study area."; public static final String FLAGS = "\t Here is a list of supported flags!\n\t -p for study areas with ports\n\t" + " -i for study areas that are indoors\n\t -s {size} for maximum number of pax"; @@ -58,53 +57,11 @@ public class Ui { + "area!"; public static final String ONLY_FLAG = "Please enter the flag along with \"-\""; public static final String INCONSISTENT_DATA_STORAGE = "Data is wrongly stored in locations.txt"; + public static final String END_COMMAND = "end"; public static final String HELP_COMMAND = "help"; public static final String TAB = "\t "; public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; - public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"event\" to start your event" - + " list! If you are in the mood to mug and you want to start your study area list, enter \"study\" !" - + "If you want to exit, enter \"bye\" !"; - public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; - public static final String EVENT_COMMAND = "event"; - public static final String STUDY_COMMAND = "study"; - public static final String GOODBYE_MESSAGE = "Goodbye! Hope to see you again!"; - public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or" - + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; - public static final String EMPTY_LOCATION = "Location entered is empty! Please type a location to search for " - + "StudyAreas!"; - - //@@author NizarMohd-reused - //Reused from https://www.netclipart.com/isee/iRwmhJb_bt21-rj-transparent-background/ and https://asciiart.club/ - //Image for public static final String DAB is obtained from the first link and then generated in second link. - public static final String DAB = "\t ``````````````````````````````````````````````````````````\n" - + "\t ````````````````````````````````:v(v'`````````````````````\n" - + "\t ```````````````````````````,)4|ex` `L}````````````````````\n" - + "\t `````````````````````````!s\"'h `M: ^z_;)T```````````````\n" - + "\t `````````````````````````Z u|}Z: \"}``````````````\n" - + "\t ``````````````````````:=?) 'B?L'```````````\n" - + "\t `````````````````````'Z ;Yp\"```````````\n" - + "\t `````````````````````.e ?_```````````\n" - + "\t ```````````````````'QDGH .5````````````\n" - + "\t ````````````````````I#g' '_` ||````````````\n" - + "\t ```````````:mX_``````YhL` `'q!` ? h````````````\n" - + "\t ```````````'Qbs)|L=_V\" 'Y} ^'q@&b=c=_` ,Z````````````\n" - + "\t ````````````q> 'T, ,o\" ;\"@c. .sVx~`````````````\n" - + "\t ````````````c! \"bh` `,p z:``````````````\n" - + "\t `````````````q. ngDQmh8s X'``````````````\n" - + "\t ``````````````LY\" :n}>``b; _V```````````````\n" - + "\t ````````````````q?, ?; \"V````````````````\n" - + "\t ``````````````KvR ' )x_`````````````````\n" - + "\t ``````````````zjL GLY\"```````````````````\n" - + "\t ```````````````M .I)``````````````````````\n" - + "\t ```````````````Lz `D:``````````````````````\n" - + "\t ``````````````vu` (I)_;\"\". P.`````````````````````\n" - + "\t ``````````````p :X.':^,\"=n \"q``````````````````````\n" - + "\t `````````````)0X?^:)I````````m' :j``````````````````````\n" - + "\t `````````````.IGD8k'`````````<&G55M```````````````````````\n" - + "\t ``````````````````````````````````````````````````````````"; - //@@author - /** * This method ensures that the message printed is within the standard length. @@ -113,9 +70,6 @@ public class Ui { * @return String of standard length per line */ - //@@author NizarMohd-reused - //Reused from https://stackoverflow.com/questions/7528045/large-string-split-into-lines-with-maximum-length-in-java - // with minor modification. public static String formatMessage(String message, int maxLength) { StringTokenizer token = new StringTokenizer(message, SPACE); StringBuilder standardLengthMessage = new StringBuilder(message.length()); @@ -131,7 +85,7 @@ public static String formatMessage(String message, int maxLength) { } return TAB + standardLengthMessage.toString().stripTrailing(); } - + /** * Display the list of supported commands. */ From 232d04764bcd63fe95561fa325077ace227107d8 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Tue, 10 Mar 2020 19:42:40 +0800 Subject: [PATCH 044/435] Add Deadline with #35. --- src/main/java/deadline/DeadlineList.java | 57 +++--- src/main/java/driver/Driver.java | 43 ----- src/main/java/resourceloader/EventLoader.java | 1 - src/main/java/seedu/duke/Duke.java | 31 ++- src/main/java/studyarea/StudyAreaList.java | 2 - src/main/java/ui/Ui.java | 178 ++++++++++++++---- 6 files changed, 207 insertions(+), 105 deletions(-) delete mode 100644 src/main/java/driver/Driver.java diff --git a/src/main/java/deadline/DeadlineList.java b/src/main/java/deadline/DeadlineList.java index e6c0fd27f..d010273c8 100644 --- a/src/main/java/deadline/DeadlineList.java +++ b/src/main/java/deadline/DeadlineList.java @@ -11,7 +11,6 @@ */ public class DeadlineList { - Ui ui = new Ui(); /** Stores the deadline information. */ public ArrayList deadlines; @@ -31,24 +30,26 @@ public DeadlineList(ArrayList deadlines) { * Adds a new deadline to the list. * * @param newDeadline Deadline represents the new deadline tot be added. + * @param ui This allows for the deadline class to interact with Users. */ - public void addDeadline(Deadline newDeadline) { + public void addDeadline(Deadline newDeadline, Ui ui) { ui.printLine(); deadlines.add(newDeadline); - ui.printWithIndentation("A new deadline with the following information has been added."); - ui.printWithIndentation(newDeadline.getDeadlineInformation()); + ui.printMessage("A new deadline with the following information has been added."); + ui.printMessage(newDeadline.getDeadlineInformation()); ui.printLine(); } /** * Displays the current list of deadlines. + * @param ui This allows for the deadline class to interact with Users. */ - public void listDeadlines() { + public void listDeadlines(Ui ui) { ui.printLine(); System.out.println("Here is the list of deadlines added so far:"); int deadlineNumber = 1; for (Deadline deadline: deadlines) { - ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } ui.printLine(); @@ -58,16 +59,17 @@ public void listDeadlines() { * Deletes the deadline at the specified index. * * @param index The index (1-based) of the deadline to be deleted. + * @param ui This allows for the deadline class to interact with Users. */ - public void deleteDeadline(int index) { + public void deleteDeadline(int index, Ui ui) { try { deadlines.remove(index - 1); ui.printLine(); - ui.printWithIndentation("The deadline at the mentioned index has been deleted"); + ui.printMessage("The deadline at the mentioned index has been deleted"); ui.printLine(); } catch (IndexOutOfBoundsException e) { ui.printLine(); - ui.printWithIndentation("Enter a valid index"); + ui.printMessage("Enter a valid index"); ui.printLine(); } @@ -75,47 +77,50 @@ public void deleteDeadline(int index) { /** * Clears all the deadlines currently stored. + * @param ui This allows for the deadline class to interact with Users. */ - public void clearDeadlines() { + public void clearDeadlines(Ui ui) { deadlines.clear(); ui.printLine(); - ui.printWithIndentation("The list of deadlines is cleared."); + ui.printMessage("The list of deadlines is cleared."); ui.printLine(); } /** * Lists all the tasks sorted by their priority. + * @param ui This allows for the deadline class to interact with Users. */ - public void priorityView() { + public void priorityView(Ui ui) { ArrayList deadlinesSortedByPriority = deadlines; deadlinesSortedByPriority.sort(Comparator.comparingInt(Deadline::getPriority)); Collections.reverse(deadlinesSortedByPriority); ui.printLine(); int deadlineNumber = 1; for (Deadline deadline:deadlinesSortedByPriority) { - ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } if (deadlineNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } ui.printLine(); } /** * Lists all the tasks sorted by date along with the days remaining. + * @param ui This allows for the deadline class to interact with Users. */ - public void countdownView() { + public void countdownView(Ui ui) { ArrayList deadlinesSortedByDate = deadlines; deadlinesSortedByDate.sort(Comparator.comparing(Deadline::getDate)); ui.printLine(); int deadlineNumber = 1; for (Deadline deadline:deadlinesSortedByDate) { - ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } if (deadlineNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } ui.printLine(); } @@ -124,14 +129,15 @@ public void countdownView() { * Displays the list of deadlines containing the keyword. * * @param keyword The keyword to be searched for. + * @param ui This allows for the deadline class to interact with Users. */ - public void searchDeadlines(String keyword) { + public void searchDeadlines(String keyword, Ui ui) { ui.printLine(); int deadlineNumber = 1; for (Deadline deadline:deadlines) { try { if (deadline.hasKeyword(keyword)) { - ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } } catch (Exception e) { @@ -139,19 +145,20 @@ public void searchDeadlines(String keyword) { } } if (deadlineNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } ui.printLine(); } /** * Adds a new deadline to the list by parsing information from the user given string - * and calling {@link #addDeadline(Deadline)} if the information is given in the correct format + * and calling {@link #addDeadline(Deadline, Ui)} if the information is given in the correct format * to add the deadline. * * @param deadlineDetails Contains all the information related to the deadline as provided by the user. + * @param ui This allows for the deadline class to interact with Users. */ - public void add(String deadlineDetails) { + public void add(String deadlineDetails, Ui ui) { try { String[] details = deadlineDetails.split(" ",2)[1].split("/"); String description = details[0]; @@ -159,14 +166,14 @@ public void add(String deadlineDetails) { String dueTime = details[2].substring(2); String priority = details[3].substring(2); Deadline newDeadline = new Deadline(description,date,dueTime, priority); - addDeadline(newDeadline); + addDeadline(newDeadline, ui); } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { ui.printLine(); - ui.printWithIndentation("Wrong format to add deadlines"); + ui.printMessage("Wrong format to add deadlines"); ui.printLine(); } catch (Exception e) { ui.printLine(); - ui.printWithIndentation(e.getMessage()); + ui.printMessage(e.getMessage()); ui.printLine(); } } diff --git a/src/main/java/driver/Driver.java b/src/main/java/driver/Driver.java deleted file mode 100644 index 60d6528f0..000000000 --- a/src/main/java/driver/Driver.java +++ /dev/null @@ -1,43 +0,0 @@ -package driver; - -import command.EventCommand; -import event.EventList; -import java.io.FileNotFoundException; - -import resourceloader.EventLoader; -import resourceloader.StudyAreaLoader; -import studyarea.IllegalStudyAreaException; -import command.StudyAreaCommand; -import studyarea.StudyAreaList; -import ui.Ui; - -public class Driver { - public static EventLoader eventLoader; - public static StudyAreaLoader studyAreaLoader; - - /** - * Constructor for Driver Class. - * This class setups the loading of events and study areas into - * the program and runs either study area or organiser functionality. - * - * @param mode 1 for organiser, 0 for study area - * @throws FileNotFoundException if file is not found. - * @throws IllegalStudyAreaException custom exception for study area - */ - public Driver(int mode) throws FileNotFoundException, IllegalStudyAreaException { - eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); - EventList eventList = new EventList(eventLoader.loadFile()); - - studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); - StudyAreaList studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); - Ui ui = new Ui(); - if (mode == 1) { - EventCommand eventCommand = new EventCommand(); - eventCommand.runCommands(eventList, ui, eventLoader); - eventLoader.saveEvents(eventList.events); - } else { - StudyAreaCommand studyAreaCommand = new StudyAreaCommand(); - studyAreaCommand.runCommands(studyAreaList, ui); - } - } -} diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java index c1f81376a..da13d1641 100644 --- a/src/main/java/resourceloader/EventLoader.java +++ b/src/main/java/resourceloader/EventLoader.java @@ -2,7 +2,6 @@ import event.Event; import ui.Ui; - import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 9b09c3fe7..3388c1a8f 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,12 +1,39 @@ package seedu.duke; +import command.EventCommand; +import command.StudyAreaCommand; +import event.EventList; +import resourceloader.EventLoader; +import resourceloader.StudyAreaLoader; +import studyarea.IllegalStudyAreaException; +import studyarea.StudyAreaList; +import ui.Ui; +import java.io.FileNotFoundException; + +/** + * This is Duke class, which forms the main class of the program. + */ public class Duke { private static EventLoader eventLoader; protected static StudyAreaLoader studyAreaLoader; private static EventList eventList; private static StudyAreaList studyAreaList; - private static Ui ui = new Ui(); + /** + * This is the constructor to create a new Duke program every time user runs the main loop. + */ + public Duke() { + try { + eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); + eventList = new EventList(eventLoader.loadFile()); + studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); + studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); + } catch (FileNotFoundException | IllegalStudyAreaException e) { + Ui ui = new Ui(); + ui.printMessage(e.getMessage()); + ui.close(); + } + } /** * This method runs the program. @@ -47,4 +74,4 @@ public void run() { public static void main(String[] args) { new Duke().run(); } -} +} \ No newline at end of file diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 812f8e4ff..8bd3fe9ad 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -1,8 +1,6 @@ package studyarea; import ui.Ui; - -import java.io.FileNotFoundException; import java.util.ArrayList; /** diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index e7602f670..157a049fe 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -1,16 +1,13 @@ package ui; -import studyarea.IllegalStudyAreaException; -import studyarea.StudyArea; +import studyarea.StudyArea; import java.io.File; import java.io.InputStream; import java.io.PrintStream; import java.util.Scanner; import java.util.StringTokenizer; -import static java.lang.System.lineSeparator; - /** * Contains functions used to interact with the user. * @@ -107,8 +104,96 @@ public class Ui { /** - * This method ensures that the message printed is within the standard length. - * @param message is the String that we intend to format to a standard length per line. + * This is the constructor used to create the Ui class in Duke.run(). + */ + public Ui() { + this(System.in, System.out); + } + + /** + * This constructor assigns IO stream to the attributes of Ui. + * + * @param in This is the Input Stream for Ui. + * @param out This is the Output Stream for Ui. + */ + public Ui(InputStream in, PrintStream out) { + this.in = new Scanner(in); + this.out = out; + } + + /** + * Returns the mode (event features or StudyArea features or exit) based on User input. + * + * @return an integer which is assigned to each mode. + */ + public int getMode() { + String userIn = this.in.nextLine().toLowerCase(); + switch (userIn) { + case EVENT_COMMAND : + return 1; + case STUDY_COMMAND : + return 2; + case BYE_COMMAND : + return -1; + default : + return 0; + } + } + + /** + * This method allows for other class to get User input. + * + * @return String input from User. + */ + public String getUserIn() { + return this.in.nextLine(); + } + + /** + * This method closes the Input Stream after usage is completed. + */ + public void close() { + this.in.close(); + } + + /** + * This method allows other classes to print messages to interact with User. + * + * @param message This is the message that is intended to be printed to Users. + */ + public void printMessage(String message) { + if (message.equals(GOODBYE_MESSAGE + DAB)) { + this.out.println(formatMessage(GOODBYE_MESSAGE, MAX_LINE_LENGTH)); + this.out.println(DAB); + } else { + this.out.println(formatMessage(message, MAX_LINE_LENGTH)); + } + } + + /** + * This method allows for StudyAreaCommand to print StudyArea based on its actual format, + * so that formatMessage method does not interfere with the initial format. + * + * @param studyArea This is the StudyArea to be printed. + */ + public void printStudyArea(StudyArea studyArea) { + this.out.println(studyArea.toString()); + } + + /** + * Prints a line made up of '_'. + */ + public void printLine() { + System.out.println(LINE); + } + + /** + * This is a modification of a code from Stack Overflow to format strings into a standard length. Minor edition is + * made to ensure suitability with the program. + * This method ensures that the message printed is within the standard
+ * length. + * @param message is the String that we intend to format to a standard length
+ * per line.
* @param maxLength This is the standard length intended to be formatted. * @return String of standard length per line */ @@ -131,42 +216,71 @@ public static String formatMessage(String message, int maxLength) { } return TAB + standardLengthMessage.toString().stripTrailing(); } - + //@@author + /** * Display the list of supported commands. */ public void printHelp() { - printLine(); - System.out.println("OrgaNice! Supports the following commands"); - System.out.println("Please enter the keywords followed by the information shown in the brackets"); - System.out.println("add /d /s /e /p "); - System.out.println("------------------------------------------- Create a new event"); - System.out.println("view -------------------------------------- View existing events"); - System.out.println("priority_view ----------------------------- View existing events based on priority"); - System.out.println("countdown --------------------------------- View existing events based on days left"); - System.out.println("clear ------------------------------------- Delete all events"); - System.out.println("search ----------- View existing events that contains " + this.out.println("OrgaNice! Supports the following commands"); + this.out.println("Please enter the keywords followed by the information shown in the brackets"); + this.out.println("add /d /s /e /p "); + this.out.println("------------------------------------------- Create a new event"); + this.out.println("view -------------------------------------- View existing events"); + this.out.println("priority_view ----------------------------- View existing events based on priority"); + this.out.println("countdown --------------------------------- View existing events based on days left"); + this.out.println("clear ------------------------------------- Delete all events"); + this.out.println("search ----------- View existing events that contains " + "the keyword"); - System.out.println("delete ------------ Delete the event"); - System.out.println("bye --------------------------------------- Terminate program"); - System.out.println("Notes:"); - System.out.println("*All dates should follow YYYY-MM-DD format"); - System.out.println("*All timing should follow 24 hour clock"); - System.out.println("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " + this.out.println("delete ------------ Delete the event"); + this.out.println("bye --------------------------------------- Terminate program"); + this.out.println("Notes:"); + this.out.println("*All dates should follow YYYY-MM-DD format"); + this.out.println("*All timing should follow 24 hour clock"); + this.out.println("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " + "least urgent"); - printLine(); } /** - * Display welcome message. + * Prints the welcome message and starts interaction with user. */ public void printWelcomeMessage() { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - System.out.println("What is your name?"); + + //@@author NizarMohd-reused + //Reused logo from http://patorjk.com/software/taag/#p=display&f=Graffiti&t=TypeSomething with minor + // modifications. The website above allows for generation of fonts in ascii format. Therefore, logo is + // generated from the service provided by the website. + String logo = "_______/\\\\\\\\\\_____________________________________________________/\\\\\\\\\\_____/\\\\\\__" + + "__________________________________________/\\\\\\____________\n" + + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" + + "_________________________________________/\\\\\\\\\\\\\\_________\n" + + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" + + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______\n" + + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" + + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\_______\n" + + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" + + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" + + "___\n" + + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" + + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" + + "_____\n" + + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" + + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______\n" + + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\\\/\\\\" + + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" + + "_/\\\\\\_____\n" + + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" + + "_\\///______\\////////_____\\//////////______\\///_____"; + //@@author + this.out.println("Hello from\n" + logo); + this.out.println("What is your name?"); + printLine(); + String name = this.in.nextLine(); + printLine(); + this.out.println(TAB + "Hello " + name + "!"); + this.out.println(formatMessage(START_MESSAGE, MAX_LINE_LENGTH)); + printLine(); } } From cb1907aabe01760a87165c0602e65410ba6ae247 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Tue, 10 Mar 2020 19:43:25 +0800 Subject: [PATCH 045/435] Edit ui test --- text-ui-test/ACTUAL.TXT | 16 +++++++++------- text-ui-test/EXPECTED.TXT | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 892cb6cae..6c3564410 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -1,9 +1,11 @@ Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +_______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ +______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ +_____/\\\/__\///\\\____________________/\\\\\\\\___________________\/\\\/\\\__\/\\\___/\\\__________________________________/\\\\\\\\\_______ +_____/\\\______\//\\\___/\\/\\\\\\\____/\\\////\\\___/\\\\\\\\\_____\/\\\//\\\_\/\\\__\///_______/\\\\\\\\______/\\\\\\\\___\//\\\\\\\_______ +_____\/\\\_______\/\\\__\/\\\/////\\\__\//\\\\\\\\\__\////////\\\____\/\\\\//\\\\/\\\___/\\\____/\\\//////_____/\\\/////\\\___\//\\\\\_______ +______\//\\\______/\\\___\/\\\___\///____\///////\\\____/\\\\\\\\\\___\/\\\_\//\\\/\\\__\/\\\___/\\\___________/\\\\\\\\\\\_____\//\\\_______ +________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\//\\\\\\__\/\\\__\//\\\_________\//\\///////_______\///_______ +____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ +______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ What is your name? -Hello James Gosling diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 892cb6cae..6c3564410 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,9 +1,11 @@ Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +_______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ +______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ +_____/\\\/__\///\\\____________________/\\\\\\\\___________________\/\\\/\\\__\/\\\___/\\\__________________________________/\\\\\\\\\_______ +_____/\\\______\//\\\___/\\/\\\\\\\____/\\\////\\\___/\\\\\\\\\_____\/\\\//\\\_\/\\\__\///_______/\\\\\\\\______/\\\\\\\\___\//\\\\\\\_______ +_____\/\\\_______\/\\\__\/\\\/////\\\__\//\\\\\\\\\__\////////\\\____\/\\\\//\\\\/\\\___/\\\____/\\\//////_____/\\\/////\\\___\//\\\\\_______ +______\//\\\______/\\\___\/\\\___\///____\///////\\\____/\\\\\\\\\\___\/\\\_\//\\\/\\\__\/\\\___/\\\___________/\\\\\\\\\\\_____\//\\\_______ +________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\//\\\\\\__\/\\\__\//\\\_________\//\\///////_______\///_______ +____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ +______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ What is your name? -Hello James Gosling From 40000b9562645cc8ce4164a57ec89c132980705c Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Tue, 10 Mar 2020 20:11:12 +0800 Subject: [PATCH 046/435] Revert "Branch study area" --- src/main/java/deadline/DeadlineList.java | 57 +++--- src/main/java/resourceloader/EventLoader.java | 1 + src/main/java/seedu/duke/Duke.java | 34 +--- src/main/java/studyarea/StudyAreaList.java | 2 + src/main/java/ui/Ui.java | 179 +++--------------- text-ui-test/ACTUAL.TXT | 16 +- text-ui-test/EXPECTED.TXT | 16 +- 7 files changed, 71 insertions(+), 234 deletions(-) diff --git a/src/main/java/deadline/DeadlineList.java b/src/main/java/deadline/DeadlineList.java index d010273c8..e6c0fd27f 100644 --- a/src/main/java/deadline/DeadlineList.java +++ b/src/main/java/deadline/DeadlineList.java @@ -11,6 +11,7 @@ */ public class DeadlineList { + Ui ui = new Ui(); /** Stores the deadline information. */ public ArrayList deadlines; @@ -30,26 +31,24 @@ public DeadlineList(ArrayList deadlines) { * Adds a new deadline to the list. * * @param newDeadline Deadline represents the new deadline tot be added. - * @param ui This allows for the deadline class to interact with Users. */ - public void addDeadline(Deadline newDeadline, Ui ui) { + public void addDeadline(Deadline newDeadline) { ui.printLine(); deadlines.add(newDeadline); - ui.printMessage("A new deadline with the following information has been added."); - ui.printMessage(newDeadline.getDeadlineInformation()); + ui.printWithIndentation("A new deadline with the following information has been added."); + ui.printWithIndentation(newDeadline.getDeadlineInformation()); ui.printLine(); } /** * Displays the current list of deadlines. - * @param ui This allows for the deadline class to interact with Users. */ - public void listDeadlines(Ui ui) { + public void listDeadlines() { ui.printLine(); System.out.println("Here is the list of deadlines added so far:"); int deadlineNumber = 1; for (Deadline deadline: deadlines) { - ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } ui.printLine(); @@ -59,17 +58,16 @@ public void listDeadlines(Ui ui) { * Deletes the deadline at the specified index. * * @param index The index (1-based) of the deadline to be deleted. - * @param ui This allows for the deadline class to interact with Users. */ - public void deleteDeadline(int index, Ui ui) { + public void deleteDeadline(int index) { try { deadlines.remove(index - 1); ui.printLine(); - ui.printMessage("The deadline at the mentioned index has been deleted"); + ui.printWithIndentation("The deadline at the mentioned index has been deleted"); ui.printLine(); } catch (IndexOutOfBoundsException e) { ui.printLine(); - ui.printMessage("Enter a valid index"); + ui.printWithIndentation("Enter a valid index"); ui.printLine(); } @@ -77,50 +75,47 @@ public void deleteDeadline(int index, Ui ui) { /** * Clears all the deadlines currently stored. - * @param ui This allows for the deadline class to interact with Users. */ - public void clearDeadlines(Ui ui) { + public void clearDeadlines() { deadlines.clear(); ui.printLine(); - ui.printMessage("The list of deadlines is cleared."); + ui.printWithIndentation("The list of deadlines is cleared."); ui.printLine(); } /** * Lists all the tasks sorted by their priority. - * @param ui This allows for the deadline class to interact with Users. */ - public void priorityView(Ui ui) { + public void priorityView() { ArrayList deadlinesSortedByPriority = deadlines; deadlinesSortedByPriority.sort(Comparator.comparingInt(Deadline::getPriority)); Collections.reverse(deadlinesSortedByPriority); ui.printLine(); int deadlineNumber = 1; for (Deadline deadline:deadlinesSortedByPriority) { - ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } if (deadlineNumber == 1) { - ui.printMessage("The list is empty."); + ui.printWithIndentation("The list is empty."); } ui.printLine(); } /** * Lists all the tasks sorted by date along with the days remaining. - * @param ui This allows for the deadline class to interact with Users. */ - public void countdownView(Ui ui) { + public void countdownView() { ArrayList deadlinesSortedByDate = deadlines; deadlinesSortedByDate.sort(Comparator.comparing(Deadline::getDate)); ui.printLine(); int deadlineNumber = 1; for (Deadline deadline:deadlinesSortedByDate) { - ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } if (deadlineNumber == 1) { - ui.printMessage("The list is empty."); + ui.printWithIndentation("The list is empty."); } ui.printLine(); } @@ -129,15 +124,14 @@ public void countdownView(Ui ui) { * Displays the list of deadlines containing the keyword. * * @param keyword The keyword to be searched for. - * @param ui This allows for the deadline class to interact with Users. */ - public void searchDeadlines(String keyword, Ui ui) { + public void searchDeadlines(String keyword) { ui.printLine(); int deadlineNumber = 1; for (Deadline deadline:deadlines) { try { if (deadline.hasKeyword(keyword)) { - ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } } catch (Exception e) { @@ -145,20 +139,19 @@ public void searchDeadlines(String keyword, Ui ui) { } } if (deadlineNumber == 1) { - ui.printMessage("The list is empty."); + ui.printWithIndentation("The list is empty."); } ui.printLine(); } /** * Adds a new deadline to the list by parsing information from the user given string - * and calling {@link #addDeadline(Deadline, Ui)} if the information is given in the correct format + * and calling {@link #addDeadline(Deadline)} if the information is given in the correct format * to add the deadline. * * @param deadlineDetails Contains all the information related to the deadline as provided by the user. - * @param ui This allows for the deadline class to interact with Users. */ - public void add(String deadlineDetails, Ui ui) { + public void add(String deadlineDetails) { try { String[] details = deadlineDetails.split(" ",2)[1].split("/"); String description = details[0]; @@ -166,14 +159,14 @@ public void add(String deadlineDetails, Ui ui) { String dueTime = details[2].substring(2); String priority = details[3].substring(2); Deadline newDeadline = new Deadline(description,date,dueTime, priority); - addDeadline(newDeadline, ui); + addDeadline(newDeadline); } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { ui.printLine(); - ui.printMessage("Wrong format to add deadlines"); + ui.printWithIndentation("Wrong format to add deadlines"); ui.printLine(); } catch (Exception e) { ui.printLine(); - ui.printMessage(e.getMessage()); + ui.printWithIndentation(e.getMessage()); ui.printLine(); } } diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java index 6ab446bed..9326382c0 100644 --- a/src/main/java/resourceloader/EventLoader.java +++ b/src/main/java/resourceloader/EventLoader.java @@ -2,6 +2,7 @@ import event.Event; import ui.Ui; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 280fda895..1fa01f6b9 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,44 +1,14 @@ package seedu.duke; -<<<<<<< HEAD import driver.Driver; import ui.Ui; import java.util.Scanner; -======= -import command.EventCommand; -import command.StudyAreaCommand; -import event.EventList; -import resourceloader.EventLoader; -import resourceloader.StudyAreaLoader; -import studyarea.IllegalStudyAreaException; -import studyarea.StudyAreaList; -import ui.Ui; -import java.io.FileNotFoundException; - -/** - * This is Duke class, which forms the main class of the program. - */ ->>>>>>> cb1907aabe01760a87165c0602e65410ba6ae247 public class Duke { - /** - * This is the constructor to create a new Duke program every time user runs the main loop. - */ - public Duke() { - try { - eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); - eventList = new EventList(eventLoader.loadFile()); - studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); - studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); - } catch (FileNotFoundException | IllegalStudyAreaException e) { - Ui ui = new Ui(); - ui.printMessage(e.getMessage()); - ui.close(); - } - } + private static Ui ui = new Ui(); /** * Main entry-point for the java.duke.Duke application. @@ -64,4 +34,4 @@ public static void main(String[] args) throws Exception { Driver driver = new Driver(mode.nextInt()); } } -} \ No newline at end of file +} diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index c63852a4d..2f36b914c 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -1,6 +1,8 @@ package studyarea; import ui.Ui; + +import java.io.FileNotFoundException; import java.util.ArrayList; /** diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 4eb94ade6..89e7aee57 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -1,10 +1,5 @@ package ui; -<<<<<<< HEAD -======= - -import studyarea.StudyArea; ->>>>>>> cb1907aabe01760a87165c0602e65410ba6ae247 import java.io.File; import java.util.StringTokenizer; @@ -69,96 +64,8 @@ public static void printWithIndentation(String line) { public static final String END_MESSAGE = "Thank you for using our study area search service!"; /** - * This is the constructor used to create the Ui class in Duke.run(). - */ - public Ui() { - this(System.in, System.out); - } - - /** - * This constructor assigns IO stream to the attributes of Ui. - * - * @param in This is the Input Stream for Ui. - * @param out This is the Output Stream for Ui. - */ - public Ui(InputStream in, PrintStream out) { - this.in = new Scanner(in); - this.out = out; - } - - /** - * Returns the mode (event features or StudyArea features or exit) based on User input. - * - * @return an integer which is assigned to each mode. - */ - public int getMode() { - String userIn = this.in.nextLine().toLowerCase(); - switch (userIn) { - case EVENT_COMMAND : - return 1; - case STUDY_COMMAND : - return 2; - case BYE_COMMAND : - return -1; - default : - return 0; - } - } - - /** - * This method allows for other class to get User input. - * - * @return String input from User. - */ - public String getUserIn() { - return this.in.nextLine(); - } - - /** - * This method closes the Input Stream after usage is completed. - */ - public void close() { - this.in.close(); - } - - /** - * This method allows other classes to print messages to interact with User. - * - * @param message This is the message that is intended to be printed to Users. - */ - public void printMessage(String message) { - if (message.equals(GOODBYE_MESSAGE + DAB)) { - this.out.println(formatMessage(GOODBYE_MESSAGE, MAX_LINE_LENGTH)); - this.out.println(DAB); - } else { - this.out.println(formatMessage(message, MAX_LINE_LENGTH)); - } - } - - /** - * This method allows for StudyAreaCommand to print StudyArea based on its actual format, - * so that formatMessage method does not interfere with the initial format. - * - * @param studyArea This is the StudyArea to be printed. - */ - public void printStudyArea(StudyArea studyArea) { - this.out.println(studyArea.toString()); - } - - /** - * Prints a line made up of '_'. - */ - public void printLine() { - System.out.println(LINE); - } - - /** - * This is a modification of a code from Stack Overflow to format strings into a standard length. Minor edition is - * made to ensure suitability with the program. - * This method ensures that the message printed is within the standard
- * length. - * @param message is the String that we intend to format to a standard length
- * per line.
+ * This method ensures that the message printed is within the standard length. + * @param message is the String that we intend to format to a standard length per line. * @param maxLength This is the standard length intended to be formatted. * @return String of standard length per line */ @@ -178,74 +85,42 @@ public static String formatMessage(String message, int maxLength) { } return TAB + standardLengthMessage.toString().stripTrailing(); } -<<<<<<< HEAD -======= - //@@author ->>>>>>> cb1907aabe01760a87165c0602e65410ba6ae247 /** * Display the list of supported commands. */ public void printHelp() { - this.out.println("OrgaNice! Supports the following commands"); - this.out.println("Please enter the keywords followed by the information shown in the brackets"); - this.out.println("add /d /s /e /p "); - this.out.println("------------------------------------------- Create a new event"); - this.out.println("view -------------------------------------- View existing events"); - this.out.println("priority_view ----------------------------- View existing events based on priority"); - this.out.println("countdown --------------------------------- View existing events based on days left"); - this.out.println("clear ------------------------------------- Delete all events"); - this.out.println("search ----------- View existing events that contains " + printLine(); + System.out.println("OrgaNice! Supports the following commands"); + System.out.println("Please enter the keywords followed by the information shown in the brackets"); + System.out.println("add /d /s /e /p "); + System.out.println("------------------------------------------- Create a new event"); + System.out.println("view -------------------------------------- View existing events"); + System.out.println("priority_view ----------------------------- View existing events based on priority"); + System.out.println("countdown --------------------------------- View existing events based on days left"); + System.out.println("clear ------------------------------------- Delete all events"); + System.out.println("search ----------- View existing events that contains " + "the keyword"); - this.out.println("delete ------------ Delete the event"); - this.out.println("bye --------------------------------------- Terminate program"); - this.out.println("Notes:"); - this.out.println("*All dates should follow YYYY-MM-DD format"); - this.out.println("*All timing should follow 24 hour clock"); - this.out.println("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " + System.out.println("delete ------------ Delete the event"); + System.out.println("bye --------------------------------------- Terminate program"); + System.out.println("Notes:"); + System.out.println("*All dates should follow YYYY-MM-DD format"); + System.out.println("*All timing should follow 24 hour clock"); + System.out.println("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " + "least urgent"); + printLine(); } /** - * Prints the welcome message and starts interaction with user. + * Display welcome message. */ public void printWelcomeMessage() { - - //@@author NizarMohd-reused - //Reused logo from http://patorjk.com/software/taag/#p=display&f=Graffiti&t=TypeSomething with minor - // modifications. The website above allows for generation of fonts in ascii format. Therefore, logo is - // generated from the service provided by the website. - String logo = "_______/\\\\\\\\\\_____________________________________________________/\\\\\\\\\\_____/\\\\\\__" - + "__________________________________________/\\\\\\____________\n" - + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" - + "_________________________________________/\\\\\\\\\\\\\\_________\n" - + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" - + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______\n" - + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" - + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" - + "_\\//\\\\\\\\\\\\\\_______\n" - + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" - + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" - + "___\n" - + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" - + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" - + "_____\n" - + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" - + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______\n" - + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" - + "_\\//\\\\\\\\\\\\\\\\/\\\\" - + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" - + "_/\\\\\\_____\n" - + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" - + "_\\///______\\////////_____\\//////////______\\///_____"; - //@@author - this.out.println("Hello from\n" + logo); - this.out.println("What is your name?"); - printLine(); - String name = this.in.nextLine(); - printLine(); - this.out.println(TAB + "Hello " + name + "!"); - this.out.println(formatMessage(START_MESSAGE, MAX_LINE_LENGTH)); - printLine(); + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); + System.out.println("What is your name?"); } } diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 6c3564410..892cb6cae 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -1,11 +1,9 @@ Hello from -_______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ -______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ -_____/\\\/__\///\\\____________________/\\\\\\\\___________________\/\\\/\\\__\/\\\___/\\\__________________________________/\\\\\\\\\_______ -_____/\\\______\//\\\___/\\/\\\\\\\____/\\\////\\\___/\\\\\\\\\_____\/\\\//\\\_\/\\\__\///_______/\\\\\\\\______/\\\\\\\\___\//\\\\\\\_______ -_____\/\\\_______\/\\\__\/\\\/////\\\__\//\\\\\\\\\__\////////\\\____\/\\\\//\\\\/\\\___/\\\____/\\\//////_____/\\\/////\\\___\//\\\\\_______ -______\//\\\______/\\\___\/\\\___\///____\///////\\\____/\\\\\\\\\\___\/\\\_\//\\\/\\\__\/\\\___/\\\___________/\\\\\\\\\\\_____\//\\\_______ -________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\//\\\\\\__\/\\\__\//\\\_________\//\\///////_______\///_______ -____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ -______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + What is your name? +Hello James Gosling diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 6c3564410..892cb6cae 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,11 +1,9 @@ Hello from -_______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ -______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ -_____/\\\/__\///\\\____________________/\\\\\\\\___________________\/\\\/\\\__\/\\\___/\\\__________________________________/\\\\\\\\\_______ -_____/\\\______\//\\\___/\\/\\\\\\\____/\\\////\\\___/\\\\\\\\\_____\/\\\//\\\_\/\\\__\///_______/\\\\\\\\______/\\\\\\\\___\//\\\\\\\_______ -_____\/\\\_______\/\\\__\/\\\/////\\\__\//\\\\\\\\\__\////////\\\____\/\\\\//\\\\/\\\___/\\\____/\\\//////_____/\\\/////\\\___\//\\\\\_______ -______\//\\\______/\\\___\/\\\___\///____\///////\\\____/\\\\\\\\\\___\/\\\_\//\\\/\\\__\/\\\___/\\\___________/\\\\\\\\\\\_____\//\\\_______ -________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\//\\\\\\__\/\\\__\//\\\_________\//\\///////_______\///_______ -____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ -______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + What is your name? +Hello James Gosling From 3136f48765a2b79c0080ea1ad82fe3f8dd4df82c Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Tue, 10 Mar 2020 20:47:39 +0800 Subject: [PATCH 047/435] Pull from Upstream and Add changes --- src/main/java/driver/Driver.java | 43 -------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 src/main/java/driver/Driver.java diff --git a/src/main/java/driver/Driver.java b/src/main/java/driver/Driver.java deleted file mode 100644 index a09b7c01a..000000000 --- a/src/main/java/driver/Driver.java +++ /dev/null @@ -1,43 +0,0 @@ -package driver; - -import command.EventCommand; -import event.EventList; -import java.io.FileNotFoundException; - -import resourceloader.EventLoader; -import resourceloader.StudyAreaLoader; -import studyarea.IllegalStudyAreaException; -import command.StudyAreaCommand; -import studyarea.StudyAreaList; -import ui.Ui; - -public class Driver { - public static EventLoader eventLoader; - public static StudyAreaLoader studyAreaLoader; - - /** - * Constructor for Driver Class. - * This class setups the loading of events and study areas into - * the program and runs either study area or organiser functionality. - * - * @param mode 1 for organiser, 0 for study area - * @throws FileNotFoundException if file is not found. - * @throws IllegalStudyAreaException custom exception for study area - */ - public Driver(int mode) throws FileNotFoundException, IllegalStudyAreaException { - eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); - EventList eventList = new EventList(eventLoader.loadFile()); - - studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); - StudyAreaList studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); - - if (mode == 1) { - EventCommand eventCommand = new EventCommand(); - eventCommand.runCommands(eventList); - eventLoader.saveEvents(eventList.events); - } else { - StudyAreaCommand studyAreaCommand = new StudyAreaCommand(); - studyAreaCommand.runCommands(studyAreaList); - } - } -} From 5a1296500b6f0d2018015daab6ff4434db91b7f2 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Tue, 10 Mar 2020 20:47:58 +0800 Subject: [PATCH 048/435] pull from upstream and add changes --- src/main/java/command/EventCommand.java | 43 +-- src/main/java/command/StudyAreaCommand.java | 84 +++--- src/main/java/deadline/Deadline.java | 2 +- src/main/java/deadline/DeadlineList.java | 59 +++-- src/main/java/event/Event.java | 3 +- src/main/java/event/EventList.java | 85 +++--- src/main/java/resourceloader/EventLoader.java | 5 +- .../java/resourceloader/StudyAreaLoader.java | 1 + src/main/java/seedu/duke/Duke.java | 90 +++++-- .../studyarea/IllegalStudyAreaException.java | 4 +- src/main/java/studyarea/StudyArea.java | 56 +++- src/main/java/studyarea/StudyAreaList.java | 5 +- src/main/java/task/TaskList.java | 2 +- src/main/java/ui/Ui.java | 248 ++++++++++++++---- 14 files changed, 464 insertions(+), 223 deletions(-) diff --git a/src/main/java/command/EventCommand.java b/src/main/java/command/EventCommand.java index 9e9c98ef9..199ac186a 100644 --- a/src/main/java/command/EventCommand.java +++ b/src/main/java/command/EventCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import resourceloader.EventLoader; import ui.Ui; import java.util.Scanner; @@ -10,54 +11,56 @@ public class EventCommand { /** * Commands for Events. * - * @param eventList evenList + * @param eventList this is the evenList. + * @param ui allows for interaction with the User. + * @param eventLoader allows for saving of data after every execution of commands. */ - public static void runCommands(EventList eventList) { + public static void runCommands(EventList eventList, Ui ui, EventLoader eventLoader) { Scanner in = new Scanner(System.in); String command; + ui.printLine(); command = in.nextLine(); while (!command.equals(Ui.BYE_COMMAND)) { + ui.printLine(); try { String commandType = command.split(" ")[0]; switch (commandType) { case Ui.ADD_COMMAND: - eventList.add(command); + eventList.add(command, ui); break; case Ui.VIEW_COMMAND: - eventList.listEvents(); + eventList.listEvents(ui); break; case Ui.PRIORITY_VIEW_COMMAND: - eventList.priorityView(); + eventList.priorityView(ui); break; case Ui.COUNTDOWN_VIEW_COMMAND: - eventList.countdownView(); + eventList.countdownView(ui); break; case Ui.CLEAR_COMMAND: - eventList.clearEvents(); + eventList.clearEvents(ui); break; case Ui.SEARCH_COMMAND: - eventList.searchEvents(command.split(" ", 2)[1]); + eventList.searchEvents(command.split(" ", 2)[1], ui); break; case Ui.DELETE_COMMAND: - eventList.deleteEvent(Integer.parseInt(command.split(" ", 2)[1])); + eventList.deleteEvent(Integer.parseInt(command.split(" ", 2)[1]), ui); break; default: - Ui.printLine(); - System.out.println(Ui.INVALID_COMMAND_MESSAGE); - Ui.printLine(); + ui.printMessage(Ui.INVALID_COMMAND_MESSAGE); break; } } catch (NumberFormatException e) { - Ui.printLine(); - System.out.println(Ui.INVALID_INDEX_MESSAGE); - Ui.printLine(); + ui.printMessage(Ui.INVALID_INDEX_MESSAGE); } catch (IndexOutOfBoundsException e) { - Ui.printLine(); - System.out.println(Ui.INVALID_COMMAND_MESSAGE); - Ui.printLine(); + ui.printMessage(Ui.INVALID_COMMAND_MESSAGE); } + ui.printLine(); + eventLoader.saveEvents(eventList.events); command = in.nextLine(); } - System.out.println(Ui.BYE_MESSAGE); + ui.printLine(); + ui.printMessage(Ui.BYE_MESSAGE); + ui.printLine(); } -} +} \ No newline at end of file diff --git a/src/main/java/command/StudyAreaCommand.java b/src/main/java/command/StudyAreaCommand.java index be6c63ff0..0fbc33538 100644 --- a/src/main/java/command/StudyAreaCommand.java +++ b/src/main/java/command/StudyAreaCommand.java @@ -4,28 +4,26 @@ import studyarea.StudyArea; import studyarea.StudyAreaList; import ui.Ui; - -import java.io.FileNotFoundException; import java.util.ArrayList; -import java.util.Scanner; /** - * This is the Study Area Command class. It executes the Study Area Search function and interact with Users accordingly. + * This is the StudyAreaCommand class. It executes the StudyArea Search function and interact with Users accordingly. */ public class StudyAreaCommand { /** - * List out all the study areas that match with User's preference. + * List out all the StudyAreas that match with User's preference. + * @param ui This allows for StudyAreaCommand to interact with Users. * @param availStudyAreas this is the list of all study areas in location.txt. */ - public static void printList(ArrayList availStudyAreas) { + public static void printList(ArrayList availStudyAreas, Ui ui) { if (availStudyAreas.isEmpty()) { - System.out.println(Ui.formatMessage(Ui.EMPTY_LIST, Ui.MAX_LINE_LENGTH)); + ui.printMessage(Ui.EMPTY_LIST); } else { - System.out.println(Ui.formatMessage(Ui.AVAILABLE_STUDY_AREAS, Ui.MAX_LINE_LENGTH)); + ui.printMessage(Ui.AVAILABLE_STUDY_AREAS); for (StudyArea studyArea : availStudyAreas) { - System.out.println(studyArea.toString()); + ui.printStudyArea(studyArea); } } } @@ -34,47 +32,59 @@ public static void printList(ArrayList availStudyAreas) { /** * Filters command based on User Input. * @param command This is the command entered by User. - * @param studyAreaList This is the list of all Study Areas in location.txt. + * @param studyAreaList This is the list of all StudyAreas in location.txt. + * @param ui This allows for StudyAreaCommand to interact with Users. * @return boolean status. False if User enters "end" , else will always return true; + * @throws IllegalStudyAreaException if User enters invalid commands. */ - public static boolean filterCommand(String command, StudyAreaList studyAreaList) { - switch (command) { - case Ui.END_COMMAND : - System.out.println(Ui.formatMessage(Ui.END_MESSAGE, Ui.MAX_LINE_LENGTH)); - return false; - case Ui.HELP_COMMAND : - System.out.println(Ui.FLAGS); - break; - default: - try { - ArrayList availStudyAreas = studyAreaList.searchList(command); - printList(availStudyAreas); - System.out.println(Ui.formatMessage(Ui.PROMPT_USER, Ui.MAX_LINE_LENGTH)); - } catch (IllegalStudyAreaException e) { - System.out.println(Ui.formatMessage(e.getMessage(), Ui.MAX_LINE_LENGTH)); + public static boolean filterCommand(String command, StudyAreaList studyAreaList, Ui ui) throws + IllegalStudyAreaException { + + command = command.trim(); + if (command.isBlank()) { + throw new IllegalStudyAreaException(Ui.EMPTY_LOCATION); + } else { + switch (command) { + case Ui.BYE_COMMAND: + ui.printMessage(Ui.END_MESSAGE); + return false; + case Ui.HELP_COMMAND: + ui.printMessage(Ui.FLAGS); + break; + default: + try { + ArrayList availStudyAreas = studyAreaList.searchList(command); + printList(availStudyAreas, ui); + ui.printMessage(Ui.PROMPT_USER); + } catch (IllegalStudyAreaException e) { + ui.printMessage(e.getMessage()); + } + break; } } return true; } /** - * Executes the Study Area search feature. + * Executes the StudyArea search feature. + * @param ui This allows for StudyAreaCommand to interact with Users. * @param studyAreaList studyAreaList object that holds information on studyAreas available. */ - public static void runCommands(StudyAreaList studyAreaList) { - - Ui ui = new Ui(); + public static void runCommands(StudyAreaList studyAreaList, Ui ui) { ui.printLine(); - System.out.println(Ui.formatMessage(Ui.START_STUDY_AREA_SEARCH, Ui.MAX_LINE_LENGTH)); - Scanner in = new Scanner(System.in); + ui.printMessage(Ui.START_STUDY_AREA_SEARCH); boolean status = true; while (status) { - Ui.printLine(); - String command = in.nextLine(); - Ui.printLine(); - status = filterCommand(command, studyAreaList); + ui.printLine(); + String command = ui.getUserIn(); + ui.printLine(); + try { + status = filterCommand(command, studyAreaList, ui); + } catch (IllegalStudyAreaException e) { + ui.printMessage(e.getMessage()); + } } - Ui.printLine(); + ui.printLine(); } -} +} \ No newline at end of file diff --git a/src/main/java/deadline/Deadline.java b/src/main/java/deadline/Deadline.java index 9ea998dd5..03f7f9289 100644 --- a/src/main/java/deadline/Deadline.java +++ b/src/main/java/deadline/Deadline.java @@ -114,4 +114,4 @@ public String getFormattedDetails() { String formattedDeadlineDetails = description + "#" + date + "#" + dueTime + "#" + priority; return formattedDeadlineDetails; } -} +} \ No newline at end of file diff --git a/src/main/java/deadline/DeadlineList.java b/src/main/java/deadline/DeadlineList.java index e6c0fd27f..78a987d8c 100644 --- a/src/main/java/deadline/DeadlineList.java +++ b/src/main/java/deadline/DeadlineList.java @@ -11,7 +11,6 @@ */ public class DeadlineList { - Ui ui = new Ui(); /** Stores the deadline information. */ public ArrayList deadlines; @@ -31,24 +30,26 @@ public DeadlineList(ArrayList deadlines) { * Adds a new deadline to the list. * * @param newDeadline Deadline represents the new deadline tot be added. + * @param ui This allows for the deadline class to interact with Users. */ - public void addDeadline(Deadline newDeadline) { + public void addDeadline(Deadline newDeadline, Ui ui) { ui.printLine(); deadlines.add(newDeadline); - ui.printWithIndentation("A new deadline with the following information has been added."); - ui.printWithIndentation(newDeadline.getDeadlineInformation()); + ui.printMessage("A new deadline with the following information has been added."); + ui.printMessage(newDeadline.getDeadlineInformation()); ui.printLine(); } /** * Displays the current list of deadlines. + * @param ui This allows for the deadline class to interact with Users. */ - public void listDeadlines() { + public void listDeadlines(Ui ui) { ui.printLine(); System.out.println("Here is the list of deadlines added so far:"); int deadlineNumber = 1; for (Deadline deadline: deadlines) { - ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } ui.printLine(); @@ -58,16 +59,17 @@ public void listDeadlines() { * Deletes the deadline at the specified index. * * @param index The index (1-based) of the deadline to be deleted. + * @param ui This allows for the deadline class to interact with Users. */ - public void deleteDeadline(int index) { + public void deleteDeadline(int index, Ui ui) { try { deadlines.remove(index - 1); ui.printLine(); - ui.printWithIndentation("The deadline at the mentioned index has been deleted"); + ui.printMessage("The deadline at the mentioned index has been deleted"); ui.printLine(); } catch (IndexOutOfBoundsException e) { ui.printLine(); - ui.printWithIndentation("Enter a valid index"); + ui.printMessage("Enter a valid index"); ui.printLine(); } @@ -75,47 +77,50 @@ public void deleteDeadline(int index) { /** * Clears all the deadlines currently stored. + * @param ui This allows for the deadline class to interact with Users. */ - public void clearDeadlines() { + public void clearDeadlines(Ui ui) { deadlines.clear(); ui.printLine(); - ui.printWithIndentation("The list of deadlines is cleared."); + ui.printMessage("The list of deadlines is cleared."); ui.printLine(); } /** * Lists all the tasks sorted by their priority. + * @param ui This allows for the deadline class to interact with Users. */ - public void priorityView() { + public void priorityView(Ui ui) { ArrayList deadlinesSortedByPriority = deadlines; deadlinesSortedByPriority.sort(Comparator.comparingInt(Deadline::getPriority)); Collections.reverse(deadlinesSortedByPriority); ui.printLine(); int deadlineNumber = 1; for (Deadline deadline:deadlinesSortedByPriority) { - ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } if (deadlineNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } ui.printLine(); } /** * Lists all the tasks sorted by date along with the days remaining. + * @param ui This allows for the deadline class to interact with Users. */ - public void countdownView() { + public void countdownView(Ui ui) { ArrayList deadlinesSortedByDate = deadlines; deadlinesSortedByDate.sort(Comparator.comparing(Deadline::getDate)); ui.printLine(); int deadlineNumber = 1; for (Deadline deadline:deadlinesSortedByDate) { - ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } if (deadlineNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } ui.printLine(); } @@ -124,14 +129,15 @@ public void countdownView() { * Displays the list of deadlines containing the keyword. * * @param keyword The keyword to be searched for. + * @param ui This allows for the deadline class to interact with Users. */ - public void searchDeadlines(String keyword) { + public void searchDeadlines(String keyword, Ui ui) { ui.printLine(); int deadlineNumber = 1; for (Deadline deadline:deadlines) { try { if (deadline.hasKeyword(keyword)) { - ui.printWithIndentation(deadlineNumber + ") " + deadline.getDeadlineInformation()); + ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); deadlineNumber++; } } catch (Exception e) { @@ -139,19 +145,20 @@ public void searchDeadlines(String keyword) { } } if (deadlineNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } ui.printLine(); } /** * Adds a new deadline to the list by parsing information from the user given string - * and calling {@link #addDeadline(Deadline)} if the information is given in the correct format + * and calling {@link #addDeadline(Deadline, Ui)} if the information is given in the correct format * to add the deadline. * * @param deadlineDetails Contains all the information related to the deadline as provided by the user. + * @param ui This allows for the deadline class to interact with Users. */ - public void add(String deadlineDetails) { + public void add(String deadlineDetails, Ui ui) { try { String[] details = deadlineDetails.split(" ",2)[1].split("/"); String description = details[0]; @@ -159,15 +166,15 @@ public void add(String deadlineDetails) { String dueTime = details[2].substring(2); String priority = details[3].substring(2); Deadline newDeadline = new Deadline(description,date,dueTime, priority); - addDeadline(newDeadline); + addDeadline(newDeadline, ui); } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { ui.printLine(); - ui.printWithIndentation("Wrong format to add deadlines"); + ui.printMessage("Wrong format to add deadlines"); ui.printLine(); } catch (Exception e) { ui.printLine(); - ui.printWithIndentation(e.getMessage()); + ui.printMessage(e.getMessage()); ui.printLine(); } } -} +} \ No newline at end of file diff --git a/src/main/java/event/Event.java b/src/main/java/event/Event.java index 487c48845..1ea721c29 100644 --- a/src/main/java/event/Event.java +++ b/src/main/java/event/Event.java @@ -112,6 +112,7 @@ public LocalDate getDate() { * * @param keyword The keyword to be matched with the description. * @return containsKeyword Indicates the presence/absence of keyword in the event's description. + * @throws Exception to be edited */ public boolean hasKeyword(String keyword) throws Exception { if (keyword.equals("")) { @@ -130,4 +131,4 @@ public String getFormattedDetails() { String formattedEventDetails = description + "#" + date + "#" + startTime + "#" + endTime + "#" + priority; return formattedEventDetails; } -} +} \ No newline at end of file diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index 947d606da..de936b110 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -11,7 +11,6 @@ */ public class EventList { - Ui ui = new Ui(); /** Stores the event information. */ public ArrayList events; @@ -30,108 +29,104 @@ public EventList(ArrayList events) { /** * Adds a new event to the list. * + * @param ui This allows Event List class to interact with User. * @param newEvent Event represents the new event tot be added. */ - public void addEvent(Event newEvent) { - ui.printLine(); + public void addEvent(Event newEvent, Ui ui) { events.add(newEvent); - ui.printWithIndentation("A new event with the following information has been added."); - ui.printWithIndentation(newEvent.getEventInformation()); - ui.printLine(); + ui.printMessage("A new event with the following information has been added."); + ui.printMessage(newEvent.getEventInformation()); } /** * Displays the current list of events. + * + * @param ui This allows Event List class to interact with User. */ - public void listEvents() { - ui.printLine(); - System.out.println("Here is the list of events added so far:"); + public void listEvents(Ui ui) { + ui.printMessage("Here is the list of events added so far:"); int eventNumber = 1; for (Event event: events) { - ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); + ui.printMessage(eventNumber + ") " + event.getEventInformation()); eventNumber++; } - ui.printLine(); } /** * Deletes the event at the specified index. * + * @param ui This allows Event List class to interact with User. * @param index The index (1-based) of the event to be deleted. */ - public void deleteEvent(int index) { + public void deleteEvent(int index, Ui ui) { try { events.remove(index - 1); - ui.printLine(); - ui.printWithIndentation("The event at the mentioned index has been deleted"); - ui.printLine(); + ui.printMessage("The event at the mentioned index has been deleted"); } catch (IndexOutOfBoundsException e) { - ui.printLine(); - ui.printWithIndentation("Enter a valid index"); - ui.printLine(); + ui.printMessage("Enter a valid index"); } } /** * Clears all the events currently stored. + * + * @param ui This allows Event List class to interact with User. */ - public void clearEvents() { + public void clearEvents(Ui ui) { events.clear(); - ui.printLine(); - ui.printWithIndentation("The list of events is cleared."); - ui.printLine(); + ui.printMessage("The list of events is cleared."); } /** * Lists all the tasks sorted by their priority. + * + * @param ui This allows Event List class to interact with User. */ - public void priorityView() { + public void priorityView(Ui ui) { ArrayList eventsSortedByPriority = events; eventsSortedByPriority.sort(Comparator.comparingInt(Event::getPriority)); Collections.reverse(eventsSortedByPriority); - ui.printLine(); int eventNumber = 1; for (Event event:eventsSortedByPriority) { - ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); + ui.printMessage(eventNumber + ") " + event.getEventInformation()); eventNumber++; } if (eventNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } - ui.printLine(); } /** * Lists all the tasks sorted by date along with the days remaining. + * + * @param ui This allows Event List class to interact with User. */ - public void countdownView() { + public void countdownView(Ui ui) { ArrayList eventsSortedByDate = events; eventsSortedByDate.sort(Comparator.comparing(Event::getDate)); - ui.printLine(); int eventNumber = 1; for (Event event:eventsSortedByDate) { - ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); + ui.printMessage(eventNumber + ") " + event.getEventInformation()); eventNumber++; } if (eventNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } - ui.printLine(); } /** * Displays the list of events containing the keyword. * + * @param ui This allows Event List class to interact with User. * @param keyword The keyword to be searched for. */ - public void searchEvents(String keyword) { - ui.printLine(); + public void searchEvents(String keyword, Ui ui) { int eventNumber = 1; for (Event event:events) { try { if (event.hasKeyword(keyword)) { - ui.printWithIndentation(eventNumber + ") " + event.getEventInformation()); + ui.printMessage(eventNumber + ") " + event.getEventInformation()); eventNumber++; } } catch (Exception e) { @@ -139,19 +134,19 @@ public void searchEvents(String keyword) { } } if (eventNumber == 1) { - ui.printWithIndentation("The list is empty."); + ui.printMessage("The list is empty."); } - ui.printLine(); } /** * Adds a new event to the list by parsing information from the user given string - * and calling {@link #addEvent(Event)} if the information is given in the correct format + * and calling {@link #addEvent(Event, Ui)} if the information is given in the correct format * to add the event. * + * @param ui This allows Event List class to interact with User. * @param eventDetails Contains all the information related to the event as provided by the user. */ - public void add(String eventDetails) { + public void add(String eventDetails, Ui ui) { try { String[] details = eventDetails.split(" ",2)[1].split("/"); String description = details[0]; @@ -160,15 +155,11 @@ public void add(String eventDetails) { String endTime = details[3].substring(2); String priority = details[4].substring(2); Event newEvent = new Event(description,date,startTime,endTime,priority); - addEvent(newEvent); + addEvent(newEvent, ui); } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { - ui.printLine(); - ui.printWithIndentation("Wrong format to add events"); - ui.printLine(); + ui.printMessage("Wrong format to add events"); } catch (Exception e) { - ui.printLine(); - ui.printWithIndentation(e.getMessage()); - ui.printLine(); + ui.printMessage(e.getMessage()); } } -} +} \ No newline at end of file diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java index 9326382c0..bd71727ca 100644 --- a/src/main/java/resourceloader/EventLoader.java +++ b/src/main/java/resourceloader/EventLoader.java @@ -2,7 +2,6 @@ import event.Event; import ui.Ui; - import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; @@ -58,7 +57,7 @@ public ArrayList loadFile() { createNewDataFile(); } catch (Exception e) { ui.printLine(); - ui.printWithIndentation(e.getMessage()); + ui.printMessage(e.getMessage()); ui.printLine(); } return events; @@ -112,4 +111,4 @@ public void saveEvents(ArrayList events) { } } -} +} \ No newline at end of file diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index 0cee4dcc5..c26dd4f69 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -42,6 +42,7 @@ public void loadFile() throws FileNotFoundException { * * @return buffer ArrayList of Location from study area file * @throws FileNotFoundException if location.txt does not exist. + * @throws IllegalStudyAreaException if data stored is inconsistent */ public ArrayList pushToDatabase() throws FileNotFoundException, IllegalStudyAreaException { diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 1fa01f6b9..3388c1a8f 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,37 +1,77 @@ package seedu.duke; -import driver.Driver; +import command.EventCommand; +import command.StudyAreaCommand; +import event.EventList; +import resourceloader.EventLoader; +import resourceloader.StudyAreaLoader; +import studyarea.IllegalStudyAreaException; +import studyarea.StudyAreaList; import ui.Ui; +import java.io.FileNotFoundException; -import java.util.Scanner; - - +/** + * This is Duke class, which forms the main class of the program. + */ public class Duke { + private static EventLoader eventLoader; + protected static StudyAreaLoader studyAreaLoader; + private static EventList eventList; + private static StudyAreaList studyAreaList; - private static Ui ui = new Ui(); + /** + * This is the constructor to create a new Duke program every time user runs the main loop. + */ + public Duke() { + try { + eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); + eventList = new EventList(eventLoader.loadFile()); + studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); + studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); + } catch (FileNotFoundException | IllegalStudyAreaException e) { + Ui ui = new Ui(); + ui.printMessage(e.getMessage()); + ui.close(); + } + } /** - * Main entry-point for the java.duke.Duke application. - * @param args Commandline argument + * This method runs the program. */ - public static void main(String[] args) throws Exception { + public void run() { + Ui ui = new Ui(); ui.printWelcomeMessage(); - - Scanner in = new Scanner(System.in); - System.out.println("Hello " + in.nextLine()); - - /** - * To run: - * events: enter 1 - * study areas: enter 0 - * To end events loop: enter bye in events prog - * To end study areas loop: enter end in study area loop - * To end overall prog, enter ctrl+c or ctrl+z - * Take note: this is still temporary - */ - while (true) { - Scanner mode = new Scanner(System.in); - Driver driver = new Driver(mode.nextInt()); + boolean status = true; + while (status) { + int mode = ui.getMode(); + switch (mode) { + case -1: + status = false; + break; + case 1: + EventCommand.runCommands(eventList, ui, eventLoader); + eventLoader.saveEvents(eventList.events); + break; + case 2: + StudyAreaCommand.runCommands(studyAreaList, ui); + break; + default: + ui.printLine(); + ui.printMessage(Ui.WRONG_INPUT); + break; + } + ui.printMessage(Ui.INTERMEDIATE_MESSAGE); + ui.printLine(); } + ui.printMessage(Ui.GOODBYE_MESSAGE + Ui.DAB); + ui.close(); + } + + /** + * Main entry-point for the java.duke.Duke application. + * @param args this is an optional argument. + */ + public static void main(String[] args) { + new Duke().run(); } -} +} \ No newline at end of file diff --git a/src/main/java/studyarea/IllegalStudyAreaException.java b/src/main/java/studyarea/IllegalStudyAreaException.java index f7dabc5a2..c86aceee5 100644 --- a/src/main/java/studyarea/IllegalStudyAreaException.java +++ b/src/main/java/studyarea/IllegalStudyAreaException.java @@ -1,7 +1,7 @@ package studyarea; /** - * This is an extension of the Exception class that exist only for Study Area related modules. + * This is an extension of the Exception class that exist only for StudyArea related modules. */ public class IllegalStudyAreaException extends Exception { @@ -11,4 +11,4 @@ public IllegalStudyAreaException(String message) { } -} +} \ No newline at end of file diff --git a/src/main/java/studyarea/StudyArea.java b/src/main/java/studyarea/StudyArea.java index b6eb7895f..803254261 100644 --- a/src/main/java/studyarea/StudyArea.java +++ b/src/main/java/studyarea/StudyArea.java @@ -6,7 +6,7 @@ /** - * This is the Study Area class. All study area is stored as a Study Area object. + * This is the StudyArea class. All study area is stored as a Study Area object. */ public class StudyArea { @@ -18,19 +18,19 @@ public class StudyArea { private int maxPax; /** - * Constructs a Location class for a study area location with its information + * Constructs a StudyArea class for a study area with its information * Precondition: 'All variables have to be filled. * - * @param name name of study location - * @param address address of study location - * @param faculty faculty of study location + * @param name name of StudyArea + * @param address address of StudyArea + * @param faculty faculty of StudyArea * @param hasPort true for availability of ports, else false * @param isIndoor true for indoor, else false - * @param maxPax maximum number of seats for this study area + * @param maxPax maximum number of seats for this StudyArea */ public StudyArea(String name, String address, String faculty, boolean hasPort, - boolean isIndoor, int maxPax) { + boolean isIndoor, int maxPax) { this.name = name; this.address = Ui.formatMessage(address, Ui.ADDRESS_MAX_LENGTH).trim(); this.faculty = faculty; @@ -39,26 +39,56 @@ public StudyArea(String name, String address, String faculty, boolean hasPort, this.maxPax = maxPax; } + /** + * This is the getter for the name attribute. + * + * @return general name of the StudyArea. + */ public String getName() { return this.name; } + /** + * This is the getter for the address attribute. + * + * @return physical address of the StudyArea. + */ public String getAddress() { return this.address; } + /** + * This is the getter for the faculty attribute. + * + * @return the name of the faculty that the StudyArea is located at. + */ public String getFaculty() { return this.faculty; } + /** + * This is the getter for the hasPort attribute. + * + * @return true if the StudyArea has ports and false if otherwise. + */ public boolean hasPort() { return this.hasPort; } + /** + * This is the getter for the isIndoor attribute. + * + * @return true if StudyArea is indoors and false if otherwise. + */ public boolean isIndoor() { return this.isIndoor; } + /** + * This is the getter for the maxPax attribute. + * + * @return maximum number of pax the StudyArea can hold. + */ public Integer getMaxPax() { return this.maxPax; } @@ -69,13 +99,13 @@ public Integer getMaxPax() { */ public String toString() { String text = Ui.TAB + "Name: " + this.name + lineSeparator() + Ui.TAB - + "Address: " + this.address + lineSeparator() + Ui.TAB - + "Faculty: " + this.faculty + lineSeparator() + Ui.TAB - + "Port: " + this.hasPort + lineSeparator() + Ui.TAB - + "Indoor: " + this.isIndoor + lineSeparator() + Ui.TAB - + "Average number of Pax: " + this.maxPax; + + "Address: " + this.address + lineSeparator() + Ui.TAB + + "Faculty: " + this.faculty + lineSeparator() + Ui.TAB + + "Port: " + this.hasPort + lineSeparator() + Ui.TAB + + "Indoor: " + this.isIndoor + lineSeparator() + Ui.TAB + + "Average number of Pax: " + this.maxPax; String line = Ui.TAB + "__________________________________________________________"; return line + lineSeparator() + text + lineSeparator() + line; } -} +} \ No newline at end of file diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 2f36b914c..adab68442 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -1,8 +1,6 @@ package studyarea; import ui.Ui; - -import java.io.FileNotFoundException; import java.util.ArrayList; /** @@ -110,6 +108,7 @@ public static boolean containsKey(String name, String faculty, String key) { * * @param userIn This is the requirement entered by User * @return ArrayList of StudyAreas + * @throws IllegalStudyAreaException if User enters invalid commands. */ public ArrayList searchList(String userIn) throws IllegalStudyAreaException { @@ -147,4 +146,4 @@ public ArrayList searchList(String userIn) throws IllegalStudyAreaExc throw new IllegalStudyAreaException(e.getMessage()); } } -} +} \ No newline at end of file diff --git a/src/main/java/task/TaskList.java b/src/main/java/task/TaskList.java index fdc71eef5..a76413e3b 100644 --- a/src/main/java/task/TaskList.java +++ b/src/main/java/task/TaskList.java @@ -14,4 +14,4 @@ public abstract class TaskList { public abstract void countdownView(); public abstract void searchTasks(); -} +} \ No newline at end of file diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 89e7aee57..5e587cbaf 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -1,15 +1,23 @@ package ui; + +import studyarea.StudyArea; import java.io.File; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.Scanner; import java.util.StringTokenizer; /** * Contains functions used to interact with the user. + * */ public class Ui { + private final Scanner in; + private final PrintStream out; + public static final String FILE_PATH_EVENTS = "library" + File.separator + "eventList.txt"; public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; - public static final String ADD_COMMAND = "add"; public static final String VIEW_COMMAND = "view"; public static final String PRIORITY_VIEW_COMMAND = "priority_view"; @@ -21,18 +29,8 @@ public class Ui { public static final String INVALID_COMMAND_MESSAGE = "Enter a valid command"; public static final String BYE_COMMAND = "bye"; public static final String BYE_MESSAGE = "Bye!!!!!!"; - - /** - * Prints a line made up of '_'. - */ - public static void printLine() { - System.out.println("____________________________________________________________________________________"); - } - - public static void printWithIndentation(String line) { - System.out.println(" " + line); - } - + public static final String LINE = "_______________________________________________________________________________" + + "_____"; public static final int MAX_LINE_LENGTH = 55; public static final int ADDRESS_MAX_LENGTH = 48; public static final String FLAG = "-"; @@ -48,28 +46,161 @@ public static void printWithIndentation(String line) { public static final String WRONG_FLAG_ARGUMENT_POSITION = "Flags are to be used only after location"; public static final String START_STUDY_AREA_SEARCH = "Please enter the location for your desired study area. " + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" - + " location is entered. When you are done with the search, enter \"end\"."; + + " location is entered. When you are done with the search, enter \"bye\"."; public static final String PROMPT_USER = "Please enter the location for your desired study area."; - public static final String FLAGS = "\t Here is a list of supported flags!\n\t -p for study areas with ports\n\t" + public static final String FLAGS = "Here is a list of supported flags!\n\t -p for study areas with ports\n\t" + " -i for study areas that are indoors\n\t -s {size} for maximum number of pax"; public static final String AVAILABLE_STUDY_AREAS = "Here are the available study areas!"; public static final String EMPTY_LIST = "Oops! Based on your criteria we were not able to find a compatible study" + "area!"; public static final String ONLY_FLAG = "Please enter the flag along with \"-\""; public static final String INCONSISTENT_DATA_STORAGE = "Data is wrongly stored in locations.txt"; - public static final String END_COMMAND = "end"; public static final String HELP_COMMAND = "help"; public static final String TAB = "\t "; public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; + public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"event\" to start your event" + + " list! If you are in the mood to mug and you want to start your study area list, enter \"study\" !" + + "If you want to exit, enter \"bye\" !"; + public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; + public static final String EVENT_COMMAND = "event"; + public static final String STUDY_COMMAND = "study"; + public static final String GOODBYE_MESSAGE = "Goodbye! Hope to see you again!"; + public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or" + + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; + public static final String EMPTY_LOCATION = "Location entered is empty! Please type a location to search for " + + "StudyAreas!"; + + //@@author NizarMohd-reused + //Reused from https://www.netclipart.com/isee/iRwmhJb_bt21-rj-transparent-background/ and https://asciiart.club/ + //Image for public static final String DAB is obtained from the first link and then generated in second link. + public static final String DAB = "\t ``````````````````````````````````````````````````````````\n" + + "\t ````````````````````````````````:v(v'`````````````````````\n" + + "\t ```````````````````````````,)4|ex` `L}````````````````````\n" + + "\t `````````````````````````!s\"'h `M: ^z_;)T```````````````\n" + + "\t `````````````````````````Z u|}Z: \"}``````````````\n" + + "\t ``````````````````````:=?) 'B?L'```````````\n" + + "\t `````````````````````'Z ;Yp\"```````````\n" + + "\t `````````````````````.e ?_```````````\n" + + "\t ```````````````````'QDGH .5````````````\n" + + "\t ````````````````````I#g' '_` ||````````````\n" + + "\t ```````````:mX_``````YhL` `'q!` ? h````````````\n" + + "\t ```````````'Qbs)|L=_V\" 'Y} ^'q@&b=c=_` ,Z````````````\n" + + "\t ````````````q> 'T, ,o\" ;\"@c. .sVx~`````````````\n" + + "\t ````````````c! \"bh` `,p z:``````````````\n" + + "\t `````````````q. ngDQmh8s X'``````````````\n" + + "\t ``````````````LY\" :n}>``b; _V```````````````\n" + + "\t ````````````````q?, ?; \"V````````````````\n" + + "\t ``````````````KvR ' )x_`````````````````\n" + + "\t ``````````````zjL GLY\"```````````````````\n" + + "\t ```````````````M .I)``````````````````````\n" + + "\t ```````````````Lz `D:``````````````````````\n" + + "\t ``````````````vu` (I)_;\"\". P.`````````````````````\n" + + "\t ``````````````p :X.':^,\"=n \"q``````````````````````\n" + + "\t `````````````)0X?^:)I````````m' :j``````````````````````\n" + + "\t `````````````.IGD8k'`````````<&G55M```````````````````````\n" + + "\t ``````````````````````````````````````````````````````````"; + //@@author + + + /** + * This is the constructor used to create the Ui class in Duke.run(). + */ + public Ui() { + this(System.in, System.out); + } + + /** + * This constructor assigns IO stream to the attributes of Ui. + * + * @param in This is the Input Stream for Ui. + * @param out This is the Output Stream for Ui. + */ + public Ui(InputStream in, PrintStream out) { + this.in = new Scanner(in); + this.out = out; + } + + /** + * Returns the mode (event features or StudyArea features or exit) based on User input. + * + * @return an integer which is assigned to each mode. + */ + public int getMode() { + String userIn = this.in.nextLine().toLowerCase(); + switch (userIn) { + case EVENT_COMMAND : + return 1; + case STUDY_COMMAND : + return 2; + case BYE_COMMAND : + return -1; + default : + return 0; + } + } + + /** + * This method allows for other class to get User input. + * + * @return String input from User. + */ + public String getUserIn() { + return this.in.nextLine(); + } + + /** + * This method closes the Input Stream after usage is completed. + */ + public void close() { + this.in.close(); + } /** - * This method ensures that the message printed is within the standard length. - * @param message is the String that we intend to format to a standard length per line. + * This method allows other classes to print messages to interact with User. + * + * @param message This is the message that is intended to be printed to Users. + */ + public void printMessage(String message) { + if (message.equals(GOODBYE_MESSAGE + DAB)) { + this.out.println(formatMessage(GOODBYE_MESSAGE, MAX_LINE_LENGTH)); + this.out.println(DAB); + } else { + this.out.println(formatMessage(message, MAX_LINE_LENGTH)); + } + } + + /** + * This method allows for StudyAreaCommand to print StudyArea based on its actual format, + * so that formatMessage method does not interfere with the initial format. + * + * @param studyArea This is the StudyArea to be printed. + */ + public void printStudyArea(StudyArea studyArea) { + this.out.println(studyArea.toString()); + } + + /** + * Prints a line made up of '_'. + */ + public void printLine() { + System.out.println(LINE); + } + + /** + * This is a modification of a code from Stack Overflow to format strings into a standard length. Minor edition is + * made to ensure suitability with the program. + * This method ensures that the message printed is within the standard
+ * length. + * @param message is the String that we intend to format to a standard length
+ * per line.
* @param maxLength This is the standard length intended to be formatted. * @return String of standard length per line */ + //@@author NizarMohd-reused + //Reused from https://stackoverflow.com/questions/7528045/large-string-split-into-lines-with-maximum-length-in-java + // with minor modification. public static String formatMessage(String message, int maxLength) { StringTokenizer token = new StringTokenizer(message, SPACE); StringBuilder standardLengthMessage = new StringBuilder(message.length()); @@ -85,42 +216,71 @@ public static String formatMessage(String message, int maxLength) { } return TAB + standardLengthMessage.toString().stripTrailing(); } + //@@author /** * Display the list of supported commands. */ public void printHelp() { - printLine(); - System.out.println("OrgaNice! Supports the following commands"); - System.out.println("Please enter the keywords followed by the information shown in the brackets"); - System.out.println("add /d /s /e /p "); - System.out.println("------------------------------------------- Create a new event"); - System.out.println("view -------------------------------------- View existing events"); - System.out.println("priority_view ----------------------------- View existing events based on priority"); - System.out.println("countdown --------------------------------- View existing events based on days left"); - System.out.println("clear ------------------------------------- Delete all events"); - System.out.println("search ----------- View existing events that contains " + this.out.println("OrgaNice! Supports the following commands"); + this.out.println("Please enter the keywords followed by the information shown in the brackets"); + this.out.println("add /d /s /e /p "); + this.out.println("------------------------------------------- Create a new event"); + this.out.println("view -------------------------------------- View existing events"); + this.out.println("priority_view ----------------------------- View existing events based on priority"); + this.out.println("countdown --------------------------------- View existing events based on days left"); + this.out.println("clear ------------------------------------- Delete all events"); + this.out.println("search ----------- View existing events that contains " + "the keyword"); - System.out.println("delete ------------ Delete the event"); - System.out.println("bye --------------------------------------- Terminate program"); - System.out.println("Notes:"); - System.out.println("*All dates should follow YYYY-MM-DD format"); - System.out.println("*All timing should follow 24 hour clock"); - System.out.println("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " + this.out.println("delete ------------ Delete the event"); + this.out.println("bye --------------------------------------- Terminate program"); + this.out.println("Notes:"); + this.out.println("*All dates should follow YYYY-MM-DD format"); + this.out.println("*All timing should follow 24 hour clock"); + this.out.println("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " + "least urgent"); - printLine(); } /** - * Display welcome message. + * Prints the welcome message and starts interaction with user. */ public void printWelcomeMessage() { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - System.out.println("What is your name?"); + + //@@author NizarMohd-reused + //Reused logo from http://patorjk.com/software/taag/#p=display&f=Graffiti&t=TypeSomething with minor + // modifications. The website above allows for generation of fonts in ascii format. Therefore, logo is + // generated from the service provided by the website. + String logo = "_______/\\\\\\\\\\_____________________________________________________/\\\\\\\\\\_____/\\\\\\__" + + "__________________________________________/\\\\\\____________\n" + + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" + + "_________________________________________/\\\\\\\\\\\\\\_________\n" + + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" + + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______\n" + + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" + + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\_______\n" + + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" + + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" + + "___\n" + + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" + + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" + + "_____\n" + + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" + + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______\n" + + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\\\/\\\\" + + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" + + "_/\\\\\\_____\n" + + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" + + "_\\///______\\////////_____\\//////////______\\///_____"; + //@@author + this.out.println("Hello from\n" + logo); + this.out.println("What is your name?"); + printLine(); + String name = this.in.nextLine(); + printLine(); + this.out.println(TAB + "Hello " + name + "!"); + this.out.println(formatMessage(START_MESSAGE, MAX_LINE_LENGTH)); + printLine(); } -} +} \ No newline at end of file From 64f28692ce5d8d0dca51b424cce4b50169ea837e Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Tue, 10 Mar 2020 22:32:46 +0800 Subject: [PATCH 049/435] Refactor code to separate parser and command classes --- src/main/java/command/AddCommand.java | 40 ++++++++++ src/main/java/command/ClearCommand.java | 27 +++++++ src/main/java/command/Command.java | 18 +++++ src/main/java/command/CountdownCommand.java | 27 +++++++ src/main/java/command/DeleteCommand.java | 37 +++++++++ src/main/java/command/EventCommand.java | 74 +++++++----------- src/main/java/command/HelpCommand.java | 27 +++++++ .../java/command/PriorityViewCommand.java | 27 +++++++ src/main/java/command/SearchCommand.java | 32 ++++++++ src/main/java/command/ViewCommand.java | 27 +++++++ src/main/java/parser/Parser.java | 78 +++++++++++++++++++ src/main/java/ui/Ui.java | 75 +++++++----------- 12 files changed, 395 insertions(+), 94 deletions(-) create mode 100644 src/main/java/command/AddCommand.java create mode 100644 src/main/java/command/ClearCommand.java create mode 100644 src/main/java/command/Command.java create mode 100644 src/main/java/command/CountdownCommand.java create mode 100644 src/main/java/command/DeleteCommand.java create mode 100644 src/main/java/command/HelpCommand.java create mode 100644 src/main/java/command/PriorityViewCommand.java create mode 100644 src/main/java/command/SearchCommand.java create mode 100644 src/main/java/command/ViewCommand.java create mode 100644 src/main/java/parser/Parser.java diff --git a/src/main/java/command/AddCommand.java b/src/main/java/command/AddCommand.java new file mode 100644 index 000000000..c8603270e --- /dev/null +++ b/src/main/java/command/AddCommand.java @@ -0,0 +1,40 @@ +package command; + +import event.Event; +import event.EventList; + +/** + * This command is used to add new events to the event list. + */ +public class AddCommand extends Command { + + /** The new event to be added. */ + Event newEvent; + + /** + * Constructor for the AddCommand Object. + * Abstracts out the details from the user input and uses it to create a new event object. + * + * @param eventDetails The array contains the information regarding the new event to be added. + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used to create an event. + */ + public AddCommand(String[] eventDetails, boolean isOneWordCommand) throws Exception { + if (isOneWordCommand) { + throw new Exception("Wrong format used to add an event"); + } + String[] details = eventDetails[1].split("/"); + String description = details[0]; + String date = details[1].substring(2); + String startTime = details[2].substring(2); + String endTime = details[3].substring(2); + String priority = details[4].substring(2); + newEvent = new Event(description,date,startTime,endTime,priority); + } + + @Override + public void executeCommand(EventList eventList) { + eventList.addEvent(newEvent); + } + +} diff --git a/src/main/java/command/ClearCommand.java b/src/main/java/command/ClearCommand.java new file mode 100644 index 000000000..4a49f4733 --- /dev/null +++ b/src/main/java/command/ClearCommand.java @@ -0,0 +1,27 @@ +package command; + +import event.EventList; + +/** + * This command is used to clear all the events in the list. + */ +public class ClearCommand extends Command { + + /** + * Constructor for the ClearCommand Object. + * Checks if the user given input follows the correct format. + * + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public ClearCommand(boolean isOneWordCommand) throws Exception { + if (!isOneWordCommand) { + throw new Exception("Wrong command clear events (Should be :clear )"); + } + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.clearEvents(); + } +} diff --git a/src/main/java/command/Command.java b/src/main/java/command/Command.java new file mode 100644 index 000000000..c62c09a8e --- /dev/null +++ b/src/main/java/command/Command.java @@ -0,0 +1,18 @@ +package command; + +import event.EventList; + +/** + * Object represents a command and contains all the required information and implementation to execute it. + */ +public abstract class Command { + + /** + * Executes the command based on the information provided by the user. + * + * @param eventList Contains the list of tasks on which the commands are executed on. + * @throws Exception If issues are found during execution of command. + */ + public abstract void executeCommand(EventList eventList) throws Exception; + +} diff --git a/src/main/java/command/CountdownCommand.java b/src/main/java/command/CountdownCommand.java new file mode 100644 index 000000000..3fa595bf2 --- /dev/null +++ b/src/main/java/command/CountdownCommand.java @@ -0,0 +1,27 @@ +package command; + +import event.EventList; + +/** + * Displays the list of events added so far in increasing order of their dates. + */ +public class CountdownCommand extends Command { + + /** + * Constructor for the CountdownCommand Object. + * Creates a new object if the correct format is used. + * + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public CountdownCommand(boolean isOneWordCommand) throws Exception { + if (!isOneWordCommand) { + throw new Exception("Wrong command used to view countdown of events (Should be :countdown )"); + } + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.countdownView(); + } +} diff --git a/src/main/java/command/DeleteCommand.java b/src/main/java/command/DeleteCommand.java new file mode 100644 index 000000000..2e468808f --- /dev/null +++ b/src/main/java/command/DeleteCommand.java @@ -0,0 +1,37 @@ +package command; + +import event.EventList; + +/** + * Command is used to delete an event at a specific index. + */ +public class DeleteCommand extends Command { + + /** Denotes the index at which the event should be deleted at. */ + int indexToDelete; + + /** + * Constructor for the DeleteCommand object. + * Creates a new object if the correct command is used. + * + * @param commandSplit Contains information with regards to the index to be deleted at. + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the index specified is invalid/ The wrong format is used for the command. + */ + public DeleteCommand(String[] commandSplit, boolean isOneWordCommand) throws Exception { + if (isOneWordCommand) { + throw new Exception("Index to delete not mentioned"); + } + try { + indexToDelete = Integer.parseInt(commandSplit[1]); + } catch (NumberFormatException e) { + throw new Exception("Enter a valid index (1-based) to delete the corresponding event"); + } + } + + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.deleteEvent(indexToDelete); + } +} diff --git a/src/main/java/command/EventCommand.java b/src/main/java/command/EventCommand.java index 9e9c98ef9..cffcaace9 100644 --- a/src/main/java/command/EventCommand.java +++ b/src/main/java/command/EventCommand.java @@ -1,63 +1,45 @@ package command; import event.EventList; +import parser.Parser; import ui.Ui; import java.util.Scanner; +import static ui.Ui.BYE_COMMAND; + +/** + * Used to run all the functions related to events. + */ public class EventCommand { /** - * Commands for Events. + * Runs all the command for events. * - * @param eventList evenList + * @param eventList Refers to the current list of events. + * @param ui UI object used to interact with user. + * @param parser Object used to parse the user input into commands. */ - public static void runCommands(EventList eventList) { - Scanner in = new Scanner(System.in); - String command; - command = in.nextLine(); - while (!command.equals(Ui.BYE_COMMAND)) { + public void runCommands(EventList eventList, Ui ui, Parser parser) { + eventList.printHelp(); + Scanner sc = new Scanner(System.in); + String fullCommand; + Command command; + + fullCommand = sc.nextLine(); + while (!fullCommand.equals(BYE_COMMAND)) { try { - String commandType = command.split(" ")[0]; - switch (commandType) { - case Ui.ADD_COMMAND: - eventList.add(command); - break; - case Ui.VIEW_COMMAND: - eventList.listEvents(); - break; - case Ui.PRIORITY_VIEW_COMMAND: - eventList.priorityView(); - break; - case Ui.COUNTDOWN_VIEW_COMMAND: - eventList.countdownView(); - break; - case Ui.CLEAR_COMMAND: - eventList.clearEvents(); - break; - case Ui.SEARCH_COMMAND: - eventList.searchEvents(command.split(" ", 2)[1]); - break; - case Ui.DELETE_COMMAND: - eventList.deleteEvent(Integer.parseInt(command.split(" ", 2)[1])); - break; - default: - Ui.printLine(); - System.out.println(Ui.INVALID_COMMAND_MESSAGE); - Ui.printLine(); - break; - } - } catch (NumberFormatException e) { - Ui.printLine(); - System.out.println(Ui.INVALID_INDEX_MESSAGE); - Ui.printLine(); - } catch (IndexOutOfBoundsException e) { - Ui.printLine(); - System.out.println(Ui.INVALID_COMMAND_MESSAGE); - Ui.printLine(); + command = parser.parseCommand(fullCommand, ui); + command.executeCommand(eventList); + } catch (Exception exception) { + ui.printLine(); + ui.printWithIndentation(exception.getMessage()); + ui.printLine(); } - command = in.nextLine(); + ui.printEmptyLine(); + fullCommand = sc.nextLine(); } - System.out.println(Ui.BYE_MESSAGE); + ui.printByeMessage(); } + } diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java new file mode 100644 index 000000000..bb2536e3a --- /dev/null +++ b/src/main/java/command/HelpCommand.java @@ -0,0 +1,27 @@ +package command; + +import event.EventList; + +/** + * Command is used to print the list of commands supported. + */ +public class HelpCommand extends Command { + + /** + * Constructor for the HelpCommand object. + * Creates a new object if the correct format is used. + * + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public HelpCommand(boolean isOneWordCommand) throws Exception { + if (!isOneWordCommand) { + throw new Exception("Wrong command used to view command list (Should be :help )"); + } + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.printHelp(); + } +} diff --git a/src/main/java/command/PriorityViewCommand.java b/src/main/java/command/PriorityViewCommand.java new file mode 100644 index 000000000..60d6e63e3 --- /dev/null +++ b/src/main/java/command/PriorityViewCommand.java @@ -0,0 +1,27 @@ +package command; + +import event.EventList; + +/** + * Displays the list of events added so far in decreasing order of their priority. + */ +public class PriorityViewCommand extends Command { + + /** + * Constructor for the PriorityViewCommand Object. + * Creates a new object if the correct format is used. + * + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public PriorityViewCommand(boolean isOneWordCommand) throws Exception { + if (!isOneWordCommand) { + throw new Exception("Wrong command used to view events sorted by priority (Should be :priority_view )"); + } + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.priorityView(); + } +} diff --git a/src/main/java/command/SearchCommand.java b/src/main/java/command/SearchCommand.java new file mode 100644 index 000000000..bf682eb21 --- /dev/null +++ b/src/main/java/command/SearchCommand.java @@ -0,0 +1,32 @@ +package command; + +import event.EventList; + +/** + * Command used to perform a search of events whose description contain the keyword mentioned. + */ +public class SearchCommand extends Command { + + /** The word to be searched for. */ + String keyword; + + /** + * Constructor for SearchCommand object. + * Creates a new object if the correct format is used. + * + * @param commandSplit Contains the keyword to be searched for. + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public SearchCommand(String[] commandSplit, boolean isOneWordCommand) throws Exception { + if (isOneWordCommand) { + throw new Exception("The search string entered is empty."); + } + this.keyword = commandSplit[1]; + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.searchEvents(keyword); + } +} diff --git a/src/main/java/command/ViewCommand.java b/src/main/java/command/ViewCommand.java new file mode 100644 index 000000000..da4e62282 --- /dev/null +++ b/src/main/java/command/ViewCommand.java @@ -0,0 +1,27 @@ +package command; + +import event.EventList; + +/** + * Displays the list of events added so far. + */ +public class ViewCommand extends Command { + + /** + * Constructor for the ViewCommand Object. + * Creates a new object if the correct format is used. + * + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public ViewCommand(boolean isOneWordCommand) throws Exception { + if (!isOneWordCommand) { + throw new Exception("Wrong command used to view events (Should be :view )"); + } + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.listEvents(); + } +} diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java new file mode 100644 index 000000000..4b370a34e --- /dev/null +++ b/src/main/java/parser/Parser.java @@ -0,0 +1,78 @@ +package parser; + +import command.AddCommand; +import command.ClearCommand; +import command.Command; +import command.CountdownCommand; +import command.DeleteCommand; +import command.HelpCommand; +import command.PriorityViewCommand; +import command.SearchCommand; +import command.ViewCommand; +import ui.Ui; + +/** + * This class is used to parse the user input into executable commands. + */ +public class Parser { + + public static final String ADD_COMMAND = "add"; + public static final String VIEW_COMMAND = "view"; + public static final String PRIORITY_VIEW_COMMAND = "priority_view"; + public static final String COUNTDOWN_VIEW_COMMAND = "countdown"; + public static final String CLEAR_COMMAND = "clear"; + public static final String SEARCH_COMMAND = "search"; + public static final String DELETE_COMMAND = "delete"; + public static final String EMPTY_COMMAND = ""; + public static final String HELP_COMMAND = "help"; + + /** + * This method takes in the user input parses it and returns the command to be executed. + * + * @param fullCommand THe entire line of command entered by the user. + * @param ui Object used to handle interactions with user. + * @return command The command parsed form the user input. + * @throws Exception If the wrong command/ wrong format is given by the user as an input. + */ + public Command parseCommand(String fullCommand, Ui ui) throws Exception { + + String[] commandSplit = fullCommand.split(" ",2); + String commandType = commandSplit[0]; + Command command; + boolean isOneWordCommand = commandSplit.length == 1 || commandSplit[1].isBlank(); + switch (commandType) { + case ADD_COMMAND: + command = new AddCommand(commandSplit, isOneWordCommand); + break; + case VIEW_COMMAND: + command = new ViewCommand(isOneWordCommand); + break; + case PRIORITY_VIEW_COMMAND: + command = new PriorityViewCommand(isOneWordCommand); + break; + case COUNTDOWN_VIEW_COMMAND: + command = new CountdownCommand(isOneWordCommand); + break; + case CLEAR_COMMAND: + command = new ClearCommand(isOneWordCommand); + break; + case SEARCH_COMMAND: + command = new SearchCommand(commandSplit, isOneWordCommand); + break; + case DELETE_COMMAND: + command = new DeleteCommand(commandSplit, isOneWordCommand); + break; + case HELP_COMMAND: + command = new HelpCommand(isOneWordCommand); + break; + case EMPTY_COMMAND: + throw new Exception("Empty Line entered, Please enter a valid line"); + // Break statement can't be reached if added + default: + throw new Exception("Invalid command entered, Please enter a valid command"); + // Break statement can't be reached if added + } + return command; + } + +} diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 89e7aee57..373edc14b 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -9,30 +9,7 @@ public class Ui { public static final String FILE_PATH_EVENTS = "library" + File.separator + "eventList.txt"; public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; - - public static final String ADD_COMMAND = "add"; - public static final String VIEW_COMMAND = "view"; - public static final String PRIORITY_VIEW_COMMAND = "priority_view"; - public static final String COUNTDOWN_VIEW_COMMAND = "countdown"; - public static final String CLEAR_COMMAND = "clear"; - public static final String SEARCH_COMMAND = "search"; - public static final String DELETE_COMMAND = "delete"; - public static final String INVALID_INDEX_MESSAGE = "Enter a valid index"; - public static final String INVALID_COMMAND_MESSAGE = "Enter a valid command"; public static final String BYE_COMMAND = "bye"; - public static final String BYE_MESSAGE = "Bye!!!!!!"; - - /** - * Prints a line made up of '_'. - */ - public static void printLine() { - System.out.println("____________________________________________________________________________________"); - } - - public static void printWithIndentation(String line) { - System.out.println(" " + line); - } - public static final int MAX_LINE_LENGTH = 55; public static final int ADDRESS_MAX_LENGTH = 48; public static final String FLAG = "-"; @@ -63,6 +40,17 @@ public static void printWithIndentation(String line) { public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; + /** + * Prints a line made up of '_'. + */ + public void printLine() { + System.out.println("_________________________________________________________________________________" + + "_______________"); + } + + public void printWithIndentation(String line) { + System.out.println(" " + line); + } /** * This method ensures that the message printed is within the standard length. * @param message is the String that we intend to format to a standard length per line. @@ -86,31 +74,6 @@ public static String formatMessage(String message, int maxLength) { return TAB + standardLengthMessage.toString().stripTrailing(); } - /** - * Display the list of supported commands. - */ - public void printHelp() { - printLine(); - System.out.println("OrgaNice! Supports the following commands"); - System.out.println("Please enter the keywords followed by the information shown in the brackets"); - System.out.println("add /d /s /e /p "); - System.out.println("------------------------------------------- Create a new event"); - System.out.println("view -------------------------------------- View existing events"); - System.out.println("priority_view ----------------------------- View existing events based on priority"); - System.out.println("countdown --------------------------------- View existing events based on days left"); - System.out.println("clear ------------------------------------- Delete all events"); - System.out.println("search ----------- View existing events that contains " - + "the keyword"); - System.out.println("delete ------------ Delete the event"); - System.out.println("bye --------------------------------------- Terminate program"); - System.out.println("Notes:"); - System.out.println("*All dates should follow YYYY-MM-DD format"); - System.out.println("*All timing should follow 24 hour clock"); - System.out.println("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " - + "least urgent"); - printLine(); - } - /** * Display welcome message. */ @@ -123,4 +86,20 @@ public void printWelcomeMessage() { System.out.println("Hello from\n" + logo); System.out.println("What is your name?"); } + + /** + * Prints an empty line. + */ + public void printEmptyLine() { + System.out.println(); + } + + /** + * Prints the bye message. + */ + public void printByeMessage() { + printLine(); + printWithIndentation("Bye!!!!!"); + printLine(); + } } From b1e1943f9ea0ec244924a203781fd779f83f0065 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Tue, 10 Mar 2020 22:33:59 +0800 Subject: [PATCH 050/435] Add help command support to EventList --- src/main/java/event/EventList.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index 947d606da..0f5eae39e 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -171,4 +171,34 @@ public void add(String eventDetails) { ui.printLine(); } } + + /** + * Display the list of supported commands. + */ + public void printHelp() { + ui.printLine(); + ui.printWithIndentation("OrgaNice! Supports the following commands"); + ui.printWithIndentation("Please enter the keywords followed by the information shown in the brackets"); + ui.printWithIndentation("add /d /s /e /p "); + ui.printWithIndentation("------------------------------------------- Create a new event"); + ui.printWithIndentation("view -------------------------------------- View existing events"); + ui.printWithIndentation("priority_view ----------------------------- View existing events based " + + "on priority"); + ui.printWithIndentation("countdown --------------------------------- View existing events based on" + + " days left"); + ui.printWithIndentation("clear ------------------------------------- Delete all events"); + ui.printWithIndentation("search ----------- View existing events that contains " + + "the keyword"); + ui.printWithIndentation("delete ------------ Delete the event"); + ui.printWithIndentation("help -------------------------------------- View List Of Commands Supported"); + ui.printWithIndentation("bye --------------------------------------- Terminate program"); + ui.printWithIndentation("Notes:"); + ui.printWithIndentation("*All dates should follow YYYY-MM-DD format"); + ui.printWithIndentation("*All timing should follow 24 hour clock"); + ui.printWithIndentation("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " + + "least urgent"); + ui.printLine(); + } + } From 0cd81ad4a09ce5fbf7c218d17509bb7ffa3dd250 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Tue, 10 Mar 2020 22:34:34 +0800 Subject: [PATCH 051/435] Rectify issues --- library/eventList.txt | 1 + src/main/java/command/StudyAreaCommand.java | 6 +++--- src/main/java/driver/Driver.java | 11 +++++++---- src/main/java/event/Event.java | 1 + .../java/resourceloader/StudyAreaLoader.java | 1 + src/main/java/seedu/duke/Duke.java | 17 +++++++++++++++-- src/main/java/studyarea/StudyAreaList.java | 1 + 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/library/eventList.txt b/library/eventList.txt index e69de29bb..2b38057ff 100644 --- a/library/eventList.txt +++ b/library/eventList.txt @@ -0,0 +1 @@ +school #2020-04-05#12:12#12:14#123 \ No newline at end of file diff --git a/src/main/java/command/StudyAreaCommand.java b/src/main/java/command/StudyAreaCommand.java index be6c63ff0..9157680c1 100644 --- a/src/main/java/command/StudyAreaCommand.java +++ b/src/main/java/command/StudyAreaCommand.java @@ -70,11 +70,11 @@ public static void runCommands(StudyAreaList studyAreaList) { Scanner in = new Scanner(System.in); boolean status = true; while (status) { - Ui.printLine(); + ui.printLine(); String command = in.nextLine(); - Ui.printLine(); + ui.printLine(); status = filterCommand(command, studyAreaList); } - Ui.printLine(); + ui.printLine(); } } diff --git a/src/main/java/driver/Driver.java b/src/main/java/driver/Driver.java index a09b7c01a..210fbe1eb 100644 --- a/src/main/java/driver/Driver.java +++ b/src/main/java/driver/Driver.java @@ -4,6 +4,7 @@ import event.EventList; import java.io.FileNotFoundException; +import parser.Parser; import resourceloader.EventLoader; import resourceloader.StudyAreaLoader; import studyarea.IllegalStudyAreaException; @@ -20,11 +21,13 @@ public class Driver { * This class setups the loading of events and study areas into * the program and runs either study area or organiser functionality. * - * @param mode 1 for organiser, 0 for study area + * @param mode 1 for organiser, 0 for study area. + * @param ui Object used to interact with user. + * @param parser Object used to parse user commands. * @throws FileNotFoundException if file is not found. - * @throws IllegalStudyAreaException custom exception for study area + * @throws IllegalStudyAreaException custom exception for study area. */ - public Driver(int mode) throws FileNotFoundException, IllegalStudyAreaException { + public Driver(int mode, Ui ui, Parser parser) throws FileNotFoundException, IllegalStudyAreaException { eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); EventList eventList = new EventList(eventLoader.loadFile()); @@ -33,7 +36,7 @@ public Driver(int mode) throws FileNotFoundException, IllegalStudyAreaException if (mode == 1) { EventCommand eventCommand = new EventCommand(); - eventCommand.runCommands(eventList); + eventCommand.runCommands(eventList, ui, parser); eventLoader.saveEvents(eventList.events); } else { StudyAreaCommand studyAreaCommand = new StudyAreaCommand(); diff --git a/src/main/java/event/Event.java b/src/main/java/event/Event.java index 487c48845..00a511c82 100644 --- a/src/main/java/event/Event.java +++ b/src/main/java/event/Event.java @@ -112,6 +112,7 @@ public LocalDate getDate() { * * @param keyword The keyword to be matched with the description. * @return containsKeyword Indicates the presence/absence of keyword in the event's description. + * @throws Exception If keyword entered is emoty. */ public boolean hasKeyword(String keyword) throws Exception { if (keyword.equals("")) { diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index 0cee4dcc5..cb4b1f1ca 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -42,6 +42,7 @@ public void loadFile() throws FileNotFoundException { * * @return buffer ArrayList of Location from study area file * @throws FileNotFoundException if location.txt does not exist. + * @throws IllegalStudyAreaException If error is encountered during execution. */ public ArrayList pushToDatabase() throws FileNotFoundException, IllegalStudyAreaException { diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 1fa01f6b9..d2ef576ee 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,18 +1,26 @@ package seedu.duke; +import command.Command; import driver.Driver; +import event.EventList; +import parser.Parser; import ui.Ui; +import java.util.InputMismatchException; import java.util.Scanner; +import static ui.Ui.BYE_COMMAND; + public class Duke { private static Ui ui = new Ui(); + private static Parser parser = new Parser(); /** * Main entry-point for the java.duke.Duke application. * @param args Commandline argument + * @throws Exception If error is found during execution. */ public static void main(String[] args) throws Exception { ui.printWelcomeMessage(); @@ -26,12 +34,17 @@ public static void main(String[] args) throws Exception { * study areas: enter 0 * To end events loop: enter bye in events prog * To end study areas loop: enter end in study area loop - * To end overall prog, enter ctrl+c or ctrl+z + * To end overall prog, enter ctrl+c or ctrl+z or enter any string of letters. * Take note: this is still temporary */ while (true) { Scanner mode = new Scanner(System.in); - Driver driver = new Driver(mode.nextInt()); + try { + Driver driver = new Driver(mode.nextInt(), ui, parser); + } catch (NumberFormatException | InputMismatchException e) { + break; + } } } + } diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 2f36b914c..9d930b277 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -110,6 +110,7 @@ public static boolean containsKey(String name, String faculty, String key) { * * @param userIn This is the requirement entered by User * @return ArrayList of StudyAreas + * @throws IllegalStudyAreaException If error is encountered during execution. */ public ArrayList searchList(String userIn) throws IllegalStudyAreaException { From aa4f70e79e995530aba339b6cdff7e50a88b0839 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Tue, 10 Mar 2020 23:55:30 +0800 Subject: [PATCH 052/435] Rectify issue with text-ui-test --- src/main/java/resourceloader/EventLoader.java | 1 - src/main/java/seedu/duke/Duke.java | 7 +-- src/main/java/studyarea/StudyArea.java | 2 +- src/main/java/ui/Ui.java | 50 ++++------------- text-ui-test/ACTUAL.TXT | 55 ++++++++++++++++--- text-ui-test/EXPECTED.TXT | 55 ++++++++++++++++--- text-ui-test/input.txt | 3 +- text-ui-test/runtest.sh | 3 + 8 files changed, 115 insertions(+), 61 deletions(-) diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java index bd71727ca..30ecc2a98 100644 --- a/src/main/java/resourceloader/EventLoader.java +++ b/src/main/java/resourceloader/EventLoader.java @@ -85,7 +85,6 @@ private Event parseEventDetails(String taskDescription) throws Exception { * Creates a new data file when the application is run for the first time. */ private void createNewDataFile() { - try { Files.createDirectories(fileDirectory); Files.createFile(Paths.get(filePath)); diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 6867546f9..189f026ed 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -32,16 +32,15 @@ public class Duke { */ public Duke() { try { + ui = new Ui(); + parser = new Parser(); eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); eventList = new EventList(eventLoader.loadFile()); studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); - ui = new Ui(); - parser = new Parser(); } catch (FileNotFoundException | IllegalStudyAreaException e) { Ui ui = new Ui(); ui.printMessage(e.getMessage()); - ui.close(); } } @@ -68,7 +67,7 @@ public void run() { ui.printMessage(Ui.WRONG_INPUT); break; } - ui.printMessage(Ui.INTERMEDIATE_MESSAGE); + ui.printWithIndentation(Ui.INTERMEDIATE_MESSAGE); ui.printLine(); } eventLoader.saveEvents(eventList.events); diff --git a/src/main/java/studyarea/StudyArea.java b/src/main/java/studyarea/StudyArea.java index 803254261..d790c887d 100644 --- a/src/main/java/studyarea/StudyArea.java +++ b/src/main/java/studyarea/StudyArea.java @@ -32,7 +32,7 @@ public class StudyArea { public StudyArea(String name, String address, String faculty, boolean hasPort, boolean isIndoor, int maxPax) { this.name = name; - this.address = Ui.formatMessage(address, Ui.ADDRESS_MAX_LENGTH).trim(); + this.address = address.trim(); this.faculty = faculty; this.hasPort = hasPort; this.isIndoor = isIndoor; diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index c29088686..2fdc456b4 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -50,15 +50,16 @@ public class Ui { public static final String TAB = "\t "; public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; - public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"event\" to start your event" - + " list! If you are in the mood to mug and you want to start your study area list, enter \"study\" !" - + "If you want to exit, enter \"bye\" !"; + public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"event\" to start\n" + + " your event list! If you are in the mood to mug and you\n" + + " want to start your study area list, enter \"study\" !If\n" + + " you want to exit, enter \"bye\" !"; public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; public static final String EVENT_COMMAND = "event"; public static final String STUDY_COMMAND = "study"; - public static final String GOODBYE_MESSAGE = "Goodbye! Hope to see you again!"; - public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or" - + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; + public static final String GOODBYE_MESSAGE = " Goodbye! Hope to see you again!"; + public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or\n" + + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; public static final String EMPTY_LOCATION = "Location entered is empty! Please type a location to search for " + "StudyAreas!"; @@ -171,10 +172,10 @@ public void printWithIndentation(String line) { */ public void printMessage(String message) { if (message.equals(GOODBYE_MESSAGE + DAB)) { - this.out.println(formatMessage(GOODBYE_MESSAGE, MAX_LINE_LENGTH)); + this.out.println(GOODBYE_MESSAGE); this.out.println(DAB); } else { - this.out.println(formatMessage(message, MAX_LINE_LENGTH)); + this.out.println(message); } } @@ -188,37 +189,6 @@ public void printStudyArea(StudyArea studyArea) { this.out.println(studyArea.toString()); } - /** - * This is a modification of a code from Stack Overflow to format strings into a standard length. Minor edition is - * made to ensure suitability with the program. - * This method ensures that the message printed is within the standard
- * length. - * @param message is the String that we intend to format to a standard length
- * per line.
- * @param maxLength This is the standard length intended to be formatted. - * @return String of standard length per line - */ - - //@@author NizarMohd-reused - //Reused from https://stackoverflow.com/questions/7528045/large-string-split-into-lines-with-maximum-length-in-java - // with minor modification. - public static String formatMessage(String message, int maxLength) { - StringTokenizer token = new StringTokenizer(message, SPACE); - StringBuilder standardLengthMessage = new StringBuilder(message.length()); - int lineLength = 0; - while (token.hasMoreTokens()) { - String word = token.nextToken(); - if (lineLength + word.length() > maxLength) { - standardLengthMessage.append("\n\t "); - lineLength = 0; - } - standardLengthMessage.append(word).append(SPACE); - lineLength += word.length() + 1; - } - return TAB + standardLengthMessage.toString().stripTrailing(); - } - //@@author - /** * Display welcome message. */ @@ -258,7 +228,7 @@ public void printWelcomeMessage() { String name = this.in.nextLine(); printLine(); this.out.println(TAB + "Hello " + name + "!"); - this.out.println(formatMessage(START_MESSAGE, MAX_LINE_LENGTH)); + printWithIndentation(START_MESSAGE); printLine(); } diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 892cb6cae..24b4bf48b 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -1,9 +1,50 @@ +library\locations.txt (The system cannot find the file specified) Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +_______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ +______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ +_____/\\\/__\///\\\____________________/\\\\\\\\___________________\/\\\/\\\__\/\\\___/\\\__________________________________/\\\\\\\\\_______ +_____/\\\______\//\\\___/\\/\\\\\\\____/\\\////\\\___/\\\\\\\\\_____\/\\\//\\\_\/\\\__\///_______/\\\\\\\\______/\\\\\\\\___\//\\\\\\\_______ +_____\/\\\_______\/\\\__\/\\\/////\\\__\//\\\\\\\\\__\////////\\\____\/\\\\//\\\\/\\\___/\\\____/\\\//////_____/\\\/////\\\___\//\\\\\_______ +______\//\\\______/\\\___\/\\\___\///____\///////\\\____/\\\\\\\\\\___\/\\\_\//\\\/\\\__\/\\\___/\\\___________/\\\\\\\\\\\_____\//\\\_______ +________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\//\\\\\\__\/\\\__\//\\\_________\//\\///////_______\///_______ +____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ +______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ What is your name? -Hello James Gosling +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Hello James Gosling! + Welcome to OrgaNice! To start, enter "event" to start + your event list! If you are in the mood to mug and you + want to start your study area list, enter "study" !If + you want to exit, enter "bye" ! +________________________________________________________________________________________________ + Please enter "event" to continue with your event list or + "study" to continue with your study area list. To leave, enter "bye". +________________________________________________________________________________________________ + Goodbye! Hope to see you again! + `````````````````````````````````````````````````````````` + ````````````````````````````````:v(v'````````````````````` + ```````````````````````````,)4|ex` `L}```````````````````` + `````````````````````````!s"'h `M: ^z_;)T``````````````` + `````````````````````````Z u|}Z: "}`````````````` + ``````````````````````:=?) 'B?L'``````````` + `````````````````````'Z ;Yp"``````````` + `````````````````````.e ?_``````````` + ```````````````````'QDGH .5```````````` + ````````````````````I#g' '_` ||```````````` + ```````````:mX_``````YhL` `'q!` ? h```````````` + ```````````'Qbs)|L=_V" 'Y} ^'q@&b=c=_` ,Z```````````` + ````````````q> 'T, ,o" ;"@c. .sVx~````````````` + ````````````c! "bh` `,p z:`````````````` + `````````````q. ngDQmh8s X'`````````````` + ``````````````LY" :n}>``b; _V``````````````` + ````````````````q?, ?; "V```````````````` + ``````````````KvR ' )x_````````````````` + ``````````````zjL GLY"``````````````````` + ```````````````M .I)`````````````````````` + ```````````````Lz `D:`````````````````````` + ``````````````vu` (I)_;"". P.````````````````````` + ``````````````p :X.':^,"=n "q`````````````````````` + `````````````)0X?^:)I````````m' :j`````````````````````` + `````````````.IGD8k'`````````<&G55M``````````````````````` + `````````````````````````````````````````````````````````` diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 892cb6cae..24b4bf48b 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,9 +1,50 @@ +library\locations.txt (The system cannot find the file specified) Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +_______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ +______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ +_____/\\\/__\///\\\____________________/\\\\\\\\___________________\/\\\/\\\__\/\\\___/\\\__________________________________/\\\\\\\\\_______ +_____/\\\______\//\\\___/\\/\\\\\\\____/\\\////\\\___/\\\\\\\\\_____\/\\\//\\\_\/\\\__\///_______/\\\\\\\\______/\\\\\\\\___\//\\\\\\\_______ +_____\/\\\_______\/\\\__\/\\\/////\\\__\//\\\\\\\\\__\////////\\\____\/\\\\//\\\\/\\\___/\\\____/\\\//////_____/\\\/////\\\___\//\\\\\_______ +______\//\\\______/\\\___\/\\\___\///____\///////\\\____/\\\\\\\\\\___\/\\\_\//\\\/\\\__\/\\\___/\\\___________/\\\\\\\\\\\_____\//\\\_______ +________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\//\\\\\\__\/\\\__\//\\\_________\//\\///////_______\///_______ +____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ +______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ What is your name? -Hello James Gosling +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Hello James Gosling! + Welcome to OrgaNice! To start, enter "event" to start + your event list! If you are in the mood to mug and you + want to start your study area list, enter "study" !If + you want to exit, enter "bye" ! +________________________________________________________________________________________________ + Please enter "event" to continue with your event list or + "study" to continue with your study area list. To leave, enter "bye". +________________________________________________________________________________________________ + Goodbye! Hope to see you again! + `````````````````````````````````````````````````````````` + ````````````````````````````````:v(v'````````````````````` + ```````````````````````````,)4|ex` `L}```````````````````` + `````````````````````````!s"'h `M: ^z_;)T``````````````` + `````````````````````````Z u|}Z: "}`````````````` + ``````````````````````:=?) 'B?L'``````````` + `````````````````````'Z ;Yp"``````````` + `````````````````````.e ?_``````````` + ```````````````````'QDGH .5```````````` + ````````````````````I#g' '_` ||```````````` + ```````````:mX_``````YhL` `'q!` ? h```````````` + ```````````'Qbs)|L=_V" 'Y} ^'q@&b=c=_` ,Z```````````` + ````````````q> 'T, ,o" ;"@c. .sVx~````````````` + ````````````c! "bh` `,p z:`````````````` + `````````````q. ngDQmh8s X'`````````````` + ``````````````LY" :n}>``b; _V``````````````` + ````````````````q?, ?; "V```````````````` + ``````````````KvR ' )x_````````````````` + ``````````````zjL GLY"``````````````````` + ```````````````M .I)`````````````````````` + ```````````````Lz `D:`````````````````````` + ``````````````vu` (I)_;"". P.````````````````````` + ``````````````p :X.':^,"=n "q`````````````````````` + `````````````)0X?^:)I````````m' :j`````````````````````` + `````````````.IGD8k'`````````<&G55M``````````````````````` + `````````````````````````````````````````````````````````` diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index f6ec2e9f9..1329553ca 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1 +1,2 @@ -James Gosling \ No newline at end of file +James Gosling +bye \ No newline at end of file diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 8d94369a0..64c6a2c6f 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -3,6 +3,9 @@ # change to script directory cd "${0%/*}" + + + cd .. ./gradlew shadowJar From 174a07bc5fffa2b640ae254d79103c0e9e3483ed Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Wed, 11 Mar 2020 00:04:28 +0800 Subject: [PATCH 053/435] Rectify issue with runtest.sh --- src/main/java/seedu/duke/Duke.java | 3 +-- text-ui-test/ACTUAL.TXT | 1 - text-ui-test/EXPECTED.TXT | 1 - text-ui-test/library/eventList.txt | 0 text-ui-test/library/locations.txt | 8 ++++++++ text-ui-test/runtest.sh | 5 ++--- 6 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 text-ui-test/library/eventList.txt create mode 100644 text-ui-test/library/locations.txt diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 189f026ed..b49c23810 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -39,8 +39,7 @@ public Duke() { studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); } catch (FileNotFoundException | IllegalStudyAreaException e) { - Ui ui = new Ui(); - ui.printMessage(e.getMessage()); + // Handle issue later } } diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 24b4bf48b..6c9d82ed6 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -1,4 +1,3 @@ -library\locations.txt (The system cannot find the file specified) Hello from _______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ ______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 24b4bf48b..6c9d82ed6 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,4 +1,3 @@ -library\locations.txt (The system cannot find the file specified) Hello from _______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ ______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ diff --git a/text-ui-test/library/eventList.txt b/text-ui-test/library/eventList.txt new file mode 100644 index 000000000..e69de29bb diff --git a/text-ui-test/library/locations.txt b/text-ui-test/library/locations.txt new file mode 100644 index 000000000..42de138ad --- /dev/null +++ b/text-ui-test/library/locations.txt @@ -0,0 +1,8 @@ +MacCommons~2 College Ave West Education Resource Centre~Utown~true~true~5 +OCBC~2 College Ave West, Stephen Riady Centre~Utown~true~false~2 +EA Level 3~9 Engineering Drive 1,EA~Engineering~true~true~4 +EA Level 2~9 Engineering Drive 1~Engineering~true~true~4 +EA Level 1~9 Engineering Drive 1~Engineering~true~true~4 +EA Level 4~9 Engineering Drive 1, Outside Staff Offices~Engineering~true~false~6 +EA Level 5~9 Engineering Drive 1, Outside of the door beside EA05~Engineering~true~false~4 +EA Level 6~9 Engineering Drive 1, EA06-23~Engineering~true~true~4 \ No newline at end of file diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 64c6a2c6f..230bef79e 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -3,12 +3,11 @@ # change to script directory cd "${0%/*}" - - - cd .. ./gradlew shadowJar + + cd text-ui-test java -jar $(find ../build/libs/ -mindepth 1 -print -quit) < input.txt > ACTUAL.TXT From 64d934b6dd6d3510f6a4615677c9730be9a27bc4 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Wed, 11 Mar 2020 00:17:23 +0800 Subject: [PATCH 054/435] Remove Driver.java --- src/main/java/driver/Driver.java | 46 ------------------------------ src/main/java/seedu/duke/Duke.java | 4 --- 2 files changed, 50 deletions(-) delete mode 100644 src/main/java/driver/Driver.java diff --git a/src/main/java/driver/Driver.java b/src/main/java/driver/Driver.java deleted file mode 100644 index 5e19f9b91..000000000 --- a/src/main/java/driver/Driver.java +++ /dev/null @@ -1,46 +0,0 @@ -package driver; - -import command.EventCommand; -import event.EventList; -import java.io.FileNotFoundException; - -import parser.Parser; -import resourceloader.EventLoader; -import resourceloader.StudyAreaLoader; -import studyarea.IllegalStudyAreaException; -import command.StudyAreaCommand; -import studyarea.StudyAreaList; -import ui.Ui; - -public class Driver { - public static EventLoader eventLoader; - public static StudyAreaLoader studyAreaLoader; - - /** - * Constructor for Driver Class. - * This class setups the loading of events and study areas into - * the program and runs either study area or organiser functionality. - * - * @param mode 1 for organiser, 0 for study area. - * @param ui Object used to interact with user. - * @param parser Object used to parse user commands. - * @throws FileNotFoundException if file is not found. - * @throws IllegalStudyAreaException custom exception for study area. - */ - public Driver(int mode, Ui ui, Parser parser) throws FileNotFoundException, IllegalStudyAreaException { - eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); - EventList eventList = new EventList(eventLoader.loadFile()); - - studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); - StudyAreaList studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); - - if (mode == 1) { - EventCommand eventCommand = new EventCommand(); - eventCommand.runCommands(eventList, ui, parser); - eventLoader.saveEvents(eventList.events); - } else { - StudyAreaCommand studyAreaCommand = new StudyAreaCommand(); - studyAreaCommand.runCommands(studyAreaList, ui); - } - } -} diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index b49c23810..c3857b6c7 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,6 +1,5 @@ package seedu.duke; -import driver.Driver; import event.EventList; import parser.Parser; import command.EventCommand; @@ -12,9 +11,6 @@ import ui.Ui; import java.io.FileNotFoundException; -import java.util.InputMismatchException; -import java.util.Scanner; - /** * This is Duke class, which forms the main class of the program. From a7bfb7b7ed1520c9946fa82a2b431469444beb41 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Wed, 11 Mar 2020 00:31:52 +0800 Subject: [PATCH 055/435] Create Command and Parser Class (#46) * Refactor code to separate parser and command classes * Add help command support to EventList * Rectify issues * Rectify issue with text-ui-test * Rectify issue with runtest.sh * Remove Driver.java Co-authored-by: GanapathySanathBalaji --- src/main/java/command/AddCommand.java | 40 ++++++ src/main/java/command/ClearCommand.java | 27 ++++ src/main/java/command/Command.java | 22 +++ src/main/java/command/CountdownCommand.java | 27 ++++ src/main/java/command/DeleteCommand.java | 37 +++++ src/main/java/command/EventCommand.java | 79 ++++------- src/main/java/command/HelpCommand.java | 27 ++++ .../java/command/PriorityViewCommand.java | 27 ++++ src/main/java/command/SearchCommand.java | 32 +++++ src/main/java/command/ViewCommand.java | 27 ++++ src/main/java/event/Event.java | 4 +- src/main/java/event/EventList.java | 50 +++++++ src/main/java/parser/Parser.java | 78 +++++++++++ src/main/java/resourceloader/EventLoader.java | 1 - src/main/java/seedu/duke/Duke.java | 25 ++-- src/main/java/studyarea/StudyArea.java | 2 +- src/main/java/ui/Ui.java | 130 +++++++----------- text-ui-test/ACTUAL.TXT | 54 +++++++- text-ui-test/EXPECTED.TXT | 54 +++++++- text-ui-test/input.txt | 3 +- text-ui-test/library/eventList.txt | 0 text-ui-test/library/locations.txt | 8 ++ text-ui-test/runtest.sh | 2 + 23 files changed, 594 insertions(+), 162 deletions(-) create mode 100644 src/main/java/command/AddCommand.java create mode 100644 src/main/java/command/ClearCommand.java create mode 100644 src/main/java/command/Command.java create mode 100644 src/main/java/command/CountdownCommand.java create mode 100644 src/main/java/command/DeleteCommand.java create mode 100644 src/main/java/command/HelpCommand.java create mode 100644 src/main/java/command/PriorityViewCommand.java create mode 100644 src/main/java/command/SearchCommand.java create mode 100644 src/main/java/command/ViewCommand.java create mode 100644 src/main/java/parser/Parser.java create mode 100644 text-ui-test/library/eventList.txt create mode 100644 text-ui-test/library/locations.txt diff --git a/src/main/java/command/AddCommand.java b/src/main/java/command/AddCommand.java new file mode 100644 index 000000000..4c336e7fb --- /dev/null +++ b/src/main/java/command/AddCommand.java @@ -0,0 +1,40 @@ +package command; + +import event.Event; +import event.EventList; + +/** + * This command is used to add new events to the event list. + */ +public class AddCommand extends Command { + + /** The new event to be added. */ + Event newEvent; + + /** + * Constructor for the AddCommand Object. + * Abstracts out the details from the user input and uses it to create a new event object. + * + * @param eventDetails The array contains the information regarding the new event to be added. + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used to create an event. + */ + public AddCommand(String[] eventDetails, boolean isOneWordCommand) throws Exception { + if (isOneWordCommand) { + throw new Exception("Wrong format used to add an event"); + } + String[] details = eventDetails[1].split("/"); + String description = details[0]; + String date = details[1].substring(2); + String startTime = details[2].substring(2); + String endTime = details[3].substring(2); + String priority = details[4].substring(2); + newEvent = new Event(description,date,startTime,endTime,priority); + } + + @Override + public void executeCommand(EventList eventList) { + eventList.addEvent(newEvent, ui); + } + +} diff --git a/src/main/java/command/ClearCommand.java b/src/main/java/command/ClearCommand.java new file mode 100644 index 000000000..fde3dafe1 --- /dev/null +++ b/src/main/java/command/ClearCommand.java @@ -0,0 +1,27 @@ +package command; + +import event.EventList; + +/** + * This command is used to clear all the events in the list. + */ +public class ClearCommand extends Command { + + /** + * Constructor for the ClearCommand Object. + * Checks if the user given input follows the correct format. + * + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public ClearCommand(boolean isOneWordCommand) throws Exception { + if (!isOneWordCommand) { + throw new Exception("Wrong command clear events (Should be :clear )"); + } + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.clearEvents(ui); + } +} diff --git a/src/main/java/command/Command.java b/src/main/java/command/Command.java new file mode 100644 index 000000000..e6f06af11 --- /dev/null +++ b/src/main/java/command/Command.java @@ -0,0 +1,22 @@ +package command; + +import event.EventList; +import ui.Ui; + +/** + * Object represents a command and contains all the required information and implementation to execute it. + */ +public abstract class Command { + + /** Object used to handle user interactions. */ + Ui ui = new Ui(); + + /** + * Executes the command based on the information provided by the user. + * + * @param eventList Contains the list of tasks on which the commands are executed on. + * @throws Exception If issues are found during execution of command. + */ + public abstract void executeCommand(EventList eventList) throws Exception; + +} diff --git a/src/main/java/command/CountdownCommand.java b/src/main/java/command/CountdownCommand.java new file mode 100644 index 000000000..6f8be411a --- /dev/null +++ b/src/main/java/command/CountdownCommand.java @@ -0,0 +1,27 @@ +package command; + +import event.EventList; + +/** + * Displays the list of events added so far in increasing order of their dates. + */ +public class CountdownCommand extends Command { + + /** + * Constructor for the CountdownCommand Object. + * Creates a new object if the correct format is used. + * + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public CountdownCommand(boolean isOneWordCommand) throws Exception { + if (!isOneWordCommand) { + throw new Exception("Wrong command used to view countdown of events (Should be :countdown )"); + } + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.countdownView(ui); + } +} diff --git a/src/main/java/command/DeleteCommand.java b/src/main/java/command/DeleteCommand.java new file mode 100644 index 000000000..a24b9ba68 --- /dev/null +++ b/src/main/java/command/DeleteCommand.java @@ -0,0 +1,37 @@ +package command; + +import event.EventList; + +/** + * Command is used to delete an event at a specific index. + */ +public class DeleteCommand extends Command { + + /** Denotes the index at which the event should be deleted at. */ + int indexToDelete; + + /** + * Constructor for the DeleteCommand object. + * Creates a new object if the correct command is used. + * + * @param commandSplit Contains information with regards to the index to be deleted at. + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the index specified is invalid/ The wrong format is used for the command. + */ + public DeleteCommand(String[] commandSplit, boolean isOneWordCommand) throws Exception { + if (isOneWordCommand) { + throw new Exception("Index to delete not mentioned"); + } + try { + indexToDelete = Integer.parseInt(commandSplit[1]); + } catch (NumberFormatException e) { + throw new Exception("Enter a valid index (1-based) to delete the corresponding event"); + } + } + + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.deleteEvent(indexToDelete, ui); + } +} diff --git a/src/main/java/command/EventCommand.java b/src/main/java/command/EventCommand.java index 199ac186a..56168d99d 100644 --- a/src/main/java/command/EventCommand.java +++ b/src/main/java/command/EventCommand.java @@ -1,66 +1,45 @@ package command; import event.EventList; -import resourceloader.EventLoader; +import parser.Parser; import ui.Ui; import java.util.Scanner; +import static ui.Ui.BYE_COMMAND; + +/** + * Used to run all the functions related to events. + */ public class EventCommand { /** - * Commands for Events. + * Runs all the command for events. * - * @param eventList this is the evenList. - * @param ui allows for interaction with the User. - * @param eventLoader allows for saving of data after every execution of commands. + * @param eventList Refers to the current list of events. + * @param ui UI object used to interact with user. + * @param parser Object used to parse the user input into commands. */ - public static void runCommands(EventList eventList, Ui ui, EventLoader eventLoader) { - Scanner in = new Scanner(System.in); - String command; - ui.printLine(); - command = in.nextLine(); - while (!command.equals(Ui.BYE_COMMAND)) { - ui.printLine(); + public static void runCommands(EventList eventList, Ui ui, Parser parser) { + eventList.printHelp(); + Scanner sc = new Scanner(System.in); + String fullCommand; + Command command; + + fullCommand = sc.nextLine(); + while (!fullCommand.equals(BYE_COMMAND)) { try { - String commandType = command.split(" ")[0]; - switch (commandType) { - case Ui.ADD_COMMAND: - eventList.add(command, ui); - break; - case Ui.VIEW_COMMAND: - eventList.listEvents(ui); - break; - case Ui.PRIORITY_VIEW_COMMAND: - eventList.priorityView(ui); - break; - case Ui.COUNTDOWN_VIEW_COMMAND: - eventList.countdownView(ui); - break; - case Ui.CLEAR_COMMAND: - eventList.clearEvents(ui); - break; - case Ui.SEARCH_COMMAND: - eventList.searchEvents(command.split(" ", 2)[1], ui); - break; - case Ui.DELETE_COMMAND: - eventList.deleteEvent(Integer.parseInt(command.split(" ", 2)[1]), ui); - break; - default: - ui.printMessage(Ui.INVALID_COMMAND_MESSAGE); - break; - } - } catch (NumberFormatException e) { - ui.printMessage(Ui.INVALID_INDEX_MESSAGE); - } catch (IndexOutOfBoundsException e) { - ui.printMessage(Ui.INVALID_COMMAND_MESSAGE); + command = parser.parseCommand(fullCommand, ui); + command.executeCommand(eventList); + } catch (Exception exception) { + ui.printLine(); + ui.printWithIndentation(exception.getMessage()); + ui.printLine(); } - ui.printLine(); - eventLoader.saveEvents(eventList.events); - command = in.nextLine(); + ui.printEmptyLine(); + fullCommand = sc.nextLine(); } - ui.printLine(); - ui.printMessage(Ui.BYE_MESSAGE); - ui.printLine(); + ui.printByeMessage(); } -} \ No newline at end of file + +} diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java new file mode 100644 index 000000000..bb2536e3a --- /dev/null +++ b/src/main/java/command/HelpCommand.java @@ -0,0 +1,27 @@ +package command; + +import event.EventList; + +/** + * Command is used to print the list of commands supported. + */ +public class HelpCommand extends Command { + + /** + * Constructor for the HelpCommand object. + * Creates a new object if the correct format is used. + * + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public HelpCommand(boolean isOneWordCommand) throws Exception { + if (!isOneWordCommand) { + throw new Exception("Wrong command used to view command list (Should be :help )"); + } + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.printHelp(); + } +} diff --git a/src/main/java/command/PriorityViewCommand.java b/src/main/java/command/PriorityViewCommand.java new file mode 100644 index 000000000..136be94c4 --- /dev/null +++ b/src/main/java/command/PriorityViewCommand.java @@ -0,0 +1,27 @@ +package command; + +import event.EventList; + +/** + * Displays the list of events added so far in decreasing order of their priority. + */ +public class PriorityViewCommand extends Command { + + /** + * Constructor for the PriorityViewCommand Object. + * Creates a new object if the correct format is used. + * + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public PriorityViewCommand(boolean isOneWordCommand) throws Exception { + if (!isOneWordCommand) { + throw new Exception("Wrong command used to view events sorted by priority (Should be :priority_view )"); + } + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.priorityView(ui); + } +} diff --git a/src/main/java/command/SearchCommand.java b/src/main/java/command/SearchCommand.java new file mode 100644 index 000000000..04f9c7b5b --- /dev/null +++ b/src/main/java/command/SearchCommand.java @@ -0,0 +1,32 @@ +package command; + +import event.EventList; + +/** + * Command used to perform a search of events whose description contain the keyword mentioned. + */ +public class SearchCommand extends Command { + + /** The word to be searched for. */ + String keyword; + + /** + * Constructor for SearchCommand object. + * Creates a new object if the correct format is used. + * + * @param commandSplit Contains the keyword to be searched for. + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public SearchCommand(String[] commandSplit, boolean isOneWordCommand) throws Exception { + if (isOneWordCommand) { + throw new Exception("The search string entered is empty."); + } + this.keyword = commandSplit[1]; + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.searchEvents(keyword, ui); + } +} diff --git a/src/main/java/command/ViewCommand.java b/src/main/java/command/ViewCommand.java new file mode 100644 index 000000000..bbac39f84 --- /dev/null +++ b/src/main/java/command/ViewCommand.java @@ -0,0 +1,27 @@ +package command; + +import event.EventList; + +/** + * Displays the list of events added so far. + */ +public class ViewCommand extends Command { + + /** + * Constructor for the ViewCommand Object. + * Creates a new object if the correct format is used. + * + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used. + */ + public ViewCommand(boolean isOneWordCommand) throws Exception { + if (!isOneWordCommand) { + throw new Exception("Wrong command used to view events (Should be :view )"); + } + } + + @Override + public void executeCommand(EventList eventList) throws Exception { + eventList.listEvents(ui); + } +} diff --git a/src/main/java/event/Event.java b/src/main/java/event/Event.java index 1ea721c29..48cce8932 100644 --- a/src/main/java/event/Event.java +++ b/src/main/java/event/Event.java @@ -112,7 +112,7 @@ public LocalDate getDate() { * * @param keyword The keyword to be matched with the description. * @return containsKeyword Indicates the presence/absence of keyword in the event's description. - * @throws Exception to be edited + * @throws Exception If keyword entered is empty. */ public boolean hasKeyword(String keyword) throws Exception { if (keyword.equals("")) { @@ -131,4 +131,4 @@ public String getFormattedDetails() { String formattedEventDetails = description + "#" + date + "#" + startTime + "#" + endTime + "#" + priority; return formattedEventDetails; } -} \ No newline at end of file +} diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index de936b110..617145c83 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -34,8 +34,10 @@ public EventList(ArrayList events) { */ public void addEvent(Event newEvent, Ui ui) { events.add(newEvent); + ui.printLine(); ui.printMessage("A new event with the following information has been added."); ui.printMessage(newEvent.getEventInformation()); + ui.printLine(); } /** @@ -44,12 +46,14 @@ public void addEvent(Event newEvent, Ui ui) { * @param ui This allows Event List class to interact with User. */ public void listEvents(Ui ui) { + ui.printLine(); ui.printMessage("Here is the list of events added so far:"); int eventNumber = 1; for (Event event: events) { ui.printMessage(eventNumber + ") " + event.getEventInformation()); eventNumber++; } + ui.printLine(); } /** @@ -59,11 +63,14 @@ public void listEvents(Ui ui) { * @param index The index (1-based) of the event to be deleted. */ public void deleteEvent(int index, Ui ui) { + ui.printLine(); try { events.remove(index - 1); ui.printMessage("The event at the mentioned index has been deleted"); + ui.printLine(); } catch (IndexOutOfBoundsException e) { ui.printMessage("Enter a valid index"); + ui.printLine(); } } @@ -75,7 +82,9 @@ public void deleteEvent(int index, Ui ui) { */ public void clearEvents(Ui ui) { events.clear(); + ui.printLine(); ui.printMessage("The list of events is cleared."); + ui.printLine(); } /** @@ -87,6 +96,7 @@ public void priorityView(Ui ui) { ArrayList eventsSortedByPriority = events; eventsSortedByPriority.sort(Comparator.comparingInt(Event::getPriority)); Collections.reverse(eventsSortedByPriority); + ui.printLine(); int eventNumber = 1; for (Event event:eventsSortedByPriority) { ui.printMessage(eventNumber + ") " + event.getEventInformation()); @@ -95,6 +105,7 @@ public void priorityView(Ui ui) { if (eventNumber == 1) { ui.printMessage("The list is empty."); } + ui.printLine(); } /** @@ -105,6 +116,7 @@ public void priorityView(Ui ui) { public void countdownView(Ui ui) { ArrayList eventsSortedByDate = events; eventsSortedByDate.sort(Comparator.comparing(Event::getDate)); + ui.printLine(); int eventNumber = 1; for (Event event:eventsSortedByDate) { ui.printMessage(eventNumber + ") " + event.getEventInformation()); @@ -113,6 +125,7 @@ public void countdownView(Ui ui) { if (eventNumber == 1) { ui.printMessage("The list is empty."); } + ui.printLine(); } /** @@ -123,6 +136,7 @@ public void countdownView(Ui ui) { */ public void searchEvents(String keyword, Ui ui) { int eventNumber = 1; + ui.printLine(); for (Event event:events) { try { if (event.hasKeyword(keyword)) { @@ -136,6 +150,7 @@ public void searchEvents(String keyword, Ui ui) { if (eventNumber == 1) { ui.printMessage("The list is empty."); } + ui.printLine(); } /** @@ -157,9 +172,44 @@ public void add(String eventDetails, Ui ui) { Event newEvent = new Event(description,date,startTime,endTime,priority); addEvent(newEvent, ui); } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { + ui.printLine(); ui.printMessage("Wrong format to add events"); + ui.printLine(); } catch (Exception e) { + ui.printLine(); ui.printMessage(e.getMessage()); + ui.printLine(); } } + + /** + * Display the list of supported commands. + */ + public void printHelp() { + Ui ui = new Ui(); + ui.printLine(); + ui.printWithIndentation("OrgaNice! Supports the following commands"); + ui.printWithIndentation("Please enter the keywords followed by the information shown in the brackets"); + ui.printWithIndentation("add /d /s /e /p "); + ui.printWithIndentation("------------------------------------------- Create a new event"); + ui.printWithIndentation("view -------------------------------------- View existing events"); + ui.printWithIndentation("priority_view ----------------------------- View existing events based " + + "on priority"); + ui.printWithIndentation("countdown --------------------------------- View existing events based on" + + " days left"); + ui.printWithIndentation("clear ------------------------------------- Delete all events"); + ui.printWithIndentation("search ----------- View existing events that contains " + + "the keyword"); + ui.printWithIndentation("delete ------------ Delete the event"); + ui.printWithIndentation("help -------------------------------------- View List Of Commands Supported"); + ui.printWithIndentation("bye --------------------------------------- Terminate program"); + ui.printWithIndentation("Notes:"); + ui.printWithIndentation("*All dates should follow YYYY-MM-DD format"); + ui.printWithIndentation("*All timing should follow 24 hour clock"); + ui.printWithIndentation("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " + + "least urgent"); + ui.printLine(); + } + } \ No newline at end of file diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java new file mode 100644 index 000000000..4b370a34e --- /dev/null +++ b/src/main/java/parser/Parser.java @@ -0,0 +1,78 @@ +package parser; + +import command.AddCommand; +import command.ClearCommand; +import command.Command; +import command.CountdownCommand; +import command.DeleteCommand; +import command.HelpCommand; +import command.PriorityViewCommand; +import command.SearchCommand; +import command.ViewCommand; +import ui.Ui; + +/** + * This class is used to parse the user input into executable commands. + */ +public class Parser { + + public static final String ADD_COMMAND = "add"; + public static final String VIEW_COMMAND = "view"; + public static final String PRIORITY_VIEW_COMMAND = "priority_view"; + public static final String COUNTDOWN_VIEW_COMMAND = "countdown"; + public static final String CLEAR_COMMAND = "clear"; + public static final String SEARCH_COMMAND = "search"; + public static final String DELETE_COMMAND = "delete"; + public static final String EMPTY_COMMAND = ""; + public static final String HELP_COMMAND = "help"; + + /** + * This method takes in the user input parses it and returns the command to be executed. + * + * @param fullCommand THe entire line of command entered by the user. + * @param ui Object used to handle interactions with user. + * @return command The command parsed form the user input. + * @throws Exception If the wrong command/ wrong format is given by the user as an input. + */ + public Command parseCommand(String fullCommand, Ui ui) throws Exception { + + String[] commandSplit = fullCommand.split(" ",2); + String commandType = commandSplit[0]; + Command command; + boolean isOneWordCommand = commandSplit.length == 1 || commandSplit[1].isBlank(); + switch (commandType) { + case ADD_COMMAND: + command = new AddCommand(commandSplit, isOneWordCommand); + break; + case VIEW_COMMAND: + command = new ViewCommand(isOneWordCommand); + break; + case PRIORITY_VIEW_COMMAND: + command = new PriorityViewCommand(isOneWordCommand); + break; + case COUNTDOWN_VIEW_COMMAND: + command = new CountdownCommand(isOneWordCommand); + break; + case CLEAR_COMMAND: + command = new ClearCommand(isOneWordCommand); + break; + case SEARCH_COMMAND: + command = new SearchCommand(commandSplit, isOneWordCommand); + break; + case DELETE_COMMAND: + command = new DeleteCommand(commandSplit, isOneWordCommand); + break; + case HELP_COMMAND: + command = new HelpCommand(isOneWordCommand); + break; + case EMPTY_COMMAND: + throw new Exception("Empty Line entered, Please enter a valid line"); + // Break statement can't be reached if added + default: + throw new Exception("Invalid command entered, Please enter a valid command"); + // Break statement can't be reached if added + } + return command; + } + +} diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java index bd71727ca..30ecc2a98 100644 --- a/src/main/java/resourceloader/EventLoader.java +++ b/src/main/java/resourceloader/EventLoader.java @@ -85,7 +85,6 @@ private Event parseEventDetails(String taskDescription) throws Exception { * Creates a new data file when the application is run for the first time. */ private void createNewDataFile() { - try { Files.createDirectories(fileDirectory); Files.createFile(Paths.get(filePath)); diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 3388c1a8f..c3857b6c7 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,8 +1,9 @@ package seedu.duke; +import event.EventList; +import parser.Parser; import command.EventCommand; import command.StudyAreaCommand; -import event.EventList; import resourceloader.EventLoader; import resourceloader.StudyAreaLoader; import studyarea.IllegalStudyAreaException; @@ -10,28 +11,31 @@ import ui.Ui; import java.io.FileNotFoundException; + /** * This is Duke class, which forms the main class of the program. */ public class Duke { private static EventLoader eventLoader; protected static StudyAreaLoader studyAreaLoader; - private static EventList eventList; + private static EventList eventList = new EventList(); private static StudyAreaList studyAreaList; + private static Ui ui; + private static Parser parser; /** * This is the constructor to create a new Duke program every time user runs the main loop. */ public Duke() { try { + ui = new Ui(); + parser = new Parser(); eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); eventList = new EventList(eventLoader.loadFile()); studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); } catch (FileNotFoundException | IllegalStudyAreaException e) { - Ui ui = new Ui(); - ui.printMessage(e.getMessage()); - ui.close(); + // Handle issue later } } @@ -39,7 +43,6 @@ public Duke() { * This method runs the program. */ public void run() { - Ui ui = new Ui(); ui.printWelcomeMessage(); boolean status = true; while (status) { @@ -49,8 +52,7 @@ public void run() { status = false; break; case 1: - EventCommand.runCommands(eventList, ui, eventLoader); - eventLoader.saveEvents(eventList.events); + EventCommand.runCommands(eventList, ui, parser); break; case 2: StudyAreaCommand.runCommands(studyAreaList, ui); @@ -60,18 +62,21 @@ public void run() { ui.printMessage(Ui.WRONG_INPUT); break; } - ui.printMessage(Ui.INTERMEDIATE_MESSAGE); + ui.printWithIndentation(Ui.INTERMEDIATE_MESSAGE); ui.printLine(); } + eventLoader.saveEvents(eventList.events); ui.printMessage(Ui.GOODBYE_MESSAGE + Ui.DAB); ui.close(); } /** * Main entry-point for the java.duke.Duke application. + * * @param args this is an optional argument. */ public static void main(String[] args) { new Duke().run(); } -} \ No newline at end of file + +} diff --git a/src/main/java/studyarea/StudyArea.java b/src/main/java/studyarea/StudyArea.java index 803254261..d790c887d 100644 --- a/src/main/java/studyarea/StudyArea.java +++ b/src/main/java/studyarea/StudyArea.java @@ -32,7 +32,7 @@ public class StudyArea { public StudyArea(String name, String address, String faculty, boolean hasPort, boolean isIndoor, int maxPax) { this.name = name; - this.address = Ui.formatMessage(address, Ui.ADDRESS_MAX_LENGTH).trim(); + this.address = address.trim(); this.faculty = faculty; this.hasPort = hasPort; this.isIndoor = isIndoor; diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 5e587cbaf..2fdc456b4 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -18,15 +18,6 @@ public class Ui { public static final String FILE_PATH_EVENTS = "library" + File.separator + "eventList.txt"; public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; - public static final String ADD_COMMAND = "add"; - public static final String VIEW_COMMAND = "view"; - public static final String PRIORITY_VIEW_COMMAND = "priority_view"; - public static final String COUNTDOWN_VIEW_COMMAND = "countdown"; - public static final String CLEAR_COMMAND = "clear"; - public static final String SEARCH_COMMAND = "search"; - public static final String DELETE_COMMAND = "delete"; - public static final String INVALID_INDEX_MESSAGE = "Enter a valid index"; - public static final String INVALID_COMMAND_MESSAGE = "Enter a valid command"; public static final String BYE_COMMAND = "bye"; public static final String BYE_MESSAGE = "Bye!!!!!!"; public static final String LINE = "_______________________________________________________________________________" @@ -59,15 +50,16 @@ public class Ui { public static final String TAB = "\t "; public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; - public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"event\" to start your event" - + " list! If you are in the mood to mug and you want to start your study area list, enter \"study\" !" - + "If you want to exit, enter \"bye\" !"; + public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"event\" to start\n" + + " your event list! If you are in the mood to mug and you\n" + + " want to start your study area list, enter \"study\" !If\n" + + " you want to exit, enter \"bye\" !"; public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; public static final String EVENT_COMMAND = "event"; public static final String STUDY_COMMAND = "study"; - public static final String GOODBYE_MESSAGE = "Goodbye! Hope to see you again!"; - public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or" - + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; + public static final String GOODBYE_MESSAGE = " Goodbye! Hope to see you again!"; + public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or\n" + + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; public static final String EMPTY_LOCATION = "Location entered is empty! Please type a location to search for " + "StudyAreas!"; @@ -157,16 +149,33 @@ public void close() { } /** - * This method allows other classes to print messages to interact with User. + * Prints a line made up of '_'. + */ + public void printLine() { + System.out.println("_________________________________________________________________________________" + + "_______________"); + } + + /** + * Prints the user given line with an indentation. + * + * @param line The line to be printed. + */ + public void printWithIndentation(String line) { + System.out.println(" " + line); + } + + /** + * This method ensures that the message printed is within the standard length. * - * @param message This is the message that is intended to be printed to Users. + * @param message is the String that we intend to format to a standard length per line. */ public void printMessage(String message) { if (message.equals(GOODBYE_MESSAGE + DAB)) { - this.out.println(formatMessage(GOODBYE_MESSAGE, MAX_LINE_LENGTH)); + this.out.println(GOODBYE_MESSAGE); this.out.println(DAB); } else { - this.out.println(formatMessage(message, MAX_LINE_LENGTH)); + this.out.println(message); } } @@ -181,68 +190,7 @@ public void printStudyArea(StudyArea studyArea) { } /** - * Prints a line made up of '_'. - */ - public void printLine() { - System.out.println(LINE); - } - - /** - * This is a modification of a code from Stack Overflow to format strings into a standard length. Minor edition is - * made to ensure suitability with the program. - * This method ensures that the message printed is within the standard
- * length. - * @param message is the String that we intend to format to a standard length
- * per line.
- * @param maxLength This is the standard length intended to be formatted. - * @return String of standard length per line - */ - - //@@author NizarMohd-reused - //Reused from https://stackoverflow.com/questions/7528045/large-string-split-into-lines-with-maximum-length-in-java - // with minor modification. - public static String formatMessage(String message, int maxLength) { - StringTokenizer token = new StringTokenizer(message, SPACE); - StringBuilder standardLengthMessage = new StringBuilder(message.length()); - int lineLength = 0; - while (token.hasMoreTokens()) { - String word = token.nextToken(); - if (lineLength + word.length() > maxLength) { - standardLengthMessage.append("\n\t "); - lineLength = 0; - } - standardLengthMessage.append(word).append(SPACE); - lineLength += word.length() + 1; - } - return TAB + standardLengthMessage.toString().stripTrailing(); - } - //@@author - - /** - * Display the list of supported commands. - */ - public void printHelp() { - this.out.println("OrgaNice! Supports the following commands"); - this.out.println("Please enter the keywords followed by the information shown in the brackets"); - this.out.println("add /d /s /e /p "); - this.out.println("------------------------------------------- Create a new event"); - this.out.println("view -------------------------------------- View existing events"); - this.out.println("priority_view ----------------------------- View existing events based on priority"); - this.out.println("countdown --------------------------------- View existing events based on days left"); - this.out.println("clear ------------------------------------- Delete all events"); - this.out.println("search ----------- View existing events that contains " - + "the keyword"); - this.out.println("delete ------------ Delete the event"); - this.out.println("bye --------------------------------------- Terminate program"); - this.out.println("Notes:"); - this.out.println("*All dates should follow YYYY-MM-DD format"); - this.out.println("*All timing should follow 24 hour clock"); - this.out.println("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " - + "least urgent"); - } - - /** - * Prints the welcome message and starts interaction with user. + * Display welcome message. */ public void printWelcomeMessage() { @@ -280,7 +228,23 @@ public void printWelcomeMessage() { String name = this.in.nextLine(); printLine(); this.out.println(TAB + "Hello " + name + "!"); - this.out.println(formatMessage(START_MESSAGE, MAX_LINE_LENGTH)); + printWithIndentation(START_MESSAGE); + printLine(); + } + + /** + * Prints an empty line. + */ + public void printEmptyLine() { + System.out.println(); + } + + /** + * Prints the bye message. + */ + public void printByeMessage() { + printLine(); + printWithIndentation("Bye!!!!!"); printLine(); } -} \ No newline at end of file +} diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 892cb6cae..6c9d82ed6 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -1,9 +1,49 @@ Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +_______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ +______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ +_____/\\\/__\///\\\____________________/\\\\\\\\___________________\/\\\/\\\__\/\\\___/\\\__________________________________/\\\\\\\\\_______ +_____/\\\______\//\\\___/\\/\\\\\\\____/\\\////\\\___/\\\\\\\\\_____\/\\\//\\\_\/\\\__\///_______/\\\\\\\\______/\\\\\\\\___\//\\\\\\\_______ +_____\/\\\_______\/\\\__\/\\\/////\\\__\//\\\\\\\\\__\////////\\\____\/\\\\//\\\\/\\\___/\\\____/\\\//////_____/\\\/////\\\___\//\\\\\_______ +______\//\\\______/\\\___\/\\\___\///____\///////\\\____/\\\\\\\\\\___\/\\\_\//\\\/\\\__\/\\\___/\\\___________/\\\\\\\\\\\_____\//\\\_______ +________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\//\\\\\\__\/\\\__\//\\\_________\//\\///////_______\///_______ +____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ +______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ What is your name? -Hello James Gosling +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Hello James Gosling! + Welcome to OrgaNice! To start, enter "event" to start + your event list! If you are in the mood to mug and you + want to start your study area list, enter "study" !If + you want to exit, enter "bye" ! +________________________________________________________________________________________________ + Please enter "event" to continue with your event list or + "study" to continue with your study area list. To leave, enter "bye". +________________________________________________________________________________________________ + Goodbye! Hope to see you again! + `````````````````````````````````````````````````````````` + ````````````````````````````````:v(v'````````````````````` + ```````````````````````````,)4|ex` `L}```````````````````` + `````````````````````````!s"'h `M: ^z_;)T``````````````` + `````````````````````````Z u|}Z: "}`````````````` + ``````````````````````:=?) 'B?L'``````````` + `````````````````````'Z ;Yp"``````````` + `````````````````````.e ?_``````````` + ```````````````````'QDGH .5```````````` + ````````````````````I#g' '_` ||```````````` + ```````````:mX_``````YhL` `'q!` ? h```````````` + ```````````'Qbs)|L=_V" 'Y} ^'q@&b=c=_` ,Z```````````` + ````````````q> 'T, ,o" ;"@c. .sVx~````````````` + ````````````c! "bh` `,p z:`````````````` + `````````````q. ngDQmh8s X'`````````````` + ``````````````LY" :n}>``b; _V``````````````` + ````````````````q?, ?; "V```````````````` + ``````````````KvR ' )x_````````````````` + ``````````````zjL GLY"``````````````````` + ```````````````M .I)`````````````````````` + ```````````````Lz `D:`````````````````````` + ``````````````vu` (I)_;"". P.````````````````````` + ``````````````p :X.':^,"=n "q`````````````````````` + `````````````)0X?^:)I````````m' :j`````````````````````` + `````````````.IGD8k'`````````<&G55M``````````````````````` + `````````````````````````````````````````````````````````` diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 892cb6cae..6c9d82ed6 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,9 +1,49 @@ Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +_______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ +______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ +_____/\\\/__\///\\\____________________/\\\\\\\\___________________\/\\\/\\\__\/\\\___/\\\__________________________________/\\\\\\\\\_______ +_____/\\\______\//\\\___/\\/\\\\\\\____/\\\////\\\___/\\\\\\\\\_____\/\\\//\\\_\/\\\__\///_______/\\\\\\\\______/\\\\\\\\___\//\\\\\\\_______ +_____\/\\\_______\/\\\__\/\\\/////\\\__\//\\\\\\\\\__\////////\\\____\/\\\\//\\\\/\\\___/\\\____/\\\//////_____/\\\/////\\\___\//\\\\\_______ +______\//\\\______/\\\___\/\\\___\///____\///////\\\____/\\\\\\\\\\___\/\\\_\//\\\/\\\__\/\\\___/\\\___________/\\\\\\\\\\\_____\//\\\_______ +________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\//\\\\\\__\/\\\__\//\\\_________\//\\///////_______\///_______ +____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ +______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ What is your name? -Hello James Gosling +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Hello James Gosling! + Welcome to OrgaNice! To start, enter "event" to start + your event list! If you are in the mood to mug and you + want to start your study area list, enter "study" !If + you want to exit, enter "bye" ! +________________________________________________________________________________________________ + Please enter "event" to continue with your event list or + "study" to continue with your study area list. To leave, enter "bye". +________________________________________________________________________________________________ + Goodbye! Hope to see you again! + `````````````````````````````````````````````````````````` + ````````````````````````````````:v(v'````````````````````` + ```````````````````````````,)4|ex` `L}```````````````````` + `````````````````````````!s"'h `M: ^z_;)T``````````````` + `````````````````````````Z u|}Z: "}`````````````` + ``````````````````````:=?) 'B?L'``````````` + `````````````````````'Z ;Yp"``````````` + `````````````````````.e ?_``````````` + ```````````````````'QDGH .5```````````` + ````````````````````I#g' '_` ||```````````` + ```````````:mX_``````YhL` `'q!` ? h```````````` + ```````````'Qbs)|L=_V" 'Y} ^'q@&b=c=_` ,Z```````````` + ````````````q> 'T, ,o" ;"@c. .sVx~````````````` + ````````````c! "bh` `,p z:`````````````` + `````````````q. ngDQmh8s X'`````````````` + ``````````````LY" :n}>``b; _V``````````````` + ````````````````q?, ?; "V```````````````` + ``````````````KvR ' )x_````````````````` + ``````````````zjL GLY"``````````````````` + ```````````````M .I)`````````````````````` + ```````````````Lz `D:`````````````````````` + ``````````````vu` (I)_;"". P.````````````````````` + ``````````````p :X.':^,"=n "q`````````````````````` + `````````````)0X?^:)I````````m' :j`````````````````````` + `````````````.IGD8k'`````````<&G55M``````````````````````` + `````````````````````````````````````````````````````````` diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index f6ec2e9f9..1329553ca 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1 +1,2 @@ -James Gosling \ No newline at end of file +James Gosling +bye \ No newline at end of file diff --git a/text-ui-test/library/eventList.txt b/text-ui-test/library/eventList.txt new file mode 100644 index 000000000..e69de29bb diff --git a/text-ui-test/library/locations.txt b/text-ui-test/library/locations.txt new file mode 100644 index 000000000..42de138ad --- /dev/null +++ b/text-ui-test/library/locations.txt @@ -0,0 +1,8 @@ +MacCommons~2 College Ave West Education Resource Centre~Utown~true~true~5 +OCBC~2 College Ave West, Stephen Riady Centre~Utown~true~false~2 +EA Level 3~9 Engineering Drive 1,EA~Engineering~true~true~4 +EA Level 2~9 Engineering Drive 1~Engineering~true~true~4 +EA Level 1~9 Engineering Drive 1~Engineering~true~true~4 +EA Level 4~9 Engineering Drive 1, Outside Staff Offices~Engineering~true~false~6 +EA Level 5~9 Engineering Drive 1, Outside of the door beside EA05~Engineering~true~false~4 +EA Level 6~9 Engineering Drive 1, EA06-23~Engineering~true~true~4 \ No newline at end of file diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 8d94369a0..230bef79e 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -6,6 +6,8 @@ cd "${0%/*}" cd .. ./gradlew shadowJar + + cd text-ui-test java -jar $(find ../build/libs/ -mindepth 1 -print -quit) < input.txt > ACTUAL.TXT From cb5f1070335fb210fdfedc1eabf7881a0e11fca8 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Wed, 11 Mar 2020 19:08:36 +0800 Subject: [PATCH 056/435] Pull from Upstream and Add changes. --- src/main/java/command/AddCommand.java | 3 +- src/main/java/command/ClearCommand.java | 3 +- src/main/java/command/Command.java | 6 +- src/main/java/command/CountdownCommand.java | 3 +- src/main/java/command/DeleteCommand.java | 3 +- src/main/java/command/EventCommand.java | 22 ++-- src/main/java/command/HelpCommand.java | 5 +- .../java/command/PriorityViewCommand.java | 3 +- src/main/java/command/SearchCommand.java | 3 +- src/main/java/command/StudyAreaCommand.java | 2 +- src/main/java/command/ViewCommand.java | 3 +- src/main/java/event/EventList.java | 30 +---- src/main/java/parser/Parser.java | 4 +- src/main/java/seedu/duke/Duke.java | 10 +- src/main/java/studyarea/StudyAreaList.java | 113 +++++++++++++----- src/main/java/ui/Ui.java | 92 ++++++++++---- text-ui-test/ACTUAL.TXT | 20 ++-- text-ui-test/EXPECTED.TXT | 20 ++-- 18 files changed, 209 insertions(+), 136 deletions(-) diff --git a/src/main/java/command/AddCommand.java b/src/main/java/command/AddCommand.java index 4c336e7fb..90bd434c7 100644 --- a/src/main/java/command/AddCommand.java +++ b/src/main/java/command/AddCommand.java @@ -2,6 +2,7 @@ import event.Event; import event.EventList; +import ui.Ui; /** * This command is used to add new events to the event list. @@ -33,7 +34,7 @@ public AddCommand(String[] eventDetails, boolean isOneWordCommand) throws Except } @Override - public void executeCommand(EventList eventList) { + public void executeCommand(EventList eventList, Ui ui) { eventList.addEvent(newEvent, ui); } diff --git a/src/main/java/command/ClearCommand.java b/src/main/java/command/ClearCommand.java index fde3dafe1..82b6ae5a0 100644 --- a/src/main/java/command/ClearCommand.java +++ b/src/main/java/command/ClearCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import ui.Ui; /** * This command is used to clear all the events in the list. @@ -21,7 +22,7 @@ public ClearCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList) throws Exception { + public void executeCommand(EventList eventList, Ui ui) throws Exception { eventList.clearEvents(ui); } } diff --git a/src/main/java/command/Command.java b/src/main/java/command/Command.java index e6f06af11..1eb9f5f10 100644 --- a/src/main/java/command/Command.java +++ b/src/main/java/command/Command.java @@ -8,15 +8,13 @@ */ public abstract class Command { - /** Object used to handle user interactions. */ - Ui ui = new Ui(); - /** * Executes the command based on the information provided by the user. * * @param eventList Contains the list of tasks on which the commands are executed on. + * @param ui This handles the interaction with Users. * @throws Exception If issues are found during execution of command. */ - public abstract void executeCommand(EventList eventList) throws Exception; + public abstract void executeCommand(EventList eventList, Ui ui) throws Exception; } diff --git a/src/main/java/command/CountdownCommand.java b/src/main/java/command/CountdownCommand.java index 6f8be411a..97091ec66 100644 --- a/src/main/java/command/CountdownCommand.java +++ b/src/main/java/command/CountdownCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import ui.Ui; /** * Displays the list of events added so far in increasing order of their dates. @@ -21,7 +22,7 @@ public CountdownCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList) throws Exception { + public void executeCommand(EventList eventList, Ui ui) throws Exception { eventList.countdownView(ui); } } diff --git a/src/main/java/command/DeleteCommand.java b/src/main/java/command/DeleteCommand.java index a24b9ba68..b5e941fb7 100644 --- a/src/main/java/command/DeleteCommand.java +++ b/src/main/java/command/DeleteCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import ui.Ui; /** * Command is used to delete an event at a specific index. @@ -31,7 +32,7 @@ public DeleteCommand(String[] commandSplit, boolean isOneWordCommand) throws Exc @Override - public void executeCommand(EventList eventList) throws Exception { + public void executeCommand(EventList eventList, Ui ui) throws Exception { eventList.deleteEvent(indexToDelete, ui); } } diff --git a/src/main/java/command/EventCommand.java b/src/main/java/command/EventCommand.java index 56168d99d..7eb0aec28 100644 --- a/src/main/java/command/EventCommand.java +++ b/src/main/java/command/EventCommand.java @@ -3,9 +3,6 @@ import event.EventList; import parser.Parser; import ui.Ui; - -import java.util.Scanner; - import static ui.Ui.BYE_COMMAND; /** @@ -21,25 +18,26 @@ public class EventCommand { * @param parser Object used to parse the user input into commands. */ public static void runCommands(EventList eventList, Ui ui, Parser parser) { - eventList.printHelp(); - Scanner sc = new Scanner(System.in); + ui.printHelp(); String fullCommand; Command command; - fullCommand = sc.nextLine(); + fullCommand = ui.getUserIn(); while (!fullCommand.equals(BYE_COMMAND)) { try { - command = parser.parseCommand(fullCommand, ui); - command.executeCommand(eventList); + command = parser.parseCommand(fullCommand); + command.executeCommand(eventList, ui); } catch (Exception exception) { ui.printLine(); - ui.printWithIndentation(exception.getMessage()); + ui.printMessage(exception.getMessage()); ui.printLine(); } - ui.printEmptyLine(); - fullCommand = sc.nextLine(); + fullCommand = ui.getUserIn(); + } - ui.printByeMessage(); + ui.printLine(); + ui.printMessage(Ui.BYE_MESSAGE); + ui.printLine(); } } diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java index bb2536e3a..e51656248 100644 --- a/src/main/java/command/HelpCommand.java +++ b/src/main/java/command/HelpCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import ui.Ui; /** * Command is used to print the list of commands supported. @@ -21,7 +22,7 @@ public HelpCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList) throws Exception { - eventList.printHelp(); + public void executeCommand(EventList eventList, Ui ui) throws Exception { + ui.printHelp(); } } diff --git a/src/main/java/command/PriorityViewCommand.java b/src/main/java/command/PriorityViewCommand.java index 136be94c4..33be48340 100644 --- a/src/main/java/command/PriorityViewCommand.java +++ b/src/main/java/command/PriorityViewCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import ui.Ui; /** * Displays the list of events added so far in decreasing order of their priority. @@ -21,7 +22,7 @@ public PriorityViewCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList) throws Exception { + public void executeCommand(EventList eventList, Ui ui) throws Exception { eventList.priorityView(ui); } } diff --git a/src/main/java/command/SearchCommand.java b/src/main/java/command/SearchCommand.java index 04f9c7b5b..bfde00d87 100644 --- a/src/main/java/command/SearchCommand.java +++ b/src/main/java/command/SearchCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import ui.Ui; /** * Command used to perform a search of events whose description contain the keyword mentioned. @@ -26,7 +27,7 @@ public SearchCommand(String[] commandSplit, boolean isOneWordCommand) throws Exc } @Override - public void executeCommand(EventList eventList) throws Exception { + public void executeCommand(EventList eventList, Ui ui) throws Exception { eventList.searchEvents(keyword, ui); } } diff --git a/src/main/java/command/StudyAreaCommand.java b/src/main/java/command/StudyAreaCommand.java index 0fbc33538..25ac5d9e0 100644 --- a/src/main/java/command/StudyAreaCommand.java +++ b/src/main/java/command/StudyAreaCommand.java @@ -77,7 +77,7 @@ public static void runCommands(StudyAreaList studyAreaList, Ui ui) { boolean status = true; while (status) { ui.printLine(); - String command = ui.getUserIn(); + String command = ui.getUserIn().toLowerCase(); ui.printLine(); try { status = filterCommand(command, studyAreaList, ui); diff --git a/src/main/java/command/ViewCommand.java b/src/main/java/command/ViewCommand.java index bbac39f84..a46bea7df 100644 --- a/src/main/java/command/ViewCommand.java +++ b/src/main/java/command/ViewCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import ui.Ui; /** * Displays the list of events added so far. @@ -21,7 +22,7 @@ public ViewCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList) throws Exception { + public void executeCommand(EventList eventList, Ui ui) throws Exception { eventList.listEvents(ui); } } diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index 617145c83..a7c418893 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -182,34 +182,6 @@ public void add(String eventDetails, Ui ui) { } } - /** - * Display the list of supported commands. - */ - public void printHelp() { - Ui ui = new Ui(); - ui.printLine(); - ui.printWithIndentation("OrgaNice! Supports the following commands"); - ui.printWithIndentation("Please enter the keywords followed by the information shown in the brackets"); - ui.printWithIndentation("add /d /s /e /p "); - ui.printWithIndentation("------------------------------------------- Create a new event"); - ui.printWithIndentation("view -------------------------------------- View existing events"); - ui.printWithIndentation("priority_view ----------------------------- View existing events based " - + "on priority"); - ui.printWithIndentation("countdown --------------------------------- View existing events based on" - + " days left"); - ui.printWithIndentation("clear ------------------------------------- Delete all events"); - ui.printWithIndentation("search ----------- View existing events that contains " - + "the keyword"); - ui.printWithIndentation("delete ------------ Delete the event"); - ui.printWithIndentation("help -------------------------------------- View List Of Commands Supported"); - ui.printWithIndentation("bye --------------------------------------- Terminate program"); - ui.printWithIndentation("Notes:"); - ui.printWithIndentation("*All dates should follow YYYY-MM-DD format"); - ui.printWithIndentation("*All timing should follow 24 hour clock"); - ui.printWithIndentation("*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " - + "least urgent"); - ui.printLine(); - } + } \ No newline at end of file diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java index 4b370a34e..510b232b5 100644 --- a/src/main/java/parser/Parser.java +++ b/src/main/java/parser/Parser.java @@ -9,7 +9,6 @@ import command.PriorityViewCommand; import command.SearchCommand; import command.ViewCommand; -import ui.Ui; /** * This class is used to parse the user input into executable commands. @@ -30,11 +29,10 @@ public class Parser { * This method takes in the user input parses it and returns the command to be executed. * * @param fullCommand THe entire line of command entered by the user. - * @param ui Object used to handle interactions with user. * @return command The command parsed form the user input. * @throws Exception If the wrong command/ wrong format is given by the user as an input. */ - public Command parseCommand(String fullCommand, Ui ui) throws Exception { + public Command parseCommand(String fullCommand) throws Exception { String[] commandSplit = fullCommand.split(" ",2); String commandType = commandSplit[0]; diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index c3857b6c7..f202113be 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -20,7 +20,7 @@ public class Duke { protected static StudyAreaLoader studyAreaLoader; private static EventList eventList = new EventList(); private static StudyAreaList studyAreaList; - private static Ui ui; + private static Ui ui = new Ui(); private static Parser parser; /** @@ -28,14 +28,15 @@ public class Duke { */ public Duke() { try { - ui = new Ui(); parser = new Parser(); eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); eventList = new EventList(eventLoader.loadFile()); studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); } catch (FileNotFoundException | IllegalStudyAreaException e) { - // Handle issue later + ui.printLine(); + ui.printMessage(e.getMessage()); + ui.printLine(); } } @@ -53,16 +54,17 @@ public void run() { break; case 1: EventCommand.runCommands(eventList, ui, parser); + ui.printMessage(Ui.INTERMEDIATE_MESSAGE); break; case 2: StudyAreaCommand.runCommands(studyAreaList, ui); + ui.printMessage(Ui.INTERMEDIATE_MESSAGE); break; default: ui.printLine(); ui.printMessage(Ui.WRONG_INPUT); break; } - ui.printWithIndentation(Ui.INTERMEDIATE_MESSAGE); ui.printLine(); } eventLoader.saveEvents(eventList.events); diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index adab68442..20439f550 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -24,6 +24,72 @@ public ArrayList getStudyAreaList() { return this.studyAreaList; } + /** + * This method checks for duplicate flags. + * @param flag this is the array of flags in the system. + * @param index this is the index referring to the specific flag to check for duplicate. + * @throws IllegalStudyAreaException if flag is not null, ie: if flag has already been mentioned. + */ + public void checkDuplicate(String[] flag, int index) throws IllegalStudyAreaException { + if (flag[index] != null) { + throw new IllegalStudyAreaException(Ui.DUPLICATE_FLAGS); + } + } + + /** + * This method check if command entered is only flags. + * @param commands This is the string of commands entered by User. + * @param index This is the index in which the method is check if only flag exist. + * @throws IllegalStudyAreaException if only flag is entered by user. + */ + + public void checkOnlyFlag(String[] commands, int index) throws IllegalStudyAreaException { + if (commands[index].length() == 1) { + throw new IllegalStudyAreaException(Ui.ONLY_FLAG); + } + } + + /** + * This method assigns flags based on User input. + * + * @param flags this is the array of flags. + * @param commands this is the full command entered by Users. + * @param index this is the index which the method is assigning the commands into the flags array. + * @param isNotFlag this is the boolean value that checks if the command entered is a flag. + * @throws IllegalStudyAreaException if user enters command wrongly. + */ + public void checkFlag(String[] flags, String[] commands, int index, boolean isNotFlag) throws + IllegalStudyAreaException { + + if (commands[index].equals(Ui.SIZE_FLAG)) { + checkDuplicate(flags, 0); + try { + int size = Integer.parseInt(commands[index + 1]); + } catch (NumberFormatException e) { + throw new IllegalStudyAreaException(Ui.NOT_INTEGER); + } catch (ArrayIndexOutOfBoundsException e) { + throw new IllegalStudyAreaException(Ui.NO_SIZE_INDICATED); + } + } else if (commands[index].contains(Ui.FLAG)) { + checkOnlyFlag(commands, index); + switch (commands[index].charAt(1)) { + case 'p': + checkDuplicate(flags, 2); + break; + case 'i': + case 'o': + checkDuplicate(flags, 3); + break; + default: + throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); + } + } else { + if (!isNotFlag) { + throw new IllegalStudyAreaException(Ui.WRONG_FLAG_ARGUMENT_POSITION); + } + } + } + /** * Obtains all the supported flags in this organiser app. * @@ -32,56 +98,42 @@ public ArrayList getStudyAreaList() { * @throws IllegalStudyAreaException when arguments for flags are invalid. */ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException { + String[] flags = new String[5]; StringBuilder name = new StringBuilder(); boolean isNotFlag = true; for (int i = 0; i < commands.length; i++) { if (commands[i].equals(Ui.SIZE_FLAG)) { - isNotFlag = false; - try { - int size = Integer.parseInt(commands[i + 1]); - if (flags[0] == null) { - flags[0] = Ui.SIZE_FLAG; - flags[1] = Integer.toString(size); - i++; - } else { - throw new IllegalStudyAreaException(Ui.DUPLICATE_FLAGS); - } - } catch (NumberFormatException e) { - throw new IllegalStudyAreaException(Ui.NOT_INTEGER); - } catch (ArrayIndexOutOfBoundsException e) { - throw new IllegalStudyAreaException(Ui.NO_SIZE_INDICATED); - } + isNotFlag = false; // update isNotFlag as false because command is a flag + checkFlag(flags, commands, i, false); // pass false instead of isNotFlag as only boolean logic + flags[0] = Ui.SIZE_FLAG; + flags[1] = Integer.toString(Integer.parseInt(commands[i + 1])); + i++; } else if (commands[i].contains(Ui.FLAG)) { isNotFlag = false; - if (commands[i].length() == 1) { - throw new IllegalStudyAreaException(Ui.ONLY_FLAG); - } + checkFlag(flags, commands, i,false); switch (commands[i].charAt(1)) { case 'p': - if (flags[2] == null) { - flags[2] = Ui.PORTS_FLAG; - } else { - throw new IllegalStudyAreaException(Ui.DUPLICATE_FLAGS); - } + flags[2] = Ui.PORTS_FLAG; break; case 'i': - if (flags[3] == null) { - flags[3] = Ui.INDOOR_FLAG; - } else { - throw new IllegalStudyAreaException(Ui.DUPLICATE_FLAGS); - } + flags[3] = Ui.INDOOR_FLAG; + break; + case 'o': + flags[3] = Ui.OUTDOOR_FLAG; break; default: throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); } } else { if (isNotFlag) { + checkFlag(flags, commands, i, true); name.append(commands[i]).append(Ui.SPACE); flags[4] = name.toString().trim(); } else { - throw new IllegalStudyAreaException(Ui.WRONG_FLAG_ARGUMENT_POSITION); + checkFlag(flags, commands, i, false); } + } } return flags; @@ -127,6 +179,9 @@ public ArrayList searchList(String userIn) throws IllegalStudyAreaExc case Ui.INDOOR_FLAG: isAvail = studyArea.isIndoor(); break; + case Ui.OUTDOOR_FLAG: + isAvail = !studyArea.isIndoor(); + break; case Ui.SIZE_FLAG: isAvail = Integer.toString(studyArea.getMaxPax()).equals(flags[1]); flags[1] = null; //so as to skip iteration on flags[1]. diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 2fdc456b4..70720912d 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -7,6 +7,7 @@ import java.io.PrintStream; import java.util.Scanner; import java.util.StringTokenizer; +import static java.lang.System.lineSeparator; /** * Contains functions used to interact with the user. @@ -23,13 +24,13 @@ public class Ui { public static final String LINE = "_______________________________________________________________________________" + "_____"; public static final int MAX_LINE_LENGTH = 55; - public static final int ADDRESS_MAX_LENGTH = 48; public static final String FLAG = "-"; public static final String MULTIPLE_WHITE_SPACES = "\\s+"; public static final String DUPLICATE_FLAGS = "Duplicate flags entered!"; public static final String SIZE_FLAG = "-s"; public static final String PORTS_FLAG = "-p"; public static final String INDOOR_FLAG = "-i"; + public static final String OUTDOOR_FLAG = "-o"; public static final String NOT_INTEGER = "Argument used after size flag \"-s\" is not an integer"; public static final String WRONG_FLAG_USAGE = "Flags indicated are wrongly used. Please enter \"help\" for the" + " supported flags!"; @@ -40,7 +41,8 @@ public class Ui { + " location is entered. When you are done with the search, enter \"bye\"."; public static final String PROMPT_USER = "Please enter the location for your desired study area."; public static final String FLAGS = "Here is a list of supported flags!\n\t -p for study areas with ports\n\t" - + " -i for study areas that are indoors\n\t -s {size} for maximum number of pax"; + + " -i for study areas that are indoors\n\t -i for study areas that are outdoors\n\t " + + "-s {size} for maximum number of pax"; public static final String AVAILABLE_STUDY_AREAS = "Here are the available study areas!"; public static final String EMPTY_LIST = "Oops! Based on your criteria we were not able to find a compatible study" + "area!"; @@ -51,15 +53,15 @@ public class Ui { public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"event\" to start\n" - + " your event list! If you are in the mood to mug and you\n" - + " want to start your study area list, enter \"study\" !If\n" - + " you want to exit, enter \"bye\" !"; + + " your event list! If you are in the mood to mug and you" + + " want to start your study area list, enter \"study\" !If" + + " you want to exit, enter \"bye\" !"; public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; public static final String EVENT_COMMAND = "event"; public static final String STUDY_COMMAND = "study"; public static final String GOODBYE_MESSAGE = " Goodbye! Hope to see you again!"; - public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or\n" - + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; + public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or" + + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; public static final String EMPTY_LOCATION = "Location entered is empty! Please type a location to search for " + "StudyAreas!"; @@ -152,18 +154,9 @@ public void close() { * Prints a line made up of '_'. */ public void printLine() { - System.out.println("_________________________________________________________________________________" - + "_______________"); + this.out.println(LINE); } - /** - * Prints the user given line with an indentation. - * - * @param line The line to be printed. - */ - public void printWithIndentation(String line) { - System.out.println(" " + line); - } /** * This method ensures that the message printed is within the standard length. @@ -172,10 +165,10 @@ public void printWithIndentation(String line) { */ public void printMessage(String message) { if (message.equals(GOODBYE_MESSAGE + DAB)) { - this.out.println(GOODBYE_MESSAGE); + this.out.println(TAB + GOODBYE_MESSAGE); this.out.println(DAB); } else { - this.out.println(message); + this.out.println(formatMessage(message, MAX_LINE_LENGTH)); } } @@ -228,7 +221,7 @@ public void printWelcomeMessage() { String name = this.in.nextLine(); printLine(); this.out.println(TAB + "Hello " + name + "!"); - printWithIndentation(START_MESSAGE); + printMessage(START_MESSAGE); printLine(); } @@ -240,11 +233,64 @@ public void printEmptyLine() { } /** - * Prints the bye message. + * Display the list of supported commands. */ - public void printByeMessage() { + public void printHelp() { printLine(); - printWithIndentation("Bye!!!!!"); + this.out.println(TAB + "OrgaNice! Supports the following commands"); + this.out.println(TAB + "Please enter the keywords followed by the information shown in the brackets"); + this.out.println(TAB + "add /d /s /e /p "); + this.out.println(TAB + "------------------------------------------- Create a new event"); + this.out.println(TAB + "view -------------------------------------- View existing events"); + this.out.println(TAB + "priority_view ----------------------------- View existing events based " + + "on priority"); + this.out.println(TAB + "countdown --------------------------------- View existing events based on" + + " days left"); + this.out.println(TAB + "clear ------------------------------------- Delete all events"); + this.out.println(TAB + "search ----------- View existing events that contains " + + "the keyword"); + this.out.println(TAB + "delete ------------ Delete the event"); + this.out.println(TAB + "help -------------------------------------- View List Of Commands Supported"); + this.out.println(TAB + "bye --------------------------------------- Terminate program"); + this.out.println(TAB + "Notes:"); + this.out.println(TAB + "*All dates should follow YYYY-MM-DD format"); + this.out.println(TAB + "*All timing should follow 24 hour clock"); + this.out.println(TAB + "*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " + + "least urgent"); printLine(); } + + /** + * This is a modification of a code from Stack Overflow to format strings into a standard length. Minor edition is + * made to ensure suitability with the program. + * This method ensures that the message printed is within the standard
+ * length. + * @param message is the String that we intend to format to a standard length
+ * per line.
+ * @param maxLength This is the standard length intended to be formatted. + * @return String of standard length per line + */ + //@@author NizarMohd-reused + //Reused from https://stackoverflow.com/questions/7528045/large-string-split-into-lines-with-maximum-length-in-java + // with minor modification. + public static String formatMessage(String message, int maxLength) { + StringTokenizer token = new StringTokenizer(message, SPACE); + StringBuilder standardLengthMessage = new StringBuilder(message.length()); + int lineLength = 0; + while (token.hasMoreTokens()) { + String word = token.nextToken(); + if (lineLength + word.length() > maxLength) { + String temp = standardLengthMessage.toString().trim(); + standardLengthMessage = new StringBuilder(temp); + standardLengthMessage.append(lineSeparator() + "\t "); + lineLength = 0; + } + standardLengthMessage.append(word).append(SPACE); + lineLength += word.length() + 1; + } + return TAB + standardLengthMessage.toString().stripTrailing(); + } + //@@author + } diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 6c9d82ed6..0a7d67f55 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -9,18 +9,16 @@ ________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\/ ____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ ______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ What is your name? -________________________________________________________________________________________________ -________________________________________________________________________________________________ +____________________________________________________________________________________ +____________________________________________________________________________________ Hello James Gosling! - Welcome to OrgaNice! To start, enter "event" to start - your event list! If you are in the mood to mug and you - want to start your study area list, enter "study" !If - you want to exit, enter "bye" ! -________________________________________________________________________________________________ - Please enter "event" to continue with your event list or - "study" to continue with your study area list. To leave, enter "bye". -________________________________________________________________________________________________ - Goodbye! Hope to see you again! + Welcome to OrgaNice! To start, enter "event" to start + your event list! If you are in the mood to mug and you + want to start your study area list, enter "study" !If + you want to exit, enter "bye" ! +____________________________________________________________________________________ +____________________________________________________________________________________ + Goodbye! Hope to see you again! `````````````````````````````````````````````````````````` ````````````````````````````````:v(v'````````````````````` ```````````````````````````,)4|ex` `L}```````````````````` diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 6c9d82ed6..0a7d67f55 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -9,18 +9,16 @@ ________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\/ ____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ ______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ What is your name? -________________________________________________________________________________________________ -________________________________________________________________________________________________ +____________________________________________________________________________________ +____________________________________________________________________________________ Hello James Gosling! - Welcome to OrgaNice! To start, enter "event" to start - your event list! If you are in the mood to mug and you - want to start your study area list, enter "study" !If - you want to exit, enter "bye" ! -________________________________________________________________________________________________ - Please enter "event" to continue with your event list or - "study" to continue with your study area list. To leave, enter "bye". -________________________________________________________________________________________________ - Goodbye! Hope to see you again! + Welcome to OrgaNice! To start, enter "event" to start + your event list! If you are in the mood to mug and you + want to start your study area list, enter "study" !If + you want to exit, enter "bye" ! +____________________________________________________________________________________ +____________________________________________________________________________________ + Goodbye! Hope to see you again! `````````````````````````````````````````````````````````` ````````````````````````````````:v(v'````````````````````` ```````````````````````````,)4|ex` `L}```````````````````` From 3abbc8fc12fb329720231c6ae08ae67fc560dc62 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Wed, 11 Mar 2020 23:14:05 +0800 Subject: [PATCH 057/435] Add JUnit Test for the EventList and Parser Class --- src/main/java/command/AddCommand.java | 2 +- src/main/java/command/DeleteCommand.java | 3 +- src/main/java/event/EventList.java | 34 ++++-- src/main/java/parser/Parser.java | 2 +- src/test/java/event/EventListTest.java | 49 ++++++++ src/test/java/parser/ParserTest.java | 136 +++++++++++++++++++++++ 6 files changed, 211 insertions(+), 15 deletions(-) create mode 100644 src/test/java/event/EventListTest.java create mode 100644 src/test/java/parser/ParserTest.java diff --git a/src/main/java/command/AddCommand.java b/src/main/java/command/AddCommand.java index 4c336e7fb..6510d95e2 100644 --- a/src/main/java/command/AddCommand.java +++ b/src/main/java/command/AddCommand.java @@ -21,7 +21,7 @@ public class AddCommand extends Command { */ public AddCommand(String[] eventDetails, boolean isOneWordCommand) throws Exception { if (isOneWordCommand) { - throw new Exception("Wrong format used to add an event"); + throw new Exception("Event details isn't provided"); } String[] details = eventDetails[1].split("/"); String description = details[0]; diff --git a/src/main/java/command/DeleteCommand.java b/src/main/java/command/DeleteCommand.java index a24b9ba68..67a4a446b 100644 --- a/src/main/java/command/DeleteCommand.java +++ b/src/main/java/command/DeleteCommand.java @@ -25,7 +25,8 @@ public DeleteCommand(String[] commandSplit, boolean isOneWordCommand) throws Exc try { indexToDelete = Integer.parseInt(commandSplit[1]); } catch (NumberFormatException e) { - throw new Exception("Enter a valid index (1-based) to delete the corresponding event"); + throw new Exception("Enter a valid integer index (1-based) to delete the corresponding event " + + "(format: delete index)"); } } diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index 617145c83..3d0165f7e 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -22,10 +22,24 @@ public EventList() { events = new ArrayList(); } + /** + * Overloaded constructor for EventList class. + * + * @param events The list of events the class's list of events is initialised with. + */ public EventList(ArrayList events) { this.events = events; } + /** + * Returns the number of events currently stored. + * + * @return The number of events stored currently. + */ + public int getEventListSize() { + return events.size(); + } + /** * Adds a new event to the list. * @@ -61,16 +75,16 @@ public void listEvents(Ui ui) { * * @param ui This allows Event List class to interact with User. * @param index The index (1-based) of the event to be deleted. + * @throws Exception If the index specified is invalid. */ - public void deleteEvent(int index, Ui ui) { - ui.printLine(); + public void deleteEvent(int index, Ui ui) throws Exception { try { events.remove(index - 1); + ui.printLine(); ui.printMessage("The event at the mentioned index has been deleted"); ui.printLine(); } catch (IndexOutOfBoundsException e) { - ui.printMessage("Enter a valid index"); - ui.printLine(); + throw new Exception("Invalid index entered. Please enter a valid index to be deleted"); } } @@ -134,17 +148,13 @@ public void countdownView(Ui ui) { * @param ui This allows Event List class to interact with User. * @param keyword The keyword to be searched for. */ - public void searchEvents(String keyword, Ui ui) { + public void searchEvents(String keyword, Ui ui) throws Exception { int eventNumber = 1; ui.printLine(); for (Event event:events) { - try { - if (event.hasKeyword(keyword)) { - ui.printMessage(eventNumber + ") " + event.getEventInformation()); - eventNumber++; - } - } catch (Exception e) { - e.printStackTrace(); + if (event.hasKeyword(keyword)) { + ui.printMessage(eventNumber + ") " + event.getEventInformation()); + eventNumber++; } } if (eventNumber == 1) { diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java index 4b370a34e..468d409f6 100644 --- a/src/main/java/parser/Parser.java +++ b/src/main/java/parser/Parser.java @@ -29,7 +29,7 @@ public class Parser { /** * This method takes in the user input parses it and returns the command to be executed. * - * @param fullCommand THe entire line of command entered by the user. + * @param fullCommand The entire line of command entered by the user. * @param ui Object used to handle interactions with user. * @return command The command parsed form the user input. * @throws Exception If the wrong command/ wrong format is given by the user as an input. diff --git a/src/test/java/event/EventListTest.java b/src/test/java/event/EventListTest.java new file mode 100644 index 000000000..589efaa9e --- /dev/null +++ b/src/test/java/event/EventListTest.java @@ -0,0 +1,49 @@ +package event; + +import org.junit.jupiter.api.Test; +import ui.Ui; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Contains all the test related to EventList class. + */ +class EventListTest { + + Ui ui = new Ui(); + EventList eventList; + + public EventListTest() throws Exception { + eventList = new EventList(); + eventList.addEvent(new Event("Team Meeting", "2020-03-21", "09:00", + "17:00", "1"),ui); + } + + @Test + void deleteEvent_invalidIndex_throwException() throws Exception { + try { + eventList.deleteEvent(2,ui); + fail("Illegal delete not found"); + } catch (Exception exception) { + assertEquals("Invalid index entered. Please enter a valid index to be deleted", + exception.getMessage()); + } + } + + @Test + void searchEvents_emptySearchKeyword_throwException() { + try { + eventList.searchEvents("",ui); + fail("Empty string search not identified"); + } catch (Exception exception) { + assertEquals("Keyword is empty", exception.getMessage()); + } + } + + @Test + void clearCommand() { + eventList.clearEvents(ui); + assertEquals(0, eventList.getEventListSize()); + } + +} \ No newline at end of file diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java new file mode 100644 index 000000000..bb5dff3c7 --- /dev/null +++ b/src/test/java/parser/ParserTest.java @@ -0,0 +1,136 @@ +package parser; + +import command.Command; +import org.junit.jupiter.api.Test; +import ui.Ui; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Contains all test regarding the Parser Class. + */ +class ParserTest { + + Ui ui = new Ui(); + Parser parser = new Parser(); + Command command; + + @Test + void parseCommand_emptyAddCommand_throwException() { + try { + command = parser.parseCommand("add",ui); + fail("Empty add command not identified"); + } catch (Exception exception) { + assertEquals("Event details isn't provided",exception.getMessage()); + } + } + + + @Test + void parseCommand_emptyCommand_throwException() { + try { + command = parser.parseCommand("",ui); + fail("Empty command not identified"); + } catch (Exception exception) { + assertEquals("Empty Line entered, Please enter a valid line",exception.getMessage()); + } + } + + @Test + void parseCommand_invalidCommand_throwException() { + try { + command = parser.parseCommand("list",ui); + fail("Invalid command not identified"); + } catch (Exception exception) { + assertEquals("Invalid command entered, Please enter a valid command",exception.getMessage()); + } + } + + @Test + void parseCommand_invalidPriorityViewCommand_throwException() { + try { + command = parser.parseCommand("priority_view of events", ui); + fail("Invalid priority view command not identified"); + } catch (Exception exception) { + assertEquals("Wrong command used to view events sorted by priority (Should be :priority_view )", + exception.getMessage()); + } + } + + @Test + void parseCommand_invalidCountdownViewCommand_throwException() { + try { + command = parser.parseCommand("countdown of events", ui); + fail("Invalid countdown view command not identified"); + } catch (Exception exception) { + assertEquals("Wrong command used to view countdown of events (Should be :countdown )", + exception.getMessage()); + } + } + + @Test + void parseCommand_invalidViewCommand_throwException() { + try { + command = parser.parseCommand("view events", ui); + fail("Invalid view command not identified"); + } catch (Exception exception) { + assertEquals("Wrong command used to view events (Should be :view )", + exception.getMessage()); + } + } + + @Test + void parseCommand_invalidClearCommand_throwException() { + try { + command = parser.parseCommand("clear events", ui); + fail("Invalid clear command not identified"); + } catch (Exception exception) { + assertEquals("Wrong command clear events (Should be :clear )", + exception.getMessage()); + } + } + + @Test + void parseCommand_invalidHelpCommand_throwException() { + try { + command = parser.parseCommand("help for commands", ui); + fail("Invalid help command not identified"); + } catch (Exception exception) { + assertEquals("Wrong command used to view command list (Should be :help )", + exception.getMessage()); + } + } + + @Test + void parseCommand_emptySearchCommand_throwException() { + try { + command = parser.parseCommand("search ", ui); + fail("Empty search command not identified"); + } catch (Exception exception) { + assertEquals("The search string entered is empty.",exception.getMessage()); + } + } + + @Test + void parseCommand_emptyDeleteCommand_throwException() { + try { + command = parser.parseCommand("delete ", ui); + fail("Empty delete command not identified"); + } catch (Exception exception) { + assertEquals("Index to delete not mentioned", exception.getMessage()); + } + } + + @Test + void parseCommand_invalidDeleteCommand_throwException() { + try { + command = parser.parseCommand("delete one", ui); + fail("Invalid delete command not identified"); + } catch (Exception exception) { + assertEquals("Enter a valid integer index (1-based) to delete the corresponding event " + + "(format: delete index)", + exception.getMessage()); + } + } + +} \ No newline at end of file From 886b1427a7fb994fdef6f79c015db80176ea9a16 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Wed, 11 Mar 2020 23:19:21 +0800 Subject: [PATCH 058/435] Rectify issue with coding style --- src/test/java/event/EventListTest.java | 5 +++-- src/test/java/parser/ParserTest.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/event/EventListTest.java b/src/test/java/event/EventListTest.java index 589efaa9e..b12552c7b 100644 --- a/src/test/java/event/EventListTest.java +++ b/src/test/java/event/EventListTest.java @@ -3,7 +3,8 @@ import org.junit.jupiter.api.Test; import ui.Ui; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Contains all the test related to EventList class. @@ -46,4 +47,4 @@ void clearCommand() { assertEquals(0, eventList.getEventListSize()); } -} \ No newline at end of file +} diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java index bb5dff3c7..490ab204a 100644 --- a/src/test/java/parser/ParserTest.java +++ b/src/test/java/parser/ParserTest.java @@ -4,7 +4,8 @@ import org.junit.jupiter.api.Test; import ui.Ui; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Contains all test regarding the Parser Class. @@ -133,4 +134,4 @@ void parseCommand_invalidDeleteCommand_throwException() { } } -} \ No newline at end of file +} From eea9ab32383c71f8bf5dec94431ff8d5d868fbc1 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Wed, 11 Mar 2020 23:20:41 +0800 Subject: [PATCH 059/435] Add javadoc comment --- src/main/java/event/EventList.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index 3d0165f7e..98b8a040b 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -147,6 +147,7 @@ public void countdownView(Ui ui) { * * @param ui This allows Event List class to interact with User. * @param keyword The keyword to be searched for. + * @throws Exception If the keyword is empty. */ public void searchEvents(String keyword, Ui ui) throws Exception { int eventNumber = 1; From 7e84f0c229023b28a6f40823d2bf616c81256ca3 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Wed, 11 Mar 2020 23:26:26 +0800 Subject: [PATCH 060/435] rectified changes to pass windows test --- src/main/java/resourceloader/EventLoader.java | 1 + .../java/resourceloader/StudyAreaLoader.java | 21 ++++++++----------- src/main/java/ui/Ui.java | 1 + text-ui-test/library/locations.txt | 8 ------- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java index 30ecc2a98..2e8bb85b5 100644 --- a/src/main/java/resourceloader/EventLoader.java +++ b/src/main/java/resourceloader/EventLoader.java @@ -88,6 +88,7 @@ private void createNewDataFile() { try { Files.createDirectories(fileDirectory); Files.createFile(Paths.get(filePath)); + Files.createFile(Paths.get(Ui.FILE_PATH_STUDYAREAS)); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index c26dd4f69..f5bc9d3ab 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -3,7 +3,6 @@ import studyarea.IllegalStudyAreaException; import studyarea.StudyArea; import ui.Ui; - import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; @@ -15,24 +14,22 @@ public class StudyAreaLoader { private static final String DIVIDER = "~"; - private final String url; + private String url; private File file; - public StudyAreaLoader(String url) throws FileNotFoundException { + public StudyAreaLoader(String url) throws IllegalStudyAreaException { this.url = url; loadFile(); } /** * Loads url into file. - * - * @throws FileNotFoundException if file is not present error */ - public void loadFile() throws FileNotFoundException { + public void loadFile() throws IllegalStudyAreaException{ try { - file = new File(url); + this.file = new File(this.url); } catch (Exception e) { - throw new FileNotFoundException("File not found."); + throw new IllegalStudyAreaException(Ui.MISSING_STUDY_AREA_DATA); } } @@ -45,9 +42,9 @@ public void loadFile() throws FileNotFoundException { * @throws IllegalStudyAreaException if data stored is inconsistent */ - public ArrayList pushToDatabase() throws FileNotFoundException, IllegalStudyAreaException { + public ArrayList pushToDatabase() throws IllegalStudyAreaException, FileNotFoundException { ArrayList buffer = new ArrayList<>(); - Scanner input = new Scanner(file); + Scanner input = new Scanner(this.file); while (input.hasNextLine()) { String detailsOfLocation = input.nextLine(); String[] detailsBuffer = detailsOfLocation.split(DIVIDER); @@ -59,8 +56,8 @@ public ArrayList pushToDatabase() throws FileNotFoundException, Illeg Integer.parseInt(detailsBuffer[5])); buffer.add(studyArea); } + input.close(); return buffer; } +} - -} \ No newline at end of file diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 70720912d..2f381049e 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -19,6 +19,7 @@ public class Ui { public static final String FILE_PATH_EVENTS = "library" + File.separator + "eventList.txt"; public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; + public static final String MISSING_STUDY_AREA_DATA = "locations.txt is missing"; public static final String BYE_COMMAND = "bye"; public static final String BYE_MESSAGE = "Bye!!!!!!"; public static final String LINE = "_______________________________________________________________________________" diff --git a/text-ui-test/library/locations.txt b/text-ui-test/library/locations.txt index 42de138ad..e69de29bb 100644 --- a/text-ui-test/library/locations.txt +++ b/text-ui-test/library/locations.txt @@ -1,8 +0,0 @@ -MacCommons~2 College Ave West Education Resource Centre~Utown~true~true~5 -OCBC~2 College Ave West, Stephen Riady Centre~Utown~true~false~2 -EA Level 3~9 Engineering Drive 1,EA~Engineering~true~true~4 -EA Level 2~9 Engineering Drive 1~Engineering~true~true~4 -EA Level 1~9 Engineering Drive 1~Engineering~true~true~4 -EA Level 4~9 Engineering Drive 1, Outside Staff Offices~Engineering~true~false~6 -EA Level 5~9 Engineering Drive 1, Outside of the door beside EA05~Engineering~true~false~4 -EA Level 6~9 Engineering Drive 1, EA06-23~Engineering~true~true~4 \ No newline at end of file From d741eb287fe362391664d0ed6a29ec5aa4efd165 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Wed, 11 Mar 2020 23:31:47 +0800 Subject: [PATCH 061/435] Rectify StudyAreaLoader to pass gradle --- src/main/java/resourceloader/StudyAreaLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index f5bc9d3ab..8bdbe08a2 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -25,7 +25,7 @@ public StudyAreaLoader(String url) throws IllegalStudyAreaException { /** * Loads url into file. */ - public void loadFile() throws IllegalStudyAreaException{ + public void loadFile() throws IllegalStudyAreaException { try { this.file = new File(this.url); } catch (Exception e) { From 6f93c47ef689aae64add82e3851ee94e69b2707c Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 12 Mar 2020 00:08:01 +0800 Subject: [PATCH 062/435] parser remove ui --- src/main/java/parser/Parser.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java index 468d409f6..5b1a28b8d 100644 --- a/src/main/java/parser/Parser.java +++ b/src/main/java/parser/Parser.java @@ -9,7 +9,6 @@ import command.PriorityViewCommand; import command.SearchCommand; import command.ViewCommand; -import ui.Ui; /** * This class is used to parse the user input into executable commands. @@ -30,11 +29,10 @@ public class Parser { * This method takes in the user input parses it and returns the command to be executed. * * @param fullCommand The entire line of command entered by the user. - * @param ui Object used to handle interactions with user. * @return command The command parsed form the user input. * @throws Exception If the wrong command/ wrong format is given by the user as an input. */ - public Command parseCommand(String fullCommand, Ui ui) throws Exception { + public Command parseCommand(String fullCommand) throws Exception { String[] commandSplit = fullCommand.split(" ",2); String commandType = commandSplit[0]; From e340f10a3244319e8c9a11a20057eb4875841a4e Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 12 Mar 2020 00:15:06 +0800 Subject: [PATCH 063/435] fix javadoc --- src/main/java/parser/Parser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java index 857b0d6cc..43e5b301b 100644 --- a/src/main/java/parser/Parser.java +++ b/src/main/java/parser/Parser.java @@ -26,7 +26,7 @@ public class Parser { public static final String HELP_COMMAND = "help"; /** - * This method takes in the user input parses it and returns the command to be executed. * + * This method takes in the user input parses it and returns the command to be executed. * @param fullCommand THe entire line of command entered by the user. * @return command The command parsed form the user input. * @throws Exception If the wrong command/ wrong format is given by the user as an input. From fea44f7e8112aba3d908e25a91adecdd7ca82e16 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 12 Mar 2020 00:28:37 +0800 Subject: [PATCH 064/435] Remove ui dependency in parsertest --- src/test/java/parser/ParserTest.java | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java index 490ab204a..02e0750f5 100644 --- a/src/test/java/parser/ParserTest.java +++ b/src/test/java/parser/ParserTest.java @@ -2,7 +2,6 @@ import command.Command; import org.junit.jupiter.api.Test; -import ui.Ui; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -12,14 +11,13 @@ */ class ParserTest { - Ui ui = new Ui(); Parser parser = new Parser(); Command command; @Test void parseCommand_emptyAddCommand_throwException() { try { - command = parser.parseCommand("add",ui); + command = parser.parseCommand("add"); fail("Empty add command not identified"); } catch (Exception exception) { assertEquals("Event details isn't provided",exception.getMessage()); @@ -30,7 +28,7 @@ void parseCommand_emptyAddCommand_throwException() { @Test void parseCommand_emptyCommand_throwException() { try { - command = parser.parseCommand("",ui); + command = parser.parseCommand(""); fail("Empty command not identified"); } catch (Exception exception) { assertEquals("Empty Line entered, Please enter a valid line",exception.getMessage()); @@ -40,7 +38,7 @@ void parseCommand_emptyCommand_throwException() { @Test void parseCommand_invalidCommand_throwException() { try { - command = parser.parseCommand("list",ui); + command = parser.parseCommand("list"); fail("Invalid command not identified"); } catch (Exception exception) { assertEquals("Invalid command entered, Please enter a valid command",exception.getMessage()); @@ -50,7 +48,7 @@ void parseCommand_invalidCommand_throwException() { @Test void parseCommand_invalidPriorityViewCommand_throwException() { try { - command = parser.parseCommand("priority_view of events", ui); + command = parser.parseCommand("priority_view of events"); fail("Invalid priority view command not identified"); } catch (Exception exception) { assertEquals("Wrong command used to view events sorted by priority (Should be :priority_view )", @@ -61,7 +59,7 @@ void parseCommand_invalidPriorityViewCommand_throwException() { @Test void parseCommand_invalidCountdownViewCommand_throwException() { try { - command = parser.parseCommand("countdown of events", ui); + command = parser.parseCommand("countdown of events"); fail("Invalid countdown view command not identified"); } catch (Exception exception) { assertEquals("Wrong command used to view countdown of events (Should be :countdown )", @@ -72,7 +70,7 @@ void parseCommand_invalidCountdownViewCommand_throwException() { @Test void parseCommand_invalidViewCommand_throwException() { try { - command = parser.parseCommand("view events", ui); + command = parser.parseCommand("view events"); fail("Invalid view command not identified"); } catch (Exception exception) { assertEquals("Wrong command used to view events (Should be :view )", @@ -83,7 +81,7 @@ void parseCommand_invalidViewCommand_throwException() { @Test void parseCommand_invalidClearCommand_throwException() { try { - command = parser.parseCommand("clear events", ui); + command = parser.parseCommand("clear events"); fail("Invalid clear command not identified"); } catch (Exception exception) { assertEquals("Wrong command clear events (Should be :clear )", @@ -94,7 +92,7 @@ void parseCommand_invalidClearCommand_throwException() { @Test void parseCommand_invalidHelpCommand_throwException() { try { - command = parser.parseCommand("help for commands", ui); + command = parser.parseCommand("help for commands"); fail("Invalid help command not identified"); } catch (Exception exception) { assertEquals("Wrong command used to view command list (Should be :help )", @@ -105,7 +103,7 @@ void parseCommand_invalidHelpCommand_throwException() { @Test void parseCommand_emptySearchCommand_throwException() { try { - command = parser.parseCommand("search ", ui); + command = parser.parseCommand("search "); fail("Empty search command not identified"); } catch (Exception exception) { assertEquals("The search string entered is empty.",exception.getMessage()); @@ -115,7 +113,7 @@ void parseCommand_emptySearchCommand_throwException() { @Test void parseCommand_emptyDeleteCommand_throwException() { try { - command = parser.parseCommand("delete ", ui); + command = parser.parseCommand("delete "); fail("Empty delete command not identified"); } catch (Exception exception) { assertEquals("Index to delete not mentioned", exception.getMessage()); @@ -125,7 +123,7 @@ void parseCommand_emptyDeleteCommand_throwException() { @Test void parseCommand_invalidDeleteCommand_throwException() { try { - command = parser.parseCommand("delete one", ui); + command = parser.parseCommand("delete one"); fail("Invalid delete command not identified"); } catch (Exception exception) { assertEquals("Enter a valid integer index (1-based) to delete the corresponding event " From cffa69b72b485c22618db01792f5381aaf0b4008 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 12 Mar 2020 01:15:57 +0800 Subject: [PATCH 065/435] Fix test output mismatches --- src/main/java/command/AddCommand.java | 2 +- src/main/java/command/DeleteCommand.java | 3 ++- src/main/java/event/EventList.java | 5 ++++- src/test/java/event/EventListTest.java | 10 ++++------ src/test/java/parser/ParserTest.java | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/command/AddCommand.java b/src/main/java/command/AddCommand.java index ee03277d3..c3dd0075d 100644 --- a/src/main/java/command/AddCommand.java +++ b/src/main/java/command/AddCommand.java @@ -22,7 +22,7 @@ public class AddCommand extends Command { */ public AddCommand(String[] eventDetails, boolean isOneWordCommand) throws Exception { if (isOneWordCommand) { - throw new Exception("Wrong format used to add an event"); + throw new Exception("Event details are not provided"); } String[] details = eventDetails[1].split("/"); diff --git a/src/main/java/command/DeleteCommand.java b/src/main/java/command/DeleteCommand.java index b5e941fb7..c8cf94c76 100644 --- a/src/main/java/command/DeleteCommand.java +++ b/src/main/java/command/DeleteCommand.java @@ -26,7 +26,8 @@ public DeleteCommand(String[] commandSplit, boolean isOneWordCommand) throws Exc try { indexToDelete = Integer.parseInt(commandSplit[1]); } catch (NumberFormatException e) { - throw new Exception("Enter a valid index (1-based) to delete the corresponding event"); + throw new Exception("Enter a valid integer index (1-based) to delete the corresponding event " + + "(format: delete index)"); } } diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index 22b2f6cfa..f566ec8b4 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -80,12 +80,15 @@ public void listEvents(Ui ui) { public void deleteEvent(int index, Ui ui) { ui.printLine(); try { + if (index > events.size() | index <= 0) { + throw new IndexOutOfBoundsException(); + } events.remove(index - 1); ui.printLine(); ui.printMessage("The event at the mentioned index has been deleted"); ui.printLine(); } catch (IndexOutOfBoundsException e) { - ui.printMessage("Enter a valid index"); + ui.printMessage("Invalid index entered. Please enter a valid index to be deleted"); ui.printLine(); } diff --git a/src/test/java/event/EventListTest.java b/src/test/java/event/EventListTest.java index b12552c7b..fb4785fdb 100644 --- a/src/test/java/event/EventListTest.java +++ b/src/test/java/event/EventListTest.java @@ -3,8 +3,7 @@ import org.junit.jupiter.api.Test; import ui.Ui; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; /** * Contains all the test related to EventList class. @@ -21,13 +20,12 @@ public EventListTest() throws Exception { } @Test - void deleteEvent_invalidIndex_throwException() throws Exception { + void deleteEvent_invalidIndex_throwException() { try { eventList.deleteEvent(2,ui); - fail("Illegal delete not found"); - } catch (Exception exception) { + } catch (Exception e) { assertEquals("Invalid index entered. Please enter a valid index to be deleted", - exception.getMessage()); + e.getMessage()); } } diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java index 02e0750f5..f0b628190 100644 --- a/src/test/java/parser/ParserTest.java +++ b/src/test/java/parser/ParserTest.java @@ -20,7 +20,7 @@ void parseCommand_emptyAddCommand_throwException() { command = parser.parseCommand("add"); fail("Empty add command not identified"); } catch (Exception exception) { - assertEquals("Event details isn't provided",exception.getMessage()); + assertEquals("Event details are not provided",exception.getMessage()); } } From c6d678084f9e7162eef01f75b205547be7a1ba0b Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 12 Mar 2020 01:18:50 +0800 Subject: [PATCH 066/435] Optimise imports in EventListTest.java --- src/test/java/event/EventListTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/event/EventListTest.java b/src/test/java/event/EventListTest.java index fb4785fdb..77bf65de8 100644 --- a/src/test/java/event/EventListTest.java +++ b/src/test/java/event/EventListTest.java @@ -3,7 +3,8 @@ import org.junit.jupiter.api.Test; import ui.Ui; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Contains all the test related to EventList class. From 3f98c7b44c3336169057d63ec71526848f3d8049 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 12 Mar 2020 02:05:44 +0800 Subject: [PATCH 067/435] Initial custom exceptions set up --- src/main/java/command/AddCommand.java | 5 +++-- src/main/java/command/ClearCommand.java | 3 ++- src/main/java/exception/CustomException.java | 7 +++++++ .../command/EventDetailsNotProvidedException.java | 9 +++++++++ .../exception/command/MisuseOfClearCommandException.java | 9 +++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/main/java/exception/CustomException.java create mode 100644 src/main/java/exception/command/EventDetailsNotProvidedException.java create mode 100644 src/main/java/exception/command/MisuseOfClearCommandException.java diff --git a/src/main/java/command/AddCommand.java b/src/main/java/command/AddCommand.java index c3dd0075d..c0d97c0ad 100644 --- a/src/main/java/command/AddCommand.java +++ b/src/main/java/command/AddCommand.java @@ -2,6 +2,7 @@ import event.Event; import event.EventList; +import exception.command.EventDetailsNotProvidedException; import ui.Ui; /** @@ -22,9 +23,9 @@ public class AddCommand extends Command { */ public AddCommand(String[] eventDetails, boolean isOneWordCommand) throws Exception { if (isOneWordCommand) { - throw new Exception("Event details are not provided"); + throw new EventDetailsNotProvidedException(); } - + String[] details = eventDetails[1].split("/"); String description = details[0]; String date = details[1].substring(2); diff --git a/src/main/java/command/ClearCommand.java b/src/main/java/command/ClearCommand.java index 82b6ae5a0..86999dbb0 100644 --- a/src/main/java/command/ClearCommand.java +++ b/src/main/java/command/ClearCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import exception.command.MisuseOfClearCommandException; import ui.Ui; /** @@ -17,7 +18,7 @@ public class ClearCommand extends Command { */ public ClearCommand(boolean isOneWordCommand) throws Exception { if (!isOneWordCommand) { - throw new Exception("Wrong command clear events (Should be :clear )"); + throw new MisuseOfClearCommandException(); } } diff --git a/src/main/java/exception/CustomException.java b/src/main/java/exception/CustomException.java new file mode 100644 index 000000000..0278f6c71 --- /dev/null +++ b/src/main/java/exception/CustomException.java @@ -0,0 +1,7 @@ +package exception; + +public abstract class CustomException extends Exception { + public CustomException(String errorMessage) { + super(errorMessage); + } +} diff --git a/src/main/java/exception/command/EventDetailsNotProvidedException.java b/src/main/java/exception/command/EventDetailsNotProvidedException.java new file mode 100644 index 000000000..4750ba53c --- /dev/null +++ b/src/main/java/exception/command/EventDetailsNotProvidedException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class EventDetailsNotProvidedException extends CustomException { + public EventDetailsNotProvidedException() { + super("Event details are not provided"); + } +} diff --git a/src/main/java/exception/command/MisuseOfClearCommandException.java b/src/main/java/exception/command/MisuseOfClearCommandException.java new file mode 100644 index 000000000..f50e3b87b --- /dev/null +++ b/src/main/java/exception/command/MisuseOfClearCommandException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class MisuseOfClearCommandException extends CustomException { + public MisuseOfClearCommandException() { + super("Wrong command clear events (Should be :clear )"); + } +} From 12a64a5df96de5373b19cced84c76ff13c951c12 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 12 Mar 2020 09:51:25 +0800 Subject: [PATCH 068/435] Completed custom exceptions for event commands --- src/main/java/command/ClearCommand.java | 2 +- src/main/java/command/CountdownCommand.java | 5 +++-- src/main/java/command/DeleteCommand.java | 7 ++++--- src/main/java/command/HelpCommand.java | 2 +- src/main/java/command/PriorityViewCommand.java | 5 +++-- src/main/java/command/SearchCommand.java | 3 ++- src/main/java/command/ViewCommand.java | 5 +++-- .../command/DeleteCommandMissingIndexException.java | 9 +++++++++ .../exception/command/IndexNotIntegerException.java | 10 ++++++++++ .../command/MisuseOfCountdownCommandException.java | 9 +++++++++ .../command/MisuseOfPriorityCommandException.java | 9 +++++++++ .../command/MisuseOfViewCommandException.java | 9 +++++++++ .../exception/command/SearchMissingTermsException.java | 9 +++++++++ 13 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 src/main/java/exception/command/DeleteCommandMissingIndexException.java create mode 100644 src/main/java/exception/command/IndexNotIntegerException.java create mode 100644 src/main/java/exception/command/MisuseOfCountdownCommandException.java create mode 100644 src/main/java/exception/command/MisuseOfPriorityCommandException.java create mode 100644 src/main/java/exception/command/MisuseOfViewCommandException.java create mode 100644 src/main/java/exception/command/SearchMissingTermsException.java diff --git a/src/main/java/command/ClearCommand.java b/src/main/java/command/ClearCommand.java index 86999dbb0..205113ef3 100644 --- a/src/main/java/command/ClearCommand.java +++ b/src/main/java/command/ClearCommand.java @@ -23,7 +23,7 @@ public ClearCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList, Ui ui) throws Exception { + public void executeCommand(EventList eventList, Ui ui) { eventList.clearEvents(ui); } } diff --git a/src/main/java/command/CountdownCommand.java b/src/main/java/command/CountdownCommand.java index 97091ec66..dfcf09976 100644 --- a/src/main/java/command/CountdownCommand.java +++ b/src/main/java/command/CountdownCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import exception.command.MisuseOfCountdownCommandException; import ui.Ui; /** @@ -17,12 +18,12 @@ public class CountdownCommand extends Command { */ public CountdownCommand(boolean isOneWordCommand) throws Exception { if (!isOneWordCommand) { - throw new Exception("Wrong command used to view countdown of events (Should be :countdown )"); + throw new MisuseOfCountdownCommandException(); } } @Override - public void executeCommand(EventList eventList, Ui ui) throws Exception { + public void executeCommand(EventList eventList, Ui ui) { eventList.countdownView(ui); } } diff --git a/src/main/java/command/DeleteCommand.java b/src/main/java/command/DeleteCommand.java index c8cf94c76..288c73b2c 100644 --- a/src/main/java/command/DeleteCommand.java +++ b/src/main/java/command/DeleteCommand.java @@ -1,6 +1,8 @@ package command; import event.EventList; +import exception.command.DeleteCommandMissingIndexException; +import exception.command.IndexNotIntegerException; import ui.Ui; /** @@ -21,13 +23,12 @@ public class DeleteCommand extends Command { */ public DeleteCommand(String[] commandSplit, boolean isOneWordCommand) throws Exception { if (isOneWordCommand) { - throw new Exception("Index to delete not mentioned"); + throw new DeleteCommandMissingIndexException(); } try { indexToDelete = Integer.parseInt(commandSplit[1]); } catch (NumberFormatException e) { - throw new Exception("Enter a valid integer index (1-based) to delete the corresponding event " - + "(format: delete index)"); + throw new IndexNotIntegerException(); } } diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java index e51656248..97d94d98c 100644 --- a/src/main/java/command/HelpCommand.java +++ b/src/main/java/command/HelpCommand.java @@ -22,7 +22,7 @@ public HelpCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList, Ui ui) throws Exception { + public void executeCommand(EventList eventList, Ui ui) { ui.printHelp(); } } diff --git a/src/main/java/command/PriorityViewCommand.java b/src/main/java/command/PriorityViewCommand.java index 33be48340..0b18a3b3d 100644 --- a/src/main/java/command/PriorityViewCommand.java +++ b/src/main/java/command/PriorityViewCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import exception.command.MisuseOfPriorityCommandException; import ui.Ui; /** @@ -17,12 +18,12 @@ public class PriorityViewCommand extends Command { */ public PriorityViewCommand(boolean isOneWordCommand) throws Exception { if (!isOneWordCommand) { - throw new Exception("Wrong command used to view events sorted by priority (Should be :priority_view )"); + throw new MisuseOfPriorityCommandException(); } } @Override - public void executeCommand(EventList eventList, Ui ui) throws Exception { + public void executeCommand(EventList eventList, Ui ui) { eventList.priorityView(ui); } } diff --git a/src/main/java/command/SearchCommand.java b/src/main/java/command/SearchCommand.java index bfde00d87..9a3df95fb 100644 --- a/src/main/java/command/SearchCommand.java +++ b/src/main/java/command/SearchCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import exception.command.SearchMissingTermsException; import ui.Ui; /** @@ -21,7 +22,7 @@ public class SearchCommand extends Command { */ public SearchCommand(String[] commandSplit, boolean isOneWordCommand) throws Exception { if (isOneWordCommand) { - throw new Exception("The search string entered is empty."); + throw new SearchMissingTermsException(); } this.keyword = commandSplit[1]; } diff --git a/src/main/java/command/ViewCommand.java b/src/main/java/command/ViewCommand.java index a46bea7df..9d7fa3b0e 100644 --- a/src/main/java/command/ViewCommand.java +++ b/src/main/java/command/ViewCommand.java @@ -1,6 +1,7 @@ package command; import event.EventList; +import exception.command.MisuseOfViewCommandException; import ui.Ui; /** @@ -17,12 +18,12 @@ public class ViewCommand extends Command { */ public ViewCommand(boolean isOneWordCommand) throws Exception { if (!isOneWordCommand) { - throw new Exception("Wrong command used to view events (Should be :view )"); + throw new MisuseOfViewCommandException(); } } @Override - public void executeCommand(EventList eventList, Ui ui) throws Exception { + public void executeCommand(EventList eventList, Ui ui) { eventList.listEvents(ui); } } diff --git a/src/main/java/exception/command/DeleteCommandMissingIndexException.java b/src/main/java/exception/command/DeleteCommandMissingIndexException.java new file mode 100644 index 000000000..28b55cc79 --- /dev/null +++ b/src/main/java/exception/command/DeleteCommandMissingIndexException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class DeleteCommandMissingIndexException extends CustomException { + public DeleteCommandMissingIndexException() { + super("Index to delete not mentioned"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/IndexNotIntegerException.java b/src/main/java/exception/command/IndexNotIntegerException.java new file mode 100644 index 000000000..bdb86ccac --- /dev/null +++ b/src/main/java/exception/command/IndexNotIntegerException.java @@ -0,0 +1,10 @@ +package exception.command; + +import exception.CustomException; + +public class IndexNotIntegerException extends CustomException { + public IndexNotIntegerException() { + super("Enter a valid integer index (1-based) to delete the corresponding event \"\n" + + " + \"(format: delete index)"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/MisuseOfCountdownCommandException.java b/src/main/java/exception/command/MisuseOfCountdownCommandException.java new file mode 100644 index 000000000..c44fed743 --- /dev/null +++ b/src/main/java/exception/command/MisuseOfCountdownCommandException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class MisuseOfCountdownCommandException extends CustomException { + public MisuseOfCountdownCommandException() { + super("Wrong command used to view countdown of events (Should be :countdown )"); + } +} diff --git a/src/main/java/exception/command/MisuseOfPriorityCommandException.java b/src/main/java/exception/command/MisuseOfPriorityCommandException.java new file mode 100644 index 000000000..ddd7da292 --- /dev/null +++ b/src/main/java/exception/command/MisuseOfPriorityCommandException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class MisuseOfPriorityCommandException extends CustomException { + public MisuseOfPriorityCommandException() { + super("Wrong command used to view events sorted by priority (Should be :priority_view )"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/MisuseOfViewCommandException.java b/src/main/java/exception/command/MisuseOfViewCommandException.java new file mode 100644 index 000000000..a9a69a27a --- /dev/null +++ b/src/main/java/exception/command/MisuseOfViewCommandException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class MisuseOfViewCommandException extends CustomException { + public MisuseOfViewCommandException() { + super("Wrong command used to view events (Should be :view )"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/SearchMissingTermsException.java b/src/main/java/exception/command/SearchMissingTermsException.java new file mode 100644 index 000000000..ab181ebe3 --- /dev/null +++ b/src/main/java/exception/command/SearchMissingTermsException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class SearchMissingTermsException extends CustomException { + public SearchMissingTermsException() { + super("The search string entered is empty."); + } +} \ No newline at end of file From 68f9b13a92bcf2989705244673048cb4264242e0 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 12 Mar 2020 09:57:58 +0800 Subject: [PATCH 069/435] Fix tests fail --- src/main/java/exception/command/IndexNotIntegerException.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/exception/command/IndexNotIntegerException.java b/src/main/java/exception/command/IndexNotIntegerException.java index bdb86ccac..ffce7d2ff 100644 --- a/src/main/java/exception/command/IndexNotIntegerException.java +++ b/src/main/java/exception/command/IndexNotIntegerException.java @@ -4,7 +4,7 @@ public class IndexNotIntegerException extends CustomException { public IndexNotIntegerException() { - super("Enter a valid integer index (1-based) to delete the corresponding event \"\n" + - " + \"(format: delete index)"); + super("Enter a valid integer index (1-based) to delete the corresponding event " + + "(format: delete index)"); } } \ No newline at end of file From 8ad9c7be6a7c162b0c4781d8c3ac1b953a76f9a0 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 12 Mar 2020 10:36:00 +0800 Subject: [PATCH 070/435] Add tests for StudyAreaList --- src/test/java/studyarea/StudyAreaListTest.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/test/java/studyarea/StudyAreaListTest.java diff --git a/src/test/java/studyarea/StudyAreaListTest.java b/src/test/java/studyarea/StudyAreaListTest.java new file mode 100644 index 000000000..8a69dea25 --- /dev/null +++ b/src/test/java/studyarea/StudyAreaListTest.java @@ -0,0 +1,5 @@ +import static org.junit.jupiter.api.Assertions.*; + +class StudyAreaListTest { + +} \ No newline at end of file From e0e908a53fb819687983f3efc6d7381b0e0b694b Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Thu, 12 Mar 2020 10:42:53 +0800 Subject: [PATCH 071/435] Fix error --- src/main/java/studyarea/StudyAreaList.java | 6 ++-- .../java/studyarea/StudyAreaListTest.java | 36 ++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 20439f550..99e258789 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -11,7 +11,7 @@ public class StudyAreaList { private ArrayList studyAreaList; // Assigns studyAreaList into object's studyAreaList. - public StudyAreaList(ArrayList studyAreaList) { + public StudyAreaList(ArrayList studyAreaList) { this.studyAreaList = studyAreaList; } @@ -30,7 +30,7 @@ public ArrayList getStudyAreaList() { * @param index this is the index referring to the specific flag to check for duplicate. * @throws IllegalStudyAreaException if flag is not null, ie: if flag has already been mentioned. */ - public void checkDuplicate(String[] flag, int index) throws IllegalStudyAreaException { + public static void checkDuplicate(String[] flag, int index) throws IllegalStudyAreaException { if (flag[index] != null) { throw new IllegalStudyAreaException(Ui.DUPLICATE_FLAGS); } @@ -43,7 +43,7 @@ public void checkDuplicate(String[] flag, int index) throws IllegalStudyAreaExce * @throws IllegalStudyAreaException if only flag is entered by user. */ - public void checkOnlyFlag(String[] commands, int index) throws IllegalStudyAreaException { + public static void checkOnlyFlag(String[] commands, int index) throws IllegalStudyAreaException { if (commands[index].length() == 1) { throw new IllegalStudyAreaException(Ui.ONLY_FLAG); } diff --git a/src/test/java/studyarea/StudyAreaListTest.java b/src/test/java/studyarea/StudyAreaListTest.java index 8a69dea25..62943e298 100644 --- a/src/test/java/studyarea/StudyAreaListTest.java +++ b/src/test/java/studyarea/StudyAreaListTest.java @@ -1,5 +1,39 @@ -import static org.junit.jupiter.api.Assertions.*; +package studyarea; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + class StudyAreaListTest { + // An exception pertaining to duplicate flag should be raised if the location at flag[index] is not null. + @Test + void checkDuplicate_gotDuplicate_raiseException() { + String[] flag = {"-a", "-b"}; + Assertions.assertThrows(IllegalStudyAreaException.class, () -> StudyAreaList.checkDuplicate(flag, 0)); + } + + // An exception pertaining to flag missing hyphen should be raised when flag has no hyphen. + @Test + void checkOnlyFlag_withoutHyphenSign_raiseException() { + String[] commands = {"f"}; + Assertions.assertThrows(IllegalStudyAreaException.class, () -> StudyAreaList.checkOnlyFlag(commands, 0)); + + } + + @Test + void checkFlag() { + } + + @Test + void getFlagsInfo() { + } + + @Test + void containsKey() { + } + + @Test + void searchList() { + } } \ No newline at end of file From 883bc1e033026e139d8be8a4aebe7c90cafe51a1 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Thu, 12 Mar 2020 22:12:58 +0800 Subject: [PATCH 072/435] Stop tracking ACTUAL.TXT --- text-ui-test/ACTUAL.TXT | 47 ----------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 text-ui-test/ACTUAL.TXT diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT deleted file mode 100644 index 0a7d67f55..000000000 --- a/text-ui-test/ACTUAL.TXT +++ /dev/null @@ -1,47 +0,0 @@ -Hello from -_______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ -______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ -_____/\\\/__\///\\\____________________/\\\\\\\\___________________\/\\\/\\\__\/\\\___/\\\__________________________________/\\\\\\\\\_______ -_____/\\\______\//\\\___/\\/\\\\\\\____/\\\////\\\___/\\\\\\\\\_____\/\\\//\\\_\/\\\__\///_______/\\\\\\\\______/\\\\\\\\___\//\\\\\\\_______ -_____\/\\\_______\/\\\__\/\\\/////\\\__\//\\\\\\\\\__\////////\\\____\/\\\\//\\\\/\\\___/\\\____/\\\//////_____/\\\/////\\\___\//\\\\\_______ -______\//\\\______/\\\___\/\\\___\///____\///////\\\____/\\\\\\\\\\___\/\\\_\//\\\/\\\__\/\\\___/\\\___________/\\\\\\\\\\\_____\//\\\_______ -________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\//\\\\\\__\/\\\__\//\\\_________\//\\///////_______\///_______ -____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ -______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ -What is your name? -____________________________________________________________________________________ -____________________________________________________________________________________ - Hello James Gosling! - Welcome to OrgaNice! To start, enter "event" to start - your event list! If you are in the mood to mug and you - want to start your study area list, enter "study" !If - you want to exit, enter "bye" ! -____________________________________________________________________________________ -____________________________________________________________________________________ - Goodbye! Hope to see you again! - `````````````````````````````````````````````````````````` - ````````````````````````````````:v(v'````````````````````` - ```````````````````````````,)4|ex` `L}```````````````````` - `````````````````````````!s"'h `M: ^z_;)T``````````````` - `````````````````````````Z u|}Z: "}`````````````` - ``````````````````````:=?) 'B?L'``````````` - `````````````````````'Z ;Yp"``````````` - `````````````````````.e ?_``````````` - ```````````````````'QDGH .5```````````` - ````````````````````I#g' '_` ||```````````` - ```````````:mX_``````YhL` `'q!` ? h```````````` - ```````````'Qbs)|L=_V" 'Y} ^'q@&b=c=_` ,Z```````````` - ````````````q> 'T, ,o" ;"@c. .sVx~````````````` - ````````````c! "bh` `,p z:`````````````` - `````````````q. ngDQmh8s X'`````````````` - ``````````````LY" :n}>``b; _V``````````````` - ````````````````q?, ?; "V```````````````` - ``````````````KvR ' )x_````````````````` - ``````````````zjL GLY"``````````````````` - ```````````````M .I)`````````````````````` - ```````````````Lz `D:`````````````````````` - ``````````````vu` (I)_;"". P.````````````````````` - ``````````````p :X.':^,"=n "q`````````````````````` - `````````````)0X?^:)I````````m' :j`````````````````````` - `````````````.IGD8k'`````````<&G55M``````````````````````` - `````````````````````````````````````````````````````````` From 77182373dba599dd1d3f0fe7f3615e0e121910cf Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Thu, 12 Mar 2020 22:15:27 +0800 Subject: [PATCH 073/435] Modify javadoc comments --- src/main/java/event/EventList.java | 1 - src/main/java/resourceloader/StudyAreaLoader.java | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index f566ec8b4..7b454a182 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -75,7 +75,6 @@ public void listEvents(Ui ui) { * * @param ui This allows Event List class to interact with User. * @param index The index (1-based) of the event to be deleted. - * @throws Exception If the index specified is invalid. */ public void deleteEvent(int index, Ui ui) { ui.printLine(); diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index 8bdbe08a2..92b489c0e 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -24,6 +24,7 @@ public StudyAreaLoader(String url) throws IllegalStudyAreaException { /** * Loads url into file. + * @throws IllegalStudyAreaException If study area data file is missing. */ public void loadFile() throws IllegalStudyAreaException { try { From 73730d85b18e79c79ae45227c5d1f5e73a9221f4 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Thu, 12 Mar 2020 22:15:41 +0800 Subject: [PATCH 074/435] Remove empty lines --- text-ui-test/runtest.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/text-ui-test/runtest.sh b/text-ui-test/runtest.sh index 230bef79e..8d94369a0 100755 --- a/text-ui-test/runtest.sh +++ b/text-ui-test/runtest.sh @@ -6,8 +6,6 @@ cd "${0%/*}" cd .. ./gradlew shadowJar - - cd text-ui-test java -jar $(find ../build/libs/ -mindepth 1 -print -quit) < input.txt > ACTUAL.TXT From a8c5df746860e5adf729fa7ed7403746df629047 Mon Sep 17 00:00:00 2001 From: Terry Tay Hoe Kiat Date: Fri, 13 Mar 2020 16:39:58 +0800 Subject: [PATCH 075/435] Finish StudyAreaListTest --- src/main/java/studyarea/StudyAreaList.java | 2 +- .../java/studyarea/StudyAreaListTest.java | 39 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 99e258789..4e1b1ce8a 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -58,7 +58,7 @@ public static void checkOnlyFlag(String[] commands, int index) throws IllegalStu * @param isNotFlag this is the boolean value that checks if the command entered is a flag. * @throws IllegalStudyAreaException if user enters command wrongly. */ - public void checkFlag(String[] flags, String[] commands, int index, boolean isNotFlag) throws + public static void checkFlag(String[] flags, String[] commands, int index, boolean isNotFlag) throws IllegalStudyAreaException { if (commands[index].equals(Ui.SIZE_FLAG)) { diff --git a/src/test/java/studyarea/StudyAreaListTest.java b/src/test/java/studyarea/StudyAreaListTest.java index 62943e298..96e0eeb4e 100644 --- a/src/test/java/studyarea/StudyAreaListTest.java +++ b/src/test/java/studyarea/StudyAreaListTest.java @@ -5,35 +5,38 @@ class StudyAreaListTest { - - // An exception pertaining to duplicate flag should be raised if the location at flag[index] is not null. + /** + * An exception pertaining to duplicate flag should be raised if the location at flag[index] is not null. + * A dummy array of flags is created, and the first flag is assessed and used it to check duplicate + * in the same location. The expected outcome is to return an exception since the location contains null. + */ @Test void checkDuplicate_gotDuplicate_raiseException() { String[] flag = {"-a", "-b"}; Assertions.assertThrows(IllegalStudyAreaException.class, () -> StudyAreaList.checkDuplicate(flag, 0)); } - // An exception pertaining to flag missing hyphen should be raised when flag has no hyphen. + /** + * An exception pertaining to flag missing hyphen should be raised when flag has no hyphen. + * A dummy array is made with a flag inside that has no hyphen character. The expected outcome is to return + * an exception since the input flag has no hyphen. + */ @Test void checkOnlyFlag_withoutHyphenSign_raiseException() { - String[] commands = {"f"}; + String[] commands = {"s"}; Assertions.assertThrows(IllegalStudyAreaException.class, () -> StudyAreaList.checkOnlyFlag(commands, 0)); - - } - - @Test - void checkFlag() { - } - - @Test - void getFlagsInfo() { - } - - @Test - void containsKey() { } + /** + * An exception pertaining to either wrong flag position or invalid flag is raised when user + * enters a flag that does not exist or user enters the flag before the search terms. + * The expected outcome is to return an exception as this test case inputs an invalid flag. + */ @Test - void searchList() { + void checkFlag_FlagDoesNotExist_raiseException() { + String[] commands = {"MacCommons", "-z"}; + String[] flags = {}; + Assertions.assertThrows(IllegalStudyAreaException.class, () -> StudyAreaList.checkFlag(flags, commands, + 1, false)); } } \ No newline at end of file From e5f1822a25842a9b9ba25d1efdc457eb6ed30d44 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Fri, 13 Mar 2020 22:31:33 +0800 Subject: [PATCH 076/435] Add Task Class and support for Deadlines --- library/eventList.txt | 0 library/taskList.txt | 2 + src/main/java/command/AddDeadlineCommand.java | 42 +++ .../{AddCommand.java => AddEventCommand.java} | 14 +- src/main/java/command/ClearCommand.java | 8 +- src/main/java/command/Command.java | 6 +- src/main/java/command/CountdownCommand.java | 8 +- src/main/java/command/DeleteCommand.java | 10 +- src/main/java/command/EventCommand.java | 12 +- src/main/java/command/HelpCommand.java | 4 +- .../java/command/PriorityViewCommand.java | 8 +- src/main/java/command/SearchCommand.java | 8 +- src/main/java/command/ViewCommand.java | 8 +- src/main/java/deadline/DeadlineList.java | 180 ------------- src/main/java/event/EventList.java | 202 --------------- src/main/java/parser/Parser.java | 13 +- src/main/java/resourceloader/EventLoader.java | 114 --------- src/main/java/resourceloader/TaskLoader.java | 160 ++++++++++++ src/main/java/seedu/duke/Duke.java | 23 +- src/main/java/task/Task.java | 17 ++ src/main/java/task/TaskList.java | 241 +++++++++++++++++- src/main/java/task/TaskType.java | 5 + .../java/{ => task}/deadline/Deadline.java | 15 +- src/main/java/{ => task}/event/Event.java | 15 +- src/main/java/ui/Ui.java | 16 +- src/test/java/parser/ParserTest.java | 13 +- .../event/TaskListTest.java} | 20 +- .../event/TaskTest.java} | 10 +- text-ui-test/EXPECTED.TXT | 117 ++++++++- text-ui-test/input.txt | 18 ++ text-ui-test/library/eventList.txt | 0 text-ui-test/library/taskList.txt | 2 + 32 files changed, 706 insertions(+), 605 deletions(-) delete mode 100644 library/eventList.txt create mode 100644 library/taskList.txt create mode 100644 src/main/java/command/AddDeadlineCommand.java rename src/main/java/command/{AddCommand.java => AddEventCommand.java} (74%) delete mode 100644 src/main/java/deadline/DeadlineList.java delete mode 100644 src/main/java/event/EventList.java delete mode 100644 src/main/java/resourceloader/EventLoader.java create mode 100644 src/main/java/resourceloader/TaskLoader.java create mode 100644 src/main/java/task/Task.java create mode 100644 src/main/java/task/TaskType.java rename src/main/java/{ => task}/deadline/Deadline.java (89%) rename src/main/java/{ => task}/event/Event.java (89%) rename src/test/java/{event/EventListTest.java => task/event/TaskListTest.java} (67%) rename src/test/java/{event/EventTest.java => task/event/TaskTest.java} (93%) delete mode 100644 text-ui-test/library/eventList.txt create mode 100644 text-ui-test/library/taskList.txt diff --git a/library/eventList.txt b/library/eventList.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/library/taskList.txt b/library/taskList.txt new file mode 100644 index 000000000..be12e1d39 --- /dev/null +++ b/library/taskList.txt @@ -0,0 +1,2 @@ +E#school #2020-05-05#12:12#13:12#2 +D#asfdafs #2020-05-06#12:13#1 diff --git a/src/main/java/command/AddDeadlineCommand.java b/src/main/java/command/AddDeadlineCommand.java new file mode 100644 index 000000000..6e6497fbc --- /dev/null +++ b/src/main/java/command/AddDeadlineCommand.java @@ -0,0 +1,42 @@ +package command; + +import exception.command.EventDetailsNotProvidedException; +import task.deadline.Deadline; +import task.event.Event; +import task.event.TaskList; +import ui.Ui; + +/** + * This command is used to add new deadlines to the Tasklist. + */ +public class AddDeadlineCommand extends Command { + + /** The new event to be added. */ + Deadline newDeadline; + + /** + * Constructor for the AddCommand Object. + * Abstracts out the details from the user input and uses it to create a new deadline object. + * + * @param deadlineDetails The array contains the information regarding the new deadline to be added. + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the wrong format is used to create an event. + */ + public AddDeadlineCommand(String[] deadlineDetails, boolean isOneWordCommand) throws Exception { + if (isOneWordCommand) { + throw new EventDetailsNotProvidedException(); + } + String[] details = deadlineDetails[1].split("/"); + String description = details[0]; + String date = details[1].substring(2); + String dueTime = details[2].substring(2); + String priority = details[3].substring(2); + newDeadline = new Deadline(description, date, dueTime, priority); + } + + @Override + public void executeCommand(TaskList taskList, Ui ui) throws Exception { + taskList.addTask(newDeadline, ui); + } + +} diff --git a/src/main/java/command/AddCommand.java b/src/main/java/command/AddEventCommand.java similarity index 74% rename from src/main/java/command/AddCommand.java rename to src/main/java/command/AddEventCommand.java index c0d97c0ad..5b028594a 100644 --- a/src/main/java/command/AddCommand.java +++ b/src/main/java/command/AddEventCommand.java @@ -1,14 +1,14 @@ package command; -import event.Event; -import event.EventList; +import task.event.Event; import exception.command.EventDetailsNotProvidedException; +import task.event.TaskList; import ui.Ui; /** - * This command is used to add new events to the event list. + * This command is used to add new events to the Tasklist. */ -public class AddCommand extends Command { +public class AddEventCommand extends Command { /** The new event to be added. */ Event newEvent; @@ -21,7 +21,7 @@ public class AddCommand extends Command { * @param isOneWordCommand Denotes whether the user given input is single or multi worded. * @throws Exception If the wrong format is used to create an event. */ - public AddCommand(String[] eventDetails, boolean isOneWordCommand) throws Exception { + public AddEventCommand(String[] eventDetails, boolean isOneWordCommand) throws Exception { if (isOneWordCommand) { throw new EventDetailsNotProvidedException(); } @@ -36,8 +36,8 @@ public AddCommand(String[] eventDetails, boolean isOneWordCommand) throws Except } @Override - public void executeCommand(EventList eventList, Ui ui) { - eventList.addEvent(newEvent, ui); + public void executeCommand(TaskList taskList, Ui ui) throws Exception { + taskList.addTask(newEvent, ui); } } diff --git a/src/main/java/command/ClearCommand.java b/src/main/java/command/ClearCommand.java index 205113ef3..786c8a1c0 100644 --- a/src/main/java/command/ClearCommand.java +++ b/src/main/java/command/ClearCommand.java @@ -1,11 +1,11 @@ package command; -import event.EventList; import exception.command.MisuseOfClearCommandException; +import task.event.TaskList; import ui.Ui; /** - * This command is used to clear all the events in the list. + * This command is used to clear all the tasks in the list. */ public class ClearCommand extends Command { @@ -23,7 +23,7 @@ public ClearCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList, Ui ui) { - eventList.clearEvents(ui); + public void executeCommand(TaskList taskList, Ui ui) { + taskList.clearTasks(ui); } } diff --git a/src/main/java/command/Command.java b/src/main/java/command/Command.java index 1eb9f5f10..361ce1afc 100644 --- a/src/main/java/command/Command.java +++ b/src/main/java/command/Command.java @@ -1,6 +1,6 @@ package command; -import event.EventList; +import task.event.TaskList; import ui.Ui; /** @@ -11,10 +11,10 @@ public abstract class Command { /** * Executes the command based on the information provided by the user. * - * @param eventList Contains the list of tasks on which the commands are executed on. + * @param taskList Contains the list of tasks on which the commands are executed on. * @param ui This handles the interaction with Users. * @throws Exception If issues are found during execution of command. */ - public abstract void executeCommand(EventList eventList, Ui ui) throws Exception; + public abstract void executeCommand(TaskList taskList, Ui ui) throws Exception; } diff --git a/src/main/java/command/CountdownCommand.java b/src/main/java/command/CountdownCommand.java index dfcf09976..ba2380881 100644 --- a/src/main/java/command/CountdownCommand.java +++ b/src/main/java/command/CountdownCommand.java @@ -1,11 +1,11 @@ package command; -import event.EventList; import exception.command.MisuseOfCountdownCommandException; +import task.event.TaskList; import ui.Ui; /** - * Displays the list of events added so far in increasing order of their dates. + * Displays the list of tasks added so far in increasing order of their dates. */ public class CountdownCommand extends Command { @@ -23,7 +23,7 @@ public CountdownCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList, Ui ui) { - eventList.countdownView(ui); + public void executeCommand(TaskList taskList, Ui ui) { + taskList.countdownView(ui); } } diff --git a/src/main/java/command/DeleteCommand.java b/src/main/java/command/DeleteCommand.java index 288c73b2c..0c53ed497 100644 --- a/src/main/java/command/DeleteCommand.java +++ b/src/main/java/command/DeleteCommand.java @@ -1,12 +1,12 @@ package command; -import event.EventList; import exception.command.DeleteCommandMissingIndexException; import exception.command.IndexNotIntegerException; +import task.event.TaskList; import ui.Ui; /** - * Command is used to delete an event at a specific index. + * Command is used to delete a task at a specific index. */ public class DeleteCommand extends Command { @@ -15,7 +15,7 @@ public class DeleteCommand extends Command { /** * Constructor for the DeleteCommand object. - * Creates a new object if the correct command is used. + * Creates a new DeleteCommand object if the correct command is used. * * @param commandSplit Contains information with regards to the index to be deleted at. * @param isOneWordCommand Denotes whether the user given input is single or multi worded. @@ -34,7 +34,7 @@ public DeleteCommand(String[] commandSplit, boolean isOneWordCommand) throws Exc @Override - public void executeCommand(EventList eventList, Ui ui) throws Exception { - eventList.deleteEvent(indexToDelete, ui); + public void executeCommand(TaskList taskList, Ui ui) throws Exception { + taskList.deleteTask(indexToDelete, ui); } } diff --git a/src/main/java/command/EventCommand.java b/src/main/java/command/EventCommand.java index 7eb0aec28..17ebb2dce 100644 --- a/src/main/java/command/EventCommand.java +++ b/src/main/java/command/EventCommand.java @@ -1,23 +1,23 @@ package command; -import event.EventList; import parser.Parser; +import task.event.TaskList; import ui.Ui; import static ui.Ui.BYE_COMMAND; /** - * Used to run all the functions related to events. + * Used to run all the functions related to tasks. */ public class EventCommand { /** - * Runs all the command for events. + * Runs all the command for tasks. * - * @param eventList Refers to the current list of events. + * @param taskList Refers to the current list of tasks. * @param ui UI object used to interact with user. * @param parser Object used to parse the user input into commands. */ - public static void runCommands(EventList eventList, Ui ui, Parser parser) { + public static void runCommands(TaskList taskList, Ui ui, Parser parser) { ui.printHelp(); String fullCommand; Command command; @@ -26,7 +26,7 @@ public static void runCommands(EventList eventList, Ui ui, Parser parser) { while (!fullCommand.equals(BYE_COMMAND)) { try { command = parser.parseCommand(fullCommand); - command.executeCommand(eventList, ui); + command.executeCommand(taskList, ui); } catch (Exception exception) { ui.printLine(); ui.printMessage(exception.getMessage()); diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java index 97d94d98c..df755864f 100644 --- a/src/main/java/command/HelpCommand.java +++ b/src/main/java/command/HelpCommand.java @@ -1,6 +1,6 @@ package command; -import event.EventList; +import task.event.TaskList; import ui.Ui; /** @@ -22,7 +22,7 @@ public HelpCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList, Ui ui) { + public void executeCommand(TaskList taskList, Ui ui) { ui.printHelp(); } } diff --git a/src/main/java/command/PriorityViewCommand.java b/src/main/java/command/PriorityViewCommand.java index 0b18a3b3d..6e911a8ef 100644 --- a/src/main/java/command/PriorityViewCommand.java +++ b/src/main/java/command/PriorityViewCommand.java @@ -1,11 +1,11 @@ package command; -import event.EventList; import exception.command.MisuseOfPriorityCommandException; +import task.event.TaskList; import ui.Ui; /** - * Displays the list of events added so far in decreasing order of their priority. + * Displays the list of tasks added so far in decreasing order of their priority. */ public class PriorityViewCommand extends Command { @@ -23,7 +23,7 @@ public PriorityViewCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList, Ui ui) { - eventList.priorityView(ui); + public void executeCommand(TaskList taskList, Ui ui) { + taskList.priorityView(ui); } } diff --git a/src/main/java/command/SearchCommand.java b/src/main/java/command/SearchCommand.java index 9a3df95fb..1bd9c07c5 100644 --- a/src/main/java/command/SearchCommand.java +++ b/src/main/java/command/SearchCommand.java @@ -1,11 +1,11 @@ package command; -import event.EventList; import exception.command.SearchMissingTermsException; +import task.event.TaskList; import ui.Ui; /** - * Command used to perform a search of events whose description contain the keyword mentioned. + * Command used to perform a search of tasks whose description contain the keyword mentioned. */ public class SearchCommand extends Command { @@ -28,7 +28,7 @@ public SearchCommand(String[] commandSplit, boolean isOneWordCommand) throws Exc } @Override - public void executeCommand(EventList eventList, Ui ui) throws Exception { - eventList.searchEvents(keyword, ui); + public void executeCommand(TaskList taskList, Ui ui) throws Exception { + taskList.searchTasks(keyword, ui); } } diff --git a/src/main/java/command/ViewCommand.java b/src/main/java/command/ViewCommand.java index 9d7fa3b0e..4469affef 100644 --- a/src/main/java/command/ViewCommand.java +++ b/src/main/java/command/ViewCommand.java @@ -1,11 +1,11 @@ package command; -import event.EventList; import exception.command.MisuseOfViewCommandException; +import task.event.TaskList; import ui.Ui; /** - * Displays the list of events added so far. + * Displays the list of tasks added so far. */ public class ViewCommand extends Command { @@ -23,7 +23,7 @@ public ViewCommand(boolean isOneWordCommand) throws Exception { } @Override - public void executeCommand(EventList eventList, Ui ui) { - eventList.listEvents(ui); + public void executeCommand(TaskList taskList, Ui ui) { + taskList.listTasks(ui); } } diff --git a/src/main/java/deadline/DeadlineList.java b/src/main/java/deadline/DeadlineList.java deleted file mode 100644 index 78a987d8c..000000000 --- a/src/main/java/deadline/DeadlineList.java +++ /dev/null @@ -1,180 +0,0 @@ -package deadline; - -import java.time.format.DateTimeParseException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import ui.Ui; - -/** - * Handles all functions related to the list of deadlines. - */ -public class DeadlineList { - - - /** Stores the deadline information. */ - public ArrayList deadlines; - - /** - * Constructor for the DeadlineList class. - */ - public DeadlineList() { - deadlines = new ArrayList(); - } - - public DeadlineList(ArrayList deadlines) { - this.deadlines = deadlines; - } - - /** - * Adds a new deadline to the list. - * - * @param newDeadline Deadline represents the new deadline tot be added. - * @param ui This allows for the deadline class to interact with Users. - */ - public void addDeadline(Deadline newDeadline, Ui ui) { - ui.printLine(); - deadlines.add(newDeadline); - ui.printMessage("A new deadline with the following information has been added."); - ui.printMessage(newDeadline.getDeadlineInformation()); - ui.printLine(); - } - - /** - * Displays the current list of deadlines. - * @param ui This allows for the deadline class to interact with Users. - */ - public void listDeadlines(Ui ui) { - ui.printLine(); - System.out.println("Here is the list of deadlines added so far:"); - int deadlineNumber = 1; - for (Deadline deadline: deadlines) { - ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); - deadlineNumber++; - } - ui.printLine(); - } - - /** - * Deletes the deadline at the specified index. - * - * @param index The index (1-based) of the deadline to be deleted. - * @param ui This allows for the deadline class to interact with Users. - */ - public void deleteDeadline(int index, Ui ui) { - try { - deadlines.remove(index - 1); - ui.printLine(); - ui.printMessage("The deadline at the mentioned index has been deleted"); - ui.printLine(); - } catch (IndexOutOfBoundsException e) { - ui.printLine(); - ui.printMessage("Enter a valid index"); - ui.printLine(); - } - - } - - /** - * Clears all the deadlines currently stored. - * @param ui This allows for the deadline class to interact with Users. - */ - public void clearDeadlines(Ui ui) { - deadlines.clear(); - ui.printLine(); - ui.printMessage("The list of deadlines is cleared."); - ui.printLine(); - } - - /** - * Lists all the tasks sorted by their priority. - * @param ui This allows for the deadline class to interact with Users. - */ - public void priorityView(Ui ui) { - ArrayList deadlinesSortedByPriority = deadlines; - deadlinesSortedByPriority.sort(Comparator.comparingInt(Deadline::getPriority)); - Collections.reverse(deadlinesSortedByPriority); - ui.printLine(); - int deadlineNumber = 1; - for (Deadline deadline:deadlinesSortedByPriority) { - ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); - deadlineNumber++; - } - if (deadlineNumber == 1) { - ui.printMessage("The list is empty."); - } - ui.printLine(); - } - - /** - * Lists all the tasks sorted by date along with the days remaining. - * @param ui This allows for the deadline class to interact with Users. - */ - public void countdownView(Ui ui) { - ArrayList deadlinesSortedByDate = deadlines; - deadlinesSortedByDate.sort(Comparator.comparing(Deadline::getDate)); - ui.printLine(); - int deadlineNumber = 1; - for (Deadline deadline:deadlinesSortedByDate) { - ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); - deadlineNumber++; - } - if (deadlineNumber == 1) { - ui.printMessage("The list is empty."); - } - ui.printLine(); - } - - /** - * Displays the list of deadlines containing the keyword. - * - * @param keyword The keyword to be searched for. - * @param ui This allows for the deadline class to interact with Users. - */ - public void searchDeadlines(String keyword, Ui ui) { - ui.printLine(); - int deadlineNumber = 1; - for (Deadline deadline:deadlines) { - try { - if (deadline.hasKeyword(keyword)) { - ui.printMessage(deadlineNumber + ") " + deadline.getDeadlineInformation()); - deadlineNumber++; - } - } catch (Exception e) { - e.printStackTrace(); - } - } - if (deadlineNumber == 1) { - ui.printMessage("The list is empty."); - } - ui.printLine(); - } - - /** - * Adds a new deadline to the list by parsing information from the user given string - * and calling {@link #addDeadline(Deadline, Ui)} if the information is given in the correct format - * to add the deadline. - * - * @param deadlineDetails Contains all the information related to the deadline as provided by the user. - * @param ui This allows for the deadline class to interact with Users. - */ - public void add(String deadlineDetails, Ui ui) { - try { - String[] details = deadlineDetails.split(" ",2)[1].split("/"); - String description = details[0]; - String date = details[1].substring(2); - String dueTime = details[2].substring(2); - String priority = details[3].substring(2); - Deadline newDeadline = new Deadline(description,date,dueTime, priority); - addDeadline(newDeadline, ui); - } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { - ui.printLine(); - ui.printMessage("Wrong format to add deadlines"); - ui.printLine(); - } catch (Exception e) { - ui.printLine(); - ui.printMessage(e.getMessage()); - ui.printLine(); - } - } -} \ No newline at end of file diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java deleted file mode 100644 index 7b454a182..000000000 --- a/src/main/java/event/EventList.java +++ /dev/null @@ -1,202 +0,0 @@ -package event; - -import java.time.format.DateTimeParseException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import ui.Ui; - -/** - * Handles all functions related to the list of events. - */ -public class EventList { - - - /** Stores the event information. */ - public ArrayList events; - - /** - * Constructor for the EventList class. - */ - public EventList() { - events = new ArrayList(); - } - - /** - * Overloaded constructor for EventList class. - * - * @param events The list of events the class's list of events is initialised with. - */ - public EventList(ArrayList events) { - this.events = events; - } - - /** - * Returns the number of events currently stored. - * - * @return The number of events stored currently. - */ - public int getEventListSize() { - return events.size(); - } - - /** - * Adds a new event to the list. - * - * @param ui This allows Event List class to interact with User. - * @param newEvent Event represents the new event tot be added. - */ - public void addEvent(Event newEvent, Ui ui) { - events.add(newEvent); - ui.printLine(); - ui.printMessage("A new event with the following information has been added."); - ui.printMessage(newEvent.getEventInformation()); - ui.printLine(); - } - - /** - * Displays the current list of events. - * - * @param ui This allows Event List class to interact with User. - */ - public void listEvents(Ui ui) { - ui.printLine(); - ui.printMessage("Here is the list of events added so far:"); - int eventNumber = 1; - for (Event event: events) { - ui.printMessage(eventNumber + ") " + event.getEventInformation()); - eventNumber++; - } - ui.printLine(); - } - - /** - * Deletes the event at the specified index. - * - * @param ui This allows Event List class to interact with User. - * @param index The index (1-based) of the event to be deleted. - */ - public void deleteEvent(int index, Ui ui) { - ui.printLine(); - try { - if (index > events.size() | index <= 0) { - throw new IndexOutOfBoundsException(); - } - events.remove(index - 1); - ui.printLine(); - ui.printMessage("The event at the mentioned index has been deleted"); - ui.printLine(); - } catch (IndexOutOfBoundsException e) { - ui.printMessage("Invalid index entered. Please enter a valid index to be deleted"); - ui.printLine(); - } - - } - - /** - * Clears all the events currently stored. - * - * @param ui This allows Event List class to interact with User. - */ - public void clearEvents(Ui ui) { - events.clear(); - ui.printLine(); - ui.printMessage("The list of events is cleared."); - ui.printLine(); - } - - /** - * Lists all the tasks sorted by their priority. - * - * @param ui This allows Event List class to interact with User. - */ - public void priorityView(Ui ui) { - ArrayList eventsSortedByPriority = events; - eventsSortedByPriority.sort(Comparator.comparingInt(Event::getPriority)); - Collections.reverse(eventsSortedByPriority); - ui.printLine(); - int eventNumber = 1; - for (Event event:eventsSortedByPriority) { - ui.printMessage(eventNumber + ") " + event.getEventInformation()); - eventNumber++; - } - if (eventNumber == 1) { - ui.printMessage("The list is empty."); - } - ui.printLine(); - } - - /** - * Lists all the tasks sorted by date along with the days remaining. - * - * @param ui This allows Event List class to interact with User. - */ - public void countdownView(Ui ui) { - ArrayList eventsSortedByDate = events; - eventsSortedByDate.sort(Comparator.comparing(Event::getDate)); - ui.printLine(); - int eventNumber = 1; - for (Event event:eventsSortedByDate) { - ui.printMessage(eventNumber + ") " + event.getEventInformation()); - eventNumber++; - } - if (eventNumber == 1) { - ui.printMessage("The list is empty."); - } - ui.printLine(); - } - - /** - * Displays the list of events containing the keyword. - * - * @param ui This allows Event List class to interact with User. - * @param keyword The keyword to be searched for. - * @throws Exception If the keyword is empty. - */ - public void searchEvents(String keyword, Ui ui) throws Exception { - int eventNumber = 1; - ui.printLine(); - for (Event event:events) { - if (event.hasKeyword(keyword)) { - ui.printMessage(eventNumber + ") " + event.getEventInformation()); - eventNumber++; - } - } - if (eventNumber == 1) { - ui.printMessage("The list is empty."); - } - ui.printLine(); - } - - /** - * Adds a new event to the list by parsing information from the user given string - * and calling {@link #addEvent(Event, Ui)} if the information is given in the correct format - * to add the event. - * - * @param ui This allows Event List class to interact with User. - * @param eventDetails Contains all the information related to the event as provided by the user. - */ - public void add(String eventDetails, Ui ui) { - try { - String[] details = eventDetails.split(" ",2)[1].split("/"); - String description = details[0]; - String date = details[1].substring(2); - String startTime = details[2].substring(2); - String endTime = details[3].substring(2); - String priority = details[4].substring(2); - Event newEvent = new Event(description,date,startTime,endTime,priority); - addEvent(newEvent, ui); - } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { - ui.printLine(); - ui.printMessage("Wrong format to add events"); - ui.printLine(); - } catch (Exception e) { - ui.printLine(); - ui.printMessage(e.getMessage()); - ui.printLine(); - } - } - - - -} \ No newline at end of file diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java index 43e5b301b..967f59fb1 100644 --- a/src/main/java/parser/Parser.java +++ b/src/main/java/parser/Parser.java @@ -1,6 +1,7 @@ package parser; -import command.AddCommand; +import command.AddDeadlineCommand; +import command.AddEventCommand; import command.ClearCommand; import command.Command; import command.CountdownCommand; @@ -15,7 +16,8 @@ */ public class Parser { - public static final String ADD_COMMAND = "add"; + public static final String ADD_DEADLINE_COMMAND = "deadline"; + public static final String ADD_EVENT_COMMAND = "event"; public static final String VIEW_COMMAND = "view"; public static final String PRIORITY_VIEW_COMMAND = "priority_view"; public static final String COUNTDOWN_VIEW_COMMAND = "countdown"; @@ -38,8 +40,11 @@ public Command parseCommand(String fullCommand) throws Exception { Command command; boolean isOneWordCommand = commandSplit.length == 1 || commandSplit[1].isBlank(); switch (commandType) { - case ADD_COMMAND: - command = new AddCommand(commandSplit, isOneWordCommand); + case ADD_DEADLINE_COMMAND: + command = new AddDeadlineCommand(commandSplit, isOneWordCommand); + break; + case ADD_EVENT_COMMAND: + command = new AddEventCommand(commandSplit, isOneWordCommand); break; case VIEW_COMMAND: command = new ViewCommand(isOneWordCommand); diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java deleted file mode 100644 index 2e8bb85b5..000000000 --- a/src/main/java/resourceloader/EventLoader.java +++ /dev/null @@ -1,114 +0,0 @@ -package resourceloader; - -import event.Event; -import ui.Ui; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Scanner; - - -/** - * Handles the task of loading and storing events. - */ -public class EventLoader { - - /** Location of data file. */ - private String filePath; - /** Directory of data file. */ - private Path fileDirectory; - - /** - * Constructor for EventLoader object. - * Initialises the object with the file path provided. - * - * @param filePath The location of the data file. - */ - public EventLoader(String filePath) { - this.filePath = filePath; - this.fileDirectory = Paths.get(filePath).getParent(); - } - - - /** - * Reads the list of events stored previously and returns it as an ArrayList of Events. - * - * @return events The list of events stored previously. - */ - public ArrayList loadFile() { - ArrayList events = new ArrayList<>();; - File dataFile; - Scanner s; - Ui ui = new Ui(); - try { - dataFile = new File(filePath); - s = new Scanner(dataFile); - while (s.hasNext()) { - String eventDescription = s.nextLine(); - Event newEvent = parseEventDetails(eventDescription); - events.add(newEvent); - } - } catch (FileNotFoundException e) { - createNewDataFile(); - } catch (Exception e) { - ui.printLine(); - ui.printMessage(e.getMessage()); - ui.printLine(); - } - return events; - } - - /** - * Parses the Event details from the given string and returns a new event object with the specified details. - * - * @param taskDescription Contains all the details with regards to the Event. - * @return newEvent The new event created with the details provided. - */ - private Event parseEventDetails(String taskDescription) throws Exception { - String[] splitDescription = taskDescription.split("#", 5); - String description = splitDescription[0]; - String date = splitDescription[1]; - String startTime = splitDescription[2]; - String endTime = splitDescription[3]; - String priority = splitDescription[4]; - Event newEvent = new Event(description, date, startTime, endTime, priority); - return newEvent; - } - - - /** - * Creates a new data file when the application is run for the first time. - */ - private void createNewDataFile() { - try { - Files.createDirectories(fileDirectory); - Files.createFile(Paths.get(filePath)); - Files.createFile(Paths.get(Ui.FILE_PATH_STUDYAREAS)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Saves the list of current tasks to the data file. - * - * @param events Represents the current list of events. - */ - public void saveEvents(ArrayList events) { - try { - FileWriter fw = new FileWriter(filePath); - for (Event event: events) { - fw.write(event.getFormattedDetails()); - } - fw.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file diff --git a/src/main/java/resourceloader/TaskLoader.java b/src/main/java/resourceloader/TaskLoader.java new file mode 100644 index 000000000..5cfdd79ca --- /dev/null +++ b/src/main/java/resourceloader/TaskLoader.java @@ -0,0 +1,160 @@ +package resourceloader; + +import task.Task; +import task.deadline.Deadline; +import task.event.Event; +import ui.Ui; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Scanner; + +import static seedu.duke.Duke.FILE_PATH_STUDYAREAS; + + +/** + * Handles the task of loading and storing events. + */ +public class TaskLoader { + + /** Location of data file. */ + private String filePath; + /** Directory of data file. */ + private Path fileDirectory; + + /** + * Constructor for TaskLoader object. + * Initialises the object with the file path provided. + * + * @param filePath The location of the data file. + */ + public TaskLoader(String filePath) { + this.filePath = filePath; + this.fileDirectory = Paths.get(filePath).getParent(); + } + + + /** + * Reads the list of events stored previously and returns it as an ArrayList of Events. + * + * @return events The list of events stored previously. + */ + public ArrayList loadFile() { + ArrayList tasks = new ArrayList<>();; + File dataFile; + Scanner s; + Ui ui = new Ui(); + try { + dataFile = new File(filePath); + s = new Scanner(dataFile); + while (s.hasNext()) { + String details = s.nextLine(); + Task newTask = parseTaskDetails(details); + tasks.add(newTask); + } + } catch (FileNotFoundException e) { + createNewDataFile(); + } catch (Exception e) { + ui.printLine(); + ui.printMessage(e.getMessage()); + ui.printLine(); + } + return tasks; + } + + /** + * Parses the Task details from the given string and returns a new task object with the specified details. + * + * @param details Contains all the details with regards to the task. + * @return newTask The new task created with the details provided. + */ + private Task parseTaskDetails(String details) throws Exception { + Task newTask = null; + char taskType = details.charAt(0); + String taskDetails = details.substring(2); + switch (taskType) { + case 'D': + newTask = parseDeadlineDetails(taskDetails); + break; + case 'E': + newTask = parseEventDetails(taskDetails); + break; + default: + // Error handling + } + return newTask; + } + + + + /** + * Parses the Deadline details from the given string and returns a new deadline object with the specified details. + * + * @param taskDescription Contains all the details with regards to the deadline. + * @return newEvent The new event created with the details provided. + */ + private Deadline parseDeadlineDetails(String taskDescription) throws Exception { + String[] details = taskDescription.split("#", 5); + String description = details[0]; + String date = details[1]; + String dueTime = details[2]; + String priority = details[3]; + Deadline newDeadline = new Deadline(description, date, dueTime, priority); + return newDeadline; + } + + + /** + * Parses the Event details from the given string and returns a new event object with the specified details. + * + * @param taskDescription Contains all the details with regards to the Event. + * @return newEvent The new event created with the details provided. + */ + private Event parseEventDetails(String taskDescription) throws Exception { + String[] details = taskDescription.split("#", 5); + String description = details[0]; + String date = details[1]; + String startTime = details[2]; + String endTime = details[3]; + String priority = details[4]; + Event newEvent = new Event(description, date, startTime, endTime, priority); + return newEvent; + } + + + /** + * Creates a new data file when the application is run for the first time. + */ + private void createNewDataFile() { + try { + Files.createDirectories(fileDirectory); + Files.createFile(Paths.get(filePath)); + Files.createFile(Paths.get(FILE_PATH_STUDYAREAS)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Saves the list of current tasks to the data file. + * + * @param tasks Represents the current list of events. + */ + public void saveTasks(ArrayList tasks) { + try { + FileWriter fw = new FileWriter(filePath); + for (Task task: tasks) { + fw.write(task.getFormattedDetails()); + } + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index f202113be..f4bceb528 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,14 +1,16 @@ package seedu.duke; -import event.EventList; import parser.Parser; import command.EventCommand; import command.StudyAreaCommand; -import resourceloader.EventLoader; +import resourceloader.TaskLoader; import resourceloader.StudyAreaLoader; import studyarea.IllegalStudyAreaException; import studyarea.StudyAreaList; +import task.event.TaskList; import ui.Ui; + +import java.io.File; import java.io.FileNotFoundException; @@ -16,9 +18,12 @@ * This is Duke class, which forms the main class of the program. */ public class Duke { - private static EventLoader eventLoader; + + public static final String FILE_PATH_EVENTS = "library" + File.separator + "taskList.txt"; + public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; + private static TaskLoader taskLoader; protected static StudyAreaLoader studyAreaLoader; - private static EventList eventList = new EventList(); + private static TaskList taskList = new TaskList(); private static StudyAreaList studyAreaList; private static Ui ui = new Ui(); private static Parser parser; @@ -29,9 +34,9 @@ public class Duke { public Duke() { try { parser = new Parser(); - eventLoader = new EventLoader(Ui.FILE_PATH_EVENTS); - eventList = new EventList(eventLoader.loadFile()); - studyAreaLoader = new StudyAreaLoader(Ui.FILE_PATH_STUDYAREAS); + taskLoader = new TaskLoader(FILE_PATH_EVENTS); + taskList = new TaskList(taskLoader.loadFile()); + studyAreaLoader = new StudyAreaLoader(FILE_PATH_STUDYAREAS); studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); } catch (FileNotFoundException | IllegalStudyAreaException e) { ui.printLine(); @@ -53,7 +58,7 @@ public void run() { status = false; break; case 1: - EventCommand.runCommands(eventList, ui, parser); + EventCommand.runCommands(taskList, ui, parser); ui.printMessage(Ui.INTERMEDIATE_MESSAGE); break; case 2: @@ -67,7 +72,7 @@ public void run() { } ui.printLine(); } - eventLoader.saveEvents(eventList.events); + taskLoader.saveTasks(taskList.tasks); ui.printMessage(Ui.GOODBYE_MESSAGE + Ui.DAB); ui.close(); } diff --git a/src/main/java/task/Task.java b/src/main/java/task/Task.java new file mode 100644 index 000000000..7bfd6e1fa --- /dev/null +++ b/src/main/java/task/Task.java @@ -0,0 +1,17 @@ +package task; + +import java.time.LocalDate; + +public abstract class Task { + + public abstract int getPriority(); + + public abstract LocalDate getDate(); + + public abstract boolean hasKeyword(String keyword) throws Exception; + + public abstract String getFormattedDetails(); + + public abstract String getTaskInformation(); + +} diff --git a/src/main/java/task/TaskList.java b/src/main/java/task/TaskList.java index a76413e3b..498811e89 100644 --- a/src/main/java/task/TaskList.java +++ b/src/main/java/task/TaskList.java @@ -1,17 +1,238 @@ -package task; +package task.event; + +import java.time.format.DateTimeParseException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +import task.Task; +import task.TaskType; +import task.deadline.Deadline; +import ui.Ui; + +/** + * Handles all functions related to the list of events. + */ +public class TaskList { + + + /** + * Stores the task's information. + */ + public ArrayList tasks; + + /** + * Constructor for the TaskList class. + */ + public TaskList() { + tasks = new ArrayList(); + } + + /** + * Overloaded constructor for TaskList class. + * + * @param tasks The list of events the task's list of events is initialised with. + */ + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + + /** + * Returns the number of tasks currently stored. + * + * @return The number of tasks stored currently. + */ + public int getTaskListSize() { + return tasks.size(); + } + + /** + * Adds a new task to the list. + * + * @param ui This allows Task List class to interact with User. + * @param newTask represents the new task to be added. + */ + public void addTask(Task newTask, Ui ui) { + tasks.add(newTask); + ui.printLine(); + ui.printMessage("A new event with the following information has been added."); + ui.printMessage(newTask.getTaskInformation()); + ui.printLine(); + } -public abstract class TaskList { /** - * TaskList is an abstract class that oversees all task-related classes. - * The current task-related classes are events, deadlines, assignments - * TaskList stores all tasks in one large array, allowing the user to access the priorityView and countdownView of - * all tasks + * Displays the current list of tasks. + * + * @param ui This allows TaskList class to interact with User. */ + public void listTasks(Ui ui) { + ui.printLine(); + ui.printMessage("Here is the list of events added so far:"); + int eventNumber = 1; + for (Task task : tasks) { + ui.printMessage(eventNumber + ") " + task.getTaskInformation()); + eventNumber++; + } + ui.printLine(); + } + + /** + * Deletes the task at the specified index. + * + * @param ui This allows TaskList class to interact with User. + * @param index The index (1-based) of the task to be deleted. + */ + public void deleteTask(int index, Ui ui) { + ui.printLine(); + try { + if (index > tasks.size() | index <= 0) { + throw new IndexOutOfBoundsException(); + } + tasks.remove(index - 1); + ui.printLine(); + ui.printMessage("The task at the mentioned index has been deleted"); + ui.printLine(); + } catch (IndexOutOfBoundsException e) { + ui.printMessage("Invalid index entered. Please enter a valid index to be deleted"); + ui.printLine(); + } + + } + + /** + * Clears all the tasks currently stored. + * + * @param ui This allows TaskList class to interact with User. + */ + public void clearTasks(Ui ui) { + tasks.clear(); + ui.printLine(); + ui.printMessage("The list of tasks is cleared."); + ui.printLine(); + } + + /** + * Lists all the tasks sorted by their priority. + * + * @param ui This allows TaskList class to interact with User. + */ + public void priorityView(Ui ui) { + ArrayList tasksSortedByPriority = tasks; + tasksSortedByPriority.sort(Comparator.comparingInt(Task::getPriority)); + Collections.reverse(tasksSortedByPriority); + ui.printLine(); + int taskNumber = 1; + for (Task task : tasksSortedByPriority) { + ui.printMessage(taskNumber + ") " + task.getTaskInformation()); + taskNumber++; + } + if (taskNumber == 1) { + ui.printMessage("The list is empty."); + } + ui.printLine(); + } + + /** + * Lists all the tasks sorted by date along with the days remaining. + * + * @param ui This allows TaskList class to interact with User. + */ + public void countdownView(Ui ui) { + ArrayList tasksSortedByDate = tasks; + tasksSortedByDate.sort(Comparator.comparing(Task::getDate)); + ui.printLine(); + int taskNumber = 1; + for (Task task : tasksSortedByDate) { + ui.printMessage(taskNumber + ") " + task.getTaskInformation()); + taskNumber++; + } + if (taskNumber == 1) { + ui.printMessage("The list is empty."); + } + ui.printLine(); + } + + /** + * Displays the list of tasks containing the keyword. + * + * @param ui This allows TaskList class to interact with User. + * @param keyword The keyword to be searched for. + * @throws Exception If the keyword is empty. + */ + public void searchTasks(String keyword, Ui ui) throws Exception { + int taskNumber = 1; + ui.printLine(); + for (Task task : tasks) { + if (task.hasKeyword(keyword)) { + ui.printMessage(taskNumber + ") " + task.getTaskInformation()); + taskNumber++; + } + } + if (taskNumber == 1) { + ui.printMessage("The list is empty."); + } + ui.printLine(); + } + +} + + +/* + public void add(String taskDetails, Ui ui, TaskType taskType) { + switch (taskType) { + case Deadline: + addNewDeadline(taskDetails,ui); + break; + case Event: + addNewEvent(taskDetails, ui); + break; + default: + ui.printMessage("Error encountered during execution"); + break; + } + } - public abstract void priorityView(); + private void addNewEvent(String eventDetails, Ui ui) { + try { + String[] details = eventDetails.split(" ",2)[1].split("/"); + String description = details[0]; + String date = details[1].substring(2); + String startTime = details[2].substring(2); + String endTime = details[3].substring(2); + String priority = details[4].substring(2); + Event newEvent = new Event(description,date,startTime,endTime,priority); + addTask(newEvent, ui); + } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { + ui.printLine(); + ui.printMessage("Wrong format to add events"); + ui.printLine(); + } catch (Exception e) { + ui.printLine(); + ui.printMessage(e.getMessage()); + ui.printLine(); + } + } - public abstract void countdownView(); + private void addNewDeadline(String deadlineDetails, Ui ui) { + try { + String[] details = deadlineDetails.split(" ",2)[1].split("/"); + String description = details[0]; + String date = details[1].substring(2); + String dueTime = details[2].substring(2); + String priority = details[3].substring(2); + Deadline newDeadline = new Deadline(description,date,dueTime, priority); + addTask(newDeadline, ui); + } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { + ui.printLine(); + ui.printMessage("Wrong format to add deadlines"); + ui.printLine(); + } catch (Exception e) { + ui.printLine(); + ui.printMessage(e.getMessage()); + ui.printLine(); + } + } - public abstract void searchTasks(); -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/src/main/java/task/TaskType.java b/src/main/java/task/TaskType.java new file mode 100644 index 000000000..64343d83f --- /dev/null +++ b/src/main/java/task/TaskType.java @@ -0,0 +1,5 @@ +package task; + +public enum TaskType { + Event, Deadline +} diff --git a/src/main/java/deadline/Deadline.java b/src/main/java/task/deadline/Deadline.java similarity index 89% rename from src/main/java/deadline/Deadline.java rename to src/main/java/task/deadline/Deadline.java index 03f7f9289..411e558e2 100644 --- a/src/main/java/deadline/Deadline.java +++ b/src/main/java/task/deadline/Deadline.java @@ -1,4 +1,6 @@ -package deadline; +package task.deadline; + +import task.Task; import java.time.LocalDate; import java.time.LocalTime; @@ -8,7 +10,7 @@ /** * Represents an deadline and contains the related functions. */ -public class Deadline { +public class Deadline extends Task { private String description; private LocalDate date; @@ -66,9 +68,9 @@ private void parseDescription(String description) { * * @return deadlineInfo Contains information related to the deadline. */ - public String getDeadlineInformation() { - String deadlineInfo = description + " on " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + " at " - + dueTime.toString(); + public String getTaskInformation() { + String deadlineInfo = "[D] " + description + " on " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + + " at " + dueTime.toString(); return deadlineInfo; } @@ -81,6 +83,7 @@ public int getPriority() { return priority; } + /** * Returns the date of the deadline. * @@ -111,7 +114,7 @@ public boolean hasKeyword(String keyword) throws Exception { * @return formattedDeadlineDetails Contains the deadline details in the required format. */ public String getFormattedDetails() { - String formattedDeadlineDetails = description + "#" + date + "#" + dueTime + "#" + priority; + String formattedDeadlineDetails = "D#" + description + "#" + date + "#" + dueTime + "#" + priority + "\n"; return formattedDeadlineDetails; } } \ No newline at end of file diff --git a/src/main/java/event/Event.java b/src/main/java/task/event/Event.java similarity index 89% rename from src/main/java/event/Event.java rename to src/main/java/task/event/Event.java index 48cce8932..008b51f74 100644 --- a/src/main/java/event/Event.java +++ b/src/main/java/task/event/Event.java @@ -1,4 +1,6 @@ -package event; +package task.event; + +import task.Task; import java.time.LocalDate; import java.time.LocalTime; @@ -8,7 +10,7 @@ /** * Represents an event and contains the related functions. */ -public class Event { +public class Event extends Task { private String description; private LocalDate date; @@ -83,9 +85,9 @@ private void parseDescription(String description) { * * @return eventInfo Contains information related to the event. */ - public String getEventInformation() { - String eventInfo = description + " at " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + " from " - + startTime.toString() + " to " + endTime.toString(); + public String getTaskInformation() { + String eventInfo = "[E] " + description + " at " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + + " from " + startTime.toString() + " to " + endTime.toString(); return eventInfo; } @@ -128,7 +130,8 @@ public boolean hasKeyword(String keyword) throws Exception { * @return formattedEventDetails Contains the event details in the required format. */ public String getFormattedDetails() { - String formattedEventDetails = description + "#" + date + "#" + startTime + "#" + endTime + "#" + priority; + String formattedEventDetails = "E#" + description + "#" + date + "#" + startTime + "#" + endTime + "#" + + priority + "\n"; return formattedEventDetails; } } diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 2f381049e..69f45298d 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -17,13 +17,11 @@ public class Ui { private final Scanner in; private final PrintStream out; - public static final String FILE_PATH_EVENTS = "library" + File.separator + "eventList.txt"; - public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; public static final String MISSING_STUDY_AREA_DATA = "locations.txt is missing"; public static final String BYE_COMMAND = "bye"; public static final String BYE_MESSAGE = "Bye!!!!!!"; public static final String LINE = "_______________________________________________________________________________" - + "_____"; + + "_________________________"; public static final int MAX_LINE_LENGTH = 55; public static final String FLAG = "-"; public static final String MULTIPLE_WHITE_SPACES = "\\s+"; @@ -53,12 +51,12 @@ public class Ui { public static final String TAB = "\t "; public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; - public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"event\" to start\n" - + " your event list! If you are in the mood to mug and you" + public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"task\" to start\n" + + " your task list! If you are in the mood to mug and you" + " want to start your study area list, enter \"study\" !If" + " you want to exit, enter \"bye\" !"; public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; - public static final String EVENT_COMMAND = "event"; + public static final String TASK_COMMAND = "task"; public static final String STUDY_COMMAND = "study"; public static final String GOODBYE_MESSAGE = " Goodbye! Hope to see you again!"; public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or" @@ -124,7 +122,7 @@ public Ui(InputStream in, PrintStream out) { public int getMode() { String userIn = this.in.nextLine().toLowerCase(); switch (userIn) { - case EVENT_COMMAND : + case TASK_COMMAND : return 1; case STUDY_COMMAND : return 2; @@ -240,8 +238,10 @@ public void printHelp() { printLine(); this.out.println(TAB + "OrgaNice! Supports the following commands"); this.out.println(TAB + "Please enter the keywords followed by the information shown in the brackets"); - this.out.println(TAB + "add /d /s /e /p /d /s /e /p "); + this.out.println(TAB + "deadline /d /t /p "); this.out.println(TAB + "------------------------------------------- Create a new event"); this.out.println(TAB + "view -------------------------------------- View existing events"); this.out.println(TAB + "priority_view ----------------------------- View existing events based " diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java index f0b628190..f3f2be54a 100644 --- a/src/test/java/parser/ParserTest.java +++ b/src/test/java/parser/ParserTest.java @@ -15,15 +15,24 @@ class ParserTest { Command command; @Test - void parseCommand_emptyAddCommand_throwException() { + void parseCommand_emptyAddEventCommand_throwException() { try { - command = parser.parseCommand("add"); + command = parser.parseCommand("event"); fail("Empty add command not identified"); } catch (Exception exception) { assertEquals("Event details are not provided",exception.getMessage()); } } + @Test + void parseCommand_emptyAddDeadlineCommand_throwException() { + try { + command = parser.parseCommand("event"); + fail("Empty add command not identified"); + } catch (Exception exception) { + assertEquals("Event details are not provided",exception.getMessage()); + } + } @Test void parseCommand_emptyCommand_throwException() { diff --git a/src/test/java/event/EventListTest.java b/src/test/java/task/event/TaskListTest.java similarity index 67% rename from src/test/java/event/EventListTest.java rename to src/test/java/task/event/TaskListTest.java index 77bf65de8..0f09db8d9 100644 --- a/src/test/java/event/EventListTest.java +++ b/src/test/java/task/event/TaskListTest.java @@ -1,4 +1,4 @@ -package event; +package task.event; import org.junit.jupiter.api.Test; import ui.Ui; @@ -9,21 +9,21 @@ /** * Contains all the test related to EventList class. */ -class EventListTest { +class TaskListTest { Ui ui = new Ui(); - EventList eventList; + task.event.TaskList taskList; - public EventListTest() throws Exception { - eventList = new EventList(); - eventList.addEvent(new Event("Team Meeting", "2020-03-21", "09:00", + public TaskListTest() throws Exception { + taskList = new task.event.TaskList(); + taskList.addTask(new Event("Team Meeting", "2020-03-21", "09:00", "17:00", "1"),ui); } @Test void deleteEvent_invalidIndex_throwException() { try { - eventList.deleteEvent(2,ui); + taskList.deleteTask(2,ui); } catch (Exception e) { assertEquals("Invalid index entered. Please enter a valid index to be deleted", e.getMessage()); @@ -33,7 +33,7 @@ void deleteEvent_invalidIndex_throwException() { @Test void searchEvents_emptySearchKeyword_throwException() { try { - eventList.searchEvents("",ui); + taskList.searchTasks("",ui); fail("Empty string search not identified"); } catch (Exception exception) { assertEquals("Keyword is empty", exception.getMessage()); @@ -42,8 +42,8 @@ void searchEvents_emptySearchKeyword_throwException() { @Test void clearCommand() { - eventList.clearEvents(ui); - assertEquals(0, eventList.getEventListSize()); + taskList.clearTasks(ui); + assertEquals(0, taskList.getTaskListSize()); } } diff --git a/src/test/java/event/EventTest.java b/src/test/java/task/event/TaskTest.java similarity index 93% rename from src/test/java/event/EventTest.java rename to src/test/java/task/event/TaskTest.java index ad2a1aca5..b074ef8d7 100644 --- a/src/test/java/event/EventTest.java +++ b/src/test/java/task/event/TaskTest.java @@ -1,4 +1,4 @@ -package event; +package task.event; import org.junit.jupiter.api.Test; @@ -8,18 +8,18 @@ /** * Contains all the tests related to the Event class. */ -class EventTest { +class TaskTest { @Test void eventInformation() throws Exception { - assertEquals("Team Meeting at Mar 21 2020 from 09:00 to 17:00", + assertEquals("[E] Team Meeting at Mar 21 2020 from 09:00 to 17:00", new Event("Team Meeting", "2020-03-21", "09:00", - "17:00", "1").getEventInformation()); + "17:00", "1").getTaskInformation()); } @Test void formattedDetails() throws Exception { - assertEquals("Team Meeting#2020-03-21#09:00#17:00#1", + assertEquals("E#Team Meeting#2020-03-21#09:00#17:00#1\n", new Event("Team Meeting", "2020-03-21", "09:00", "17:00", "1").getFormattedDetails()); } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 0a7d67f55..560b7cea6 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -9,15 +9,120 @@ ________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\/ ____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ ______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ What is your name? -____________________________________________________________________________________ -____________________________________________________________________________________ +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ Hello James Gosling! - Welcome to OrgaNice! To start, enter "event" to start - your event list! If you are in the mood to mug and you + Welcome to OrgaNice! To start, enter "task" to start + your task list! If you are in the mood to mug and you want to start your study area list, enter "study" !If you want to exit, enter "bye" ! -____________________________________________________________________________________ -____________________________________________________________________________________ +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + OrgaNice! Supports the following commands + Please enter the keywords followed by the information shown in the brackets + event /d /s /e /p + deadline /d /t /p + ------------------------------------------- Create a new event + view -------------------------------------- View existing events + priority_view ----------------------------- View existing events based on priority + countdown --------------------------------- View existing events based on days left + clear ------------------------------------- Delete all events + search ----------- View existing events that contains the keyword + delete ------------ Delete the event + help -------------------------------------- View List Of Commands Supported + bye --------------------------------------- Terminate program + Notes: + *All dates should follow YYYY-MM-DD format + *All timing should follow 24 hour clock + *There are 4 levels of priority, with 1 being the most urgent, and 4 being the least urgent +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + The list of tasks is cleared. +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + A new event with the following information has been + added. + [E] meeting at May 5 2020 from 12:00 to 13:00 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Here is the list of events added so far: + 1) [E] meeting at May 5 2020 from 12:00 to 13:00 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + A new event with the following information has been + added. + [D] assignment on May 2 2020 at 14:00 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + 1) [D] assignment on May 2 2020 at 14:00 + 2) [E] meeting at May 5 2020 from 12:00 to 13:00 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Invalid index entered. Please enter a valid index to be + deleted +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Index 1 out of bounds for length 1 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Enter a valid integer index (1-based) to delete the + corresponding event (format: delete index) +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Event details are not provided +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Wrong command used to view events (Should be :view ) +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Invalid command entered, Please enter a valid command +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + 1) [D] assignment on May 2 2020 at 14:00 + 2) [E] meeting at May 5 2020 from 12:00 to 13:00 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Bye!!!!!! +________________________________________________________________________________________________________ + Please enter "event" to continue with your event list + or "study" to continue with your study area list. To + leave, enter "bye". +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + OrgaNice! Supports the following commands + Please enter the keywords followed by the information shown in the brackets + event /d /s /e /p + deadline /d /t /p + ------------------------------------------- Create a new event + view -------------------------------------- View existing events + priority_view ----------------------------- View existing events based on priority + countdown --------------------------------- View existing events based on days left + clear ------------------------------------- Delete all events + search ----------- View existing events that contains the keyword + delete ------------ Delete the event + help -------------------------------------- View List Of Commands Supported + bye --------------------------------------- Terminate program + Notes: + *All dates should follow YYYY-MM-DD format + *All timing should follow 24 hour clock + *There are 4 levels of priority, with 1 being the most urgent, and 4 being the least urgent +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Wrong command used to view countdown of events (Should + be :countdown ) +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + 1) [D] assignment on May 2 2020 at 14:00 + 2) [E] meeting at May 5 2020 from 12:00 to 13:00 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Bye!!!!!! +________________________________________________________________________________________________________ + Please enter "event" to continue with your event list + or "study" to continue with your study area list. To + leave, enter "bye". +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ Goodbye! Hope to see you again! `````````````````````````````````````````````````````````` ````````````````````````````````:v(v'````````````````````` diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 1329553ca..5e4d28f31 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,2 +1,20 @@ James Gosling +task +clear +event meeting /d 2020-05-05 /s 12:00 /e 13:00 /p 1 +view +deadline assignment /d 2020-05-02 /t 14:00 /p 2 +priority_view +delete 3 +event team meeting +delete one +event +view list +task +countdown +bye +task +countdown view +countdown +bye bye \ No newline at end of file diff --git a/text-ui-test/library/eventList.txt b/text-ui-test/library/eventList.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/text-ui-test/library/taskList.txt b/text-ui-test/library/taskList.txt new file mode 100644 index 000000000..840faf7dc --- /dev/null +++ b/text-ui-test/library/taskList.txt @@ -0,0 +1,2 @@ +D#assignment #2020-05-02#14:00#2 +E#meeting #2020-05-05#12:00#13:00#1 From 95c958468a8393c1458396a9bde51a1599943bc4 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Fri, 13 Mar 2020 22:34:14 +0800 Subject: [PATCH 077/435] Clear data file --- library/taskList.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/taskList.txt b/library/taskList.txt index be12e1d39..e69de29bb 100644 --- a/library/taskList.txt +++ b/library/taskList.txt @@ -1,2 +0,0 @@ -E#school #2020-05-05#12:12#13:12#2 -D#asfdafs #2020-05-06#12:13#1 From 37636972cc12ee714d2ee8ecd5b132e900c4e20a Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Fri, 13 Mar 2020 22:47:31 +0800 Subject: [PATCH 078/435] Rename EventCommand to TaskCommand --- src/main/java/command/{EventCommand.java => TaskCommand.java} | 2 +- src/main/java/seedu/duke/Duke.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/main/java/command/{EventCommand.java => TaskCommand.java} (97%) diff --git a/src/main/java/command/EventCommand.java b/src/main/java/command/TaskCommand.java similarity index 97% rename from src/main/java/command/EventCommand.java rename to src/main/java/command/TaskCommand.java index 17ebb2dce..d4ab823ee 100644 --- a/src/main/java/command/EventCommand.java +++ b/src/main/java/command/TaskCommand.java @@ -8,7 +8,7 @@ /** * Used to run all the functions related to tasks. */ -public class EventCommand { +public class TaskCommand { /** * Runs all the command for tasks. diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index f4bceb528..d118ae7d6 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,7 +1,7 @@ package seedu.duke; import parser.Parser; -import command.EventCommand; +import command.TaskCommand; import command.StudyAreaCommand; import resourceloader.TaskLoader; import resourceloader.StudyAreaLoader; @@ -58,7 +58,7 @@ public void run() { status = false; break; case 1: - EventCommand.runCommands(taskList, ui, parser); + TaskCommand.runCommands(taskList, ui, parser); ui.printMessage(Ui.INTERMEDIATE_MESSAGE); break; case 2: From d8c60fd0459a39cd38193b5dc852171a0c44a058 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 09:50:07 +0800 Subject: [PATCH 079/435] Add support to edit tasks --- library/taskList.txt | 2 + src/main/java/command/AddDeadlineCommand.java | 3 +- src/main/java/command/AddEventCommand.java | 2 +- src/main/java/command/DeleteCommand.java | 2 +- src/main/java/command/EditCommand.java | 40 +++ .../EditCommandMissingIndexException.java | 9 + .../command/IndexNotIntegerException.java | 2 +- src/main/java/parser/Parser.java | 15 +- src/main/java/resourceloader/TaskLoader.java | 4 +- src/main/java/task/Deadline.java | 249 +++++++++++++++ src/main/java/task/Event.java | 291 ++++++++++++++++++ src/main/java/task/Task.java | 2 + src/main/java/task/TaskList.java | 115 +++---- src/main/java/task/deadline/Deadline.java | 120 -------- src/main/java/task/event/Event.java | 137 --------- src/main/java/ui/Ui.java | 20 +- src/test/java/task/event/TaskListTest.java | 1 + src/test/java/task/event/TaskTest.java | 1 + 18 files changed, 676 insertions(+), 339 deletions(-) create mode 100644 src/main/java/command/EditCommand.java create mode 100644 src/main/java/exception/command/EditCommandMissingIndexException.java create mode 100644 src/main/java/task/Deadline.java create mode 100644 src/main/java/task/Event.java delete mode 100644 src/main/java/task/deadline/Deadline.java delete mode 100644 src/main/java/task/event/Event.java diff --git a/library/taskList.txt b/library/taskList.txt index e69de29bb..b6448d4c8 100644 --- a/library/taskList.txt +++ b/library/taskList.txt @@ -0,0 +1,2 @@ +E#Hello#2020-04-05#10:00#13:00#2 +D#asdafs#2020-04-05#12:00#121 diff --git a/src/main/java/command/AddDeadlineCommand.java b/src/main/java/command/AddDeadlineCommand.java index 6e6497fbc..82cc098e5 100644 --- a/src/main/java/command/AddDeadlineCommand.java +++ b/src/main/java/command/AddDeadlineCommand.java @@ -1,8 +1,7 @@ package command; import exception.command.EventDetailsNotProvidedException; -import task.deadline.Deadline; -import task.event.Event; +import task.Deadline; import task.event.TaskList; import ui.Ui; diff --git a/src/main/java/command/AddEventCommand.java b/src/main/java/command/AddEventCommand.java index 5b028594a..b2ecde028 100644 --- a/src/main/java/command/AddEventCommand.java +++ b/src/main/java/command/AddEventCommand.java @@ -1,7 +1,7 @@ package command; -import task.event.Event; import exception.command.EventDetailsNotProvidedException; +import task.Event; import task.event.TaskList; import ui.Ui; diff --git a/src/main/java/command/DeleteCommand.java b/src/main/java/command/DeleteCommand.java index 0c53ed497..fd3ad83e7 100644 --- a/src/main/java/command/DeleteCommand.java +++ b/src/main/java/command/DeleteCommand.java @@ -10,7 +10,7 @@ */ public class DeleteCommand extends Command { - /** Denotes the index at which the event should be deleted at. */ + /** Denotes the index at which the task should be deleted at. */ int indexToDelete; /** diff --git a/src/main/java/command/EditCommand.java b/src/main/java/command/EditCommand.java new file mode 100644 index 000000000..287240976 --- /dev/null +++ b/src/main/java/command/EditCommand.java @@ -0,0 +1,40 @@ +package command; + +import exception.command.EditCommandMissingIndexException; +import exception.command.IndexNotIntegerException; +import task.event.TaskList; +import ui.Ui; + +/** + * Command is used to delete a task at a specific index. + */ +public class EditCommand extends Command { + + /** Denotes the index at which the task should be edited at. */ + int indexToEdit; + + /** + * Constructor for the DeleteCommand object. + * Creates a new DeleteCommand object if the correct command is used. + * + * @param commandSplit Contains information with regards to the index to be deleted at. + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @throws Exception If the index specified is invalid/ The wrong format is used for the command. + */ + public EditCommand(String[] commandSplit, boolean isOneWordCommand) throws Exception { + if (isOneWordCommand) { + throw new EditCommandMissingIndexException(); + } + try { + indexToEdit = Integer.parseInt(commandSplit[1]); + } catch (NumberFormatException e) { + throw new IndexNotIntegerException(); + } + } + + + @Override + public void executeCommand(TaskList taskList, Ui ui) throws Exception { + taskList.editTask(indexToEdit, ui); + } +} diff --git a/src/main/java/exception/command/EditCommandMissingIndexException.java b/src/main/java/exception/command/EditCommandMissingIndexException.java new file mode 100644 index 000000000..c82194d7e --- /dev/null +++ b/src/main/java/exception/command/EditCommandMissingIndexException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class EditCommandMissingIndexException extends CustomException { + public EditCommandMissingIndexException() { + super("Index to edited not mentioned"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/IndexNotIntegerException.java b/src/main/java/exception/command/IndexNotIntegerException.java index ffce7d2ff..bc897d706 100644 --- a/src/main/java/exception/command/IndexNotIntegerException.java +++ b/src/main/java/exception/command/IndexNotIntegerException.java @@ -4,7 +4,7 @@ public class IndexNotIntegerException extends CustomException { public IndexNotIntegerException() { - super("Enter a valid integer index (1-based) to delete the corresponding event " + super("Enter a valid integer index (1-based) to delete/edit the corresponding event " + "(format: delete index)"); } } \ No newline at end of file diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java index 967f59fb1..d41d931eb 100644 --- a/src/main/java/parser/Parser.java +++ b/src/main/java/parser/Parser.java @@ -1,15 +1,6 @@ package parser; -import command.AddDeadlineCommand; -import command.AddEventCommand; -import command.ClearCommand; -import command.Command; -import command.CountdownCommand; -import command.DeleteCommand; -import command.HelpCommand; -import command.PriorityViewCommand; -import command.SearchCommand; -import command.ViewCommand; +import command.*; /** * This class is used to parse the user input into executable commands. @@ -24,6 +15,7 @@ public class Parser { public static final String CLEAR_COMMAND = "clear"; public static final String SEARCH_COMMAND = "search"; public static final String DELETE_COMMAND = "delete"; + public static final String EDIT_COMMAND = "edit"; public static final String EMPTY_COMMAND = ""; public static final String HELP_COMMAND = "help"; @@ -46,6 +38,9 @@ public Command parseCommand(String fullCommand) throws Exception { case ADD_EVENT_COMMAND: command = new AddEventCommand(commandSplit, isOneWordCommand); break; + case EDIT_COMMAND: + command = new EditCommand(commandSplit, isOneWordCommand); + break; case VIEW_COMMAND: command = new ViewCommand(isOneWordCommand); break; diff --git a/src/main/java/resourceloader/TaskLoader.java b/src/main/java/resourceloader/TaskLoader.java index 5cfdd79ca..50366f718 100644 --- a/src/main/java/resourceloader/TaskLoader.java +++ b/src/main/java/resourceloader/TaskLoader.java @@ -1,8 +1,8 @@ package resourceloader; import task.Task; -import task.deadline.Deadline; -import task.event.Event; +import task.Deadline; +import task.Event; import ui.Ui; import java.io.File; import java.io.FileNotFoundException; diff --git a/src/main/java/task/Deadline.java b/src/main/java/task/Deadline.java new file mode 100644 index 000000000..5a8abf8f5 --- /dev/null +++ b/src/main/java/task/Deadline.java @@ -0,0 +1,249 @@ +package task; + +import ui.Ui; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +import static task.Event.*; + +/** + * Represents an deadline and contains the related functions. + */ +public class Deadline extends Task { + + private static final int EDIT_DUE_TIME = 3; + public static final int EDIT_PRIORITY = 4; + private String description; + private LocalDate date; + private LocalTime dueTime; + private int priority; + + /** + * Setter for priority of the deadline. + * + * @param priority The new priority of the deadline. + */ + public void setPriority(int priority) { + this.priority = priority; + } + + /** + * Constructor for Deadline Class. + * + * @param description Description of the deadline. + * @param date Date of specified Deadline + * @param dueTime Due time of specified deadline. + * @param priority Priority of specified deadline. + * @throws Exception If wrong format is used for date, time fields. + */ + public Deadline(String description, String date, String dueTime, String priority) throws Exception { + taskType = TaskType.Deadline; + parseDescription(description); + parseDate(date); + parseDueTime(dueTime); + parsePriority(priority); + } + + private void parsePriority(String priority) throws Exception { + try { + this.priority = Integer.parseInt(priority.strip()); + } catch (NumberFormatException e) { + throw new Exception("Priority should be an integer"); + } + } + + private void parseDueTime(String dueTime) throws Exception { + try { + this.dueTime = LocalTime.parse(dueTime.strip()); + } catch (DateTimeParseException e) { + throw new Exception("Due time provided is invalid or in wrong format (Should be HH:MM)"); + } + } + + private void parseDate(String date) throws Exception { + try { + this.date = LocalDate.parse(date.strip()); + } catch (DateTimeParseException e) { + throw new Exception("Date provided is invalid or is in wrong format (Should be YYYY-MM-DD)"); + } + + } + + private void parseDescription(String description) { + this.description = description; + } + + /** + * Returns the information related to information in form of a string. + * + * @return deadlineInfo Contains information related to the deadline. + */ + public String getTaskInformation() { + String deadlineInfo = "[D] " + description + " on " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + + " at " + dueTime.toString() + " with priority " + priority; + return deadlineInfo; + } + + /** + * Returns the priority of the specified deadline. + * + * @return Priority of deadline. + */ + public int getPriority() { + return priority; + } + + + /** + * Returns the date of the deadline. + * + * @return Date of deadline. + */ + public LocalDate getDate() { + return date; + } + + /** + * Used to identify if the string contains the keyword specified in its description. + * + * @param keyword The keyword to be matched with the description. + * @return containsKeyword Indicates the presence/absence of keyword in the deadline's description. + * @throws Exception If no keyword is entered. + */ + public boolean hasKeyword(String keyword) throws Exception { + if (keyword.equals("")) { + throw new Exception("Keyword is empty"); + } + boolean containsKeyword = description.contains(keyword); + return containsKeyword; + } + + /** + * Returns the deadline in the format used to store it in the data file. + * + * @return formattedDeadlineDetails Contains the deadline details in the required format. + */ + public String getFormattedDetails() { + String formattedDeadlineDetails = "D#" + description + "#" + date + "#" + dueTime + "#" + priority + "\n"; + return formattedDeadlineDetails; + } + + /** + * Edits the event at the index specified. + * + * @param ui Used to interact with the user. + * @return Newly updated event. + */ + public Deadline editDeadline(Ui ui) { + printOptionsToEdit(ui); + int fieldToBeEdited = 0; + fieldToBeEdited = getFieldToBeEdited(ui, false, fieldToBeEdited); + switch (fieldToBeEdited) { + case EDIT_DESCRIPTION: + editDescription(ui); + break; + case EDIT_DATE: + editDate(ui); + break; + case EDIT_DUE_TIME: + editDueTime(ui); + break; + case EDIT_PRIORITY: + editPriority(ui); + break; + default: + ui.printMessage(ERROR_MESSAGE); + break; + } + printUpdatedDetails(ui); + return this; + } + + private void editPriority(Ui ui) { + boolean exceptionEncountered; + do { + exceptionEncountered = false; + ui.printMessage("Enter new priority:"); + String newPriorityString = ui.getUserIn(); + try { + parsePriority(newPriorityString); + } catch (Exception e) { + ui.printMessage(e.getMessage()); + exceptionEncountered = true; + } + } while (exceptionEncountered); + } + + private void editDueTime(Ui ui) { + boolean exceptionEncountered; + do { + exceptionEncountered = false; + ui.printMessage("Enter new due Time:"); + String newStartTimeString = ui.getUserIn(); + try { + parseDueTime(newStartTimeString); + } catch (Exception e) { + ui.printMessage(e.getMessage()); + exceptionEncountered = true; + } + } while (exceptionEncountered); + } + + private void editDate(Ui ui) { + boolean exceptionEncountered; + do { + exceptionEncountered = false; + ui.printMessage("Enter new Date:"); + String newDateString = ui.getUserIn(); + try { + parseDate(newDateString); + } catch (Exception e) { + ui.printMessage(e.getMessage()); + exceptionEncountered = true; + } + } while (exceptionEncountered); + } + + private void editDescription(Ui ui) { + ui.printMessage("Enter new description:"); + String newDescription = ui.getUserIn(); + parseDescription(newDescription); + } + + private int getFieldToBeEdited(Ui ui, boolean exceptionEncountered, int fieldToBeEdited) { + do { + exceptionEncountered = false; + try { + fieldToBeEdited = Integer.parseInt(ui.getUserIn()); + if (fieldToBeEdited > 4 || fieldToBeEdited < 0) { + throw new Exception(); + } + } catch (Exception exception) { + ui.printMessage("Please enter a valid number"); + exceptionEncountered = true; + } + } while (exceptionEncountered); + return fieldToBeEdited; + } + + private void printUpdatedDetails(Ui ui) { + ui.printMessage("Updated Details:"); + ui.printMessage(this.getTaskInformation()); + ui.printLine(); + } + + private void printOptionsToEdit(Ui ui) { + ui.printLine(); + ui.printMessage("The deadline details are as follows:"); + ui.printMessage(this.getTaskInformation()); + ui.printMessage("Which field of the event to edit? (Enter Corresponding Number)"); + ui.printMessage("1. Description"); + ui.printMessage("2. Date"); + ui.printMessage("3. Due Time"); + ui.printMessage("4. Priority"); + ui.printEmptyLine(); + } +} \ No newline at end of file diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java new file mode 100644 index 000000000..01770cc9a --- /dev/null +++ b/src/main/java/task/Event.java @@ -0,0 +1,291 @@ +package task; + +import ui.Ui; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +/** + * Represents an event and contains the related functions. + */ +public class Event extends Task { + + public static final int EDIT_DESCRIPTION = 1; + public static final int EDIT_DATE = 2; + public static final int EDIT_START_TIME = 3; + public static final int EDIT_END_TIME = 4; + public static final int EDIT_PRIORITY = 5; + public static final String ERROR_MESSAGE = "Error encountered during execution"; + private String description; + private LocalDate date; + private LocalTime startTime; + private LocalTime endTime; + private int priority; + + /** + * Setter for priority of the deadline. + * + * @param priority The new priority of the event. + */ + public void setPriority(int priority) { + this.priority = priority; + } + + /** + * Constructor for Event Class. + * + * @param description Description of the event. + * @param date Date of specified Event. + * @param startTime Start time of specified event. + * @param endTime End time of specified event. + * @param priority Priority of specified event. + * @throws Exception If wrong format is used for date, time or priority fields. + */ + public Event(String description, String date, String startTime, String endTime, String priority) + throws Exception { + taskType = TaskType.Event; + parseDescription(description); + parseDate(date); + parseStartTime(startTime); + parseEndTime(endTime); + parsePriority(priority); + if (this.startTime.isAfter(this.endTime)) { + throw new Exception("Start time should be before End time"); + } + if (this.date.isBefore(LocalDate.now())) { + throw new Exception("Date specified must be a current or a future date"); + } + } + + private void parsePriority(String priority) throws Exception { + try { + this.priority = Integer.parseInt(priority.strip()); + } catch (NumberFormatException e) { + throw new Exception("Priority should be an integer"); + } + } + + private void parseEndTime(String endTime) throws Exception { + try { + this.endTime = LocalTime.parse(endTime.strip()); + } catch (DateTimeParseException e) { + throw new Exception("End time provided is invalid or in wrong format (Should be HH:MM)"); + } + } + + private void parseStartTime(String startTime) throws Exception { + try { + this.startTime = LocalTime.parse(startTime.strip()); + } catch (DateTimeParseException e) { + throw new Exception("Start time provided is invalid or in wrong format (Should be HH:MM)"); + } + } + + private void parseDate(String date) throws Exception { + try { + this.date = LocalDate.parse(date.strip()); + } catch (DateTimeParseException e) { + throw new Exception("Date provided is invalid or is in wrong format (Should be YYYY-MM-DD)"); + } + + } + + private void parseDescription(String description) { + this.description = description; + } + + /** + * Returns the information related to information in form of a string. + * + * @return eventInfo Contains information related to the event. + */ + public String getTaskInformation() { + String eventInfo = "[E] " + description + " at " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + + " from " + startTime.toString() + " to " + endTime.toString() + " with priority " + priority; + return eventInfo; + } + + /** + * Returns the priority of the specified event. + * + * @return Priority of event. + */ + public int getPriority() { + return priority; + } + + /** + * Returns the date of the event. + * + * @return Date of event. + */ + public LocalDate getDate() { + return date; + } + + /** + * Used to identify if the string contains the keyword specified in its description. + * + * @param keyword The keyword to be matched with the description. + * @return containsKeyword Indicates the presence/absence of keyword in the event's description. + * @throws Exception If keyword entered is empty. + */ + public boolean hasKeyword(String keyword) throws Exception { + if (keyword.equals("")) { + throw new Exception("Keyword is empty"); + } + boolean containsKeyword = description.contains(keyword); + return containsKeyword; + } + + /** + * Returns the event in the format used to store it in the data file. + * + * @return formattedEventDetails Contains the event details in the required format. + */ + public String getFormattedDetails() { + String formattedEventDetails = "E#" + description + "#" + date + "#" + startTime + "#" + endTime + "#" + + priority + "\n"; + return formattedEventDetails; + } + + /** + * Edits the event at the index specified. + * + * @param ui Used to interact with the user. + * @return Newly updated event. + */ + public Event editEvent(Ui ui) { + printOptionsToEdit(ui); + int fieldToBeEdited = 0; + fieldToBeEdited = getFieldToBeEdited(ui, false, fieldToBeEdited); + switch (fieldToBeEdited) { + case EDIT_DESCRIPTION: + editDescription(ui); + break; + case EDIT_DATE: + editDate(ui); + break; + case EDIT_START_TIME: + editStartTime(ui); + break; + case EDIT_END_TIME: + editEndTime(ui); + break; + case EDIT_PRIORITY: + editPriority(ui); + break; + default: + ui.printMessage(ERROR_MESSAGE); + break; + } + printUpdatedDetails(ui); + return this; + } + + private void editPriority(Ui ui) { + boolean exceptionEncountered; + do { + exceptionEncountered = false; + ui.printMessage("Enter new priority:"); + String newPriorityString = ui.getUserIn(); + try { + parsePriority(newPriorityString); + } catch (Exception e) { + ui.printMessage(e.getMessage()); + exceptionEncountered = true; + } + } while (exceptionEncountered); + } + + private void editEndTime(Ui ui) { + boolean exceptionEncountered; + do { + exceptionEncountered = false; + ui.printMessage("Enter new End Time:"); + String newEndTimeString = ui.getUserIn(); + try { + parseEndTime(newEndTimeString); + if (this.endTime.isBefore(this.startTime)) { + throw new Exception("End time should be after start time"); + } + } catch (Exception e) { + ui.printMessage(e.getMessage()); + exceptionEncountered = true; + } + } while (exceptionEncountered); + } + + private void editStartTime(Ui ui) { + boolean exceptionEncountered; + do { + exceptionEncountered = false; + ui.printMessage("Enter new Start Time:"); + String newStartTimeString = ui.getUserIn(); + try { + parseStartTime(newStartTimeString); + } catch (Exception e) { + ui.printMessage(e.getMessage()); + exceptionEncountered = true; + } + } while (exceptionEncountered); + } + + private void editDate(Ui ui) { + boolean exceptionEncountered; + do { + exceptionEncountered = false; + ui.printMessage("Enter new Date:"); + String newDateString = ui.getUserIn(); + try { + parseDate(newDateString); + } catch (Exception e) { + ui.printMessage(e.getMessage()); + exceptionEncountered = true; + } + } while (exceptionEncountered); + } + + private void editDescription(Ui ui) { + ui.printMessage("Enter new description:"); + String newDescription = ui.getUserIn(); + parseDescription(newDescription); + } + + private int getFieldToBeEdited(Ui ui, boolean exceptionEncountered, int fieldToBeEdited) { + do { + exceptionEncountered = false; + try { + fieldToBeEdited = Integer.parseInt(ui.getUserIn()); + if (fieldToBeEdited > 5 || fieldToBeEdited < 0) { + throw new Exception(); + } + } catch (Exception exception) { + ui.printMessage("Please enter a valid number"); + exceptionEncountered = true; + } + } while (exceptionEncountered); + return fieldToBeEdited; + } + + private void printUpdatedDetails(Ui ui) { + ui.printMessage("Updated Details:"); + ui.printMessage(this.getTaskInformation()); + ui.printLine(); + } + + private void printOptionsToEdit(Ui ui) { + ui.printLine(); + ui.printMessage("The event details are as follows:"); + ui.printMessage(this.getTaskInformation()); + ui.printMessage("Which field of the event to edit? (Enter Corresponding Number)"); + ui.printMessage("1. Description"); + ui.printMessage("2. Date"); + ui.printMessage("3. Start Time"); + ui.printMessage("4. End Time"); + ui.printMessage("5. Priority"); + ui.printEmptyLine(); + } +} diff --git a/src/main/java/task/Task.java b/src/main/java/task/Task.java index 7bfd6e1fa..c4ccbb843 100644 --- a/src/main/java/task/Task.java +++ b/src/main/java/task/Task.java @@ -4,6 +4,8 @@ public abstract class Task { + public TaskType taskType; + public abstract int getPriority(); public abstract LocalDate getDate(); diff --git a/src/main/java/task/TaskList.java b/src/main/java/task/TaskList.java index 498811e89..0a88a1eac 100644 --- a/src/main/java/task/TaskList.java +++ b/src/main/java/task/TaskList.java @@ -1,13 +1,12 @@ package task.event; -import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import task.Event; import task.Task; -import task.TaskType; -import task.deadline.Deadline; +import task.Deadline; import ui.Ui; /** @@ -96,9 +95,58 @@ public void deleteTask(int index, Ui ui) { ui.printMessage("Invalid index entered. Please enter a valid index to be deleted"); ui.printLine(); } + } + /** + * Calls a helper function to edit the task at the specified index. + * + * @param ui This allows TaskList class to interact with User. + * @param index The index (1-based) of the task to be deleted. + */ + public void editTask(int index, Ui ui) { + ui.printLine(); + try { + if (index > tasks.size() | index <= 0) { + throw new IndexOutOfBoundsException(); + } + /* Converting to '0' based index */ + editTaskAtIndex(index - 1, ui); + ui.printLine(); + ui.printMessage("The task at the mentioned index has been edited successfully"); + ui.printLine(); + } catch (IndexOutOfBoundsException e) { + ui.printMessage("Invalid index entered. Please enter a valid index to be edited"); + ui.printLine(); + } + } + + + /** + * Edits the task at the specified index. + * + * @param index The index of the task to be edited. + * @param ui This allows TaskList class to interact with User. + * @throws IndexOutOfBoundsException If the index provided is invalid (i.e, out of bounds). + */ + private void editTaskAtIndex(int index, Ui ui) throws IndexOutOfBoundsException { + switch (tasks.get(index).taskType) { + case Event: + Event oldEvent = (Event) tasks.get(index); + Event updatedEvent = oldEvent.editEvent(ui); + tasks.set(index, updatedEvent); + break; + case Deadline: + Deadline oldDeadline = (Deadline) tasks.get(index); + Deadline updatedDeadline = oldDeadline.editDeadline(ui); + tasks.set(index, updatedDeadline); + break; + default: + ui.printMessage("Error encountered during execution"); + break; + } } + /** * Clears all the tasks currently stored. * @@ -175,64 +223,3 @@ public void searchTasks(String keyword, Ui ui) throws Exception { } } - - -/* - - public void add(String taskDetails, Ui ui, TaskType taskType) { - switch (taskType) { - case Deadline: - addNewDeadline(taskDetails,ui); - break; - case Event: - addNewEvent(taskDetails, ui); - break; - default: - ui.printMessage("Error encountered during execution"); - break; - } - } - - private void addNewEvent(String eventDetails, Ui ui) { - try { - String[] details = eventDetails.split(" ",2)[1].split("/"); - String description = details[0]; - String date = details[1].substring(2); - String startTime = details[2].substring(2); - String endTime = details[3].substring(2); - String priority = details[4].substring(2); - Event newEvent = new Event(description,date,startTime,endTime,priority); - addTask(newEvent, ui); - } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { - ui.printLine(); - ui.printMessage("Wrong format to add events"); - ui.printLine(); - } catch (Exception e) { - ui.printLine(); - ui.printMessage(e.getMessage()); - ui.printLine(); - } - } - - private void addNewDeadline(String deadlineDetails, Ui ui) { - try { - String[] details = deadlineDetails.split(" ",2)[1].split("/"); - String description = details[0]; - String date = details[1].substring(2); - String dueTime = details[2].substring(2); - String priority = details[3].substring(2); - Deadline newDeadline = new Deadline(description,date,dueTime, priority); - addTask(newDeadline, ui); - } catch (IndexOutOfBoundsException | DateTimeParseException | NullPointerException e) { - ui.printLine(); - ui.printMessage("Wrong format to add deadlines"); - ui.printLine(); - } catch (Exception e) { - ui.printLine(); - ui.printMessage(e.getMessage()); - ui.printLine(); - } - } - -} -*/ \ No newline at end of file diff --git a/src/main/java/task/deadline/Deadline.java b/src/main/java/task/deadline/Deadline.java deleted file mode 100644 index 411e558e2..000000000 --- a/src/main/java/task/deadline/Deadline.java +++ /dev/null @@ -1,120 +0,0 @@ -package task.deadline; - -import task.Task; - -import java.time.LocalDate; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; - -/** - * Represents an deadline and contains the related functions. - */ -public class Deadline extends Task { - - private String description; - private LocalDate date; - private LocalTime dueTime; - private int priority; - - /** - * Constructor for Deadline - *Class. - * - * @param description Description of the deadline. - * @param date Date of specified Deadline - * @param dueTime Due time of specified deadline. - * @param priority Priority of specified deadline. - * @throws Exception If wrong format is used for date, time fields. - */ - public Deadline(String description, String date, String dueTime, String priority) throws Exception { - parseDescription(description); - parseDate(date); - parseDueTime(dueTime); - parsePriority(priority); - } - - private void parsePriority(String priority) throws Exception { - try { - this.priority = Integer.parseInt(priority.strip()); - } catch (NumberFormatException e) { - throw new Exception("Priority should be an integer"); - } - } - - private void parseDueTime(String dueTime) throws Exception { - try { - this.dueTime = LocalTime.parse(dueTime.strip()); - } catch (DateTimeParseException e) { - throw new Exception("Due time provided is invalid or in wrong format (Should be HH:MM)"); - } - } - - private void parseDate(String date) throws Exception { - try { - this.date = LocalDate.parse(date.strip()); - } catch (DateTimeParseException e) { - throw new Exception("Date provided is invalid or is in wrong format (Should be YYYY-MM-DD)"); - } - - } - - private void parseDescription(String description) { - this.description = description; - } - - /** - * Returns the information related to information in form of a string. - * - * @return deadlineInfo Contains information related to the deadline. - */ - public String getTaskInformation() { - String deadlineInfo = "[D] " + description + " on " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) - + " at " + dueTime.toString(); - return deadlineInfo; - } - - /** - * Returns the priority of the specified deadline. - * - * @return Priority of deadline. - */ - public int getPriority() { - return priority; - } - - - /** - * Returns the date of the deadline. - * - * @return Date of deadline. - */ - public LocalDate getDate() { - return date; - } - - /** - * Used to identify if the string contains the keyword specified in its description. - * - * @param keyword The keyword to be matched with the description. - * @return containsKeyword Indicates the presence/absence of keyword in the deadline's description. - * @throws Exception If no keyword is entered. - */ - public boolean hasKeyword(String keyword) throws Exception { - if (keyword.equals("")) { - throw new Exception("Keyword is empty"); - } - boolean containsKeyword = description.contains(keyword); - return containsKeyword; - } - - /** - * Returns the deadline in the format used to store it in the data file. - * - * @return formattedDeadlineDetails Contains the deadline details in the required format. - */ - public String getFormattedDetails() { - String formattedDeadlineDetails = "D#" + description + "#" + date + "#" + dueTime + "#" + priority + "\n"; - return formattedDeadlineDetails; - } -} \ No newline at end of file diff --git a/src/main/java/task/event/Event.java b/src/main/java/task/event/Event.java deleted file mode 100644 index 008b51f74..000000000 --- a/src/main/java/task/event/Event.java +++ /dev/null @@ -1,137 +0,0 @@ -package task.event; - -import task.Task; - -import java.time.LocalDate; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; - -/** - * Represents an event and contains the related functions. - */ -public class Event extends Task { - - private String description; - private LocalDate date; - private LocalTime startTime; - private LocalTime endTime; - private int priority; - - /** - * Constructor for Event Class. - * - * @param description Description of the event. - * @param date Date of specified Event. - * @param startTime Start time of specified event. - * @param endTime End time of specified event. - * @param priority Priority of specified event. - * @throws Exception If wrong format is used for date, time or priority fields. - */ - public Event(String description, String date, String startTime, String endTime, String priority) - throws Exception { - parseDescription(description); - parseDate(date); - parseStartTime(startTime); - parseEndTime(endTime); - parsePriority(priority); - if (this.startTime.isAfter(this.endTime)) { - throw new Exception("Start time should be before End time"); - } - if (this.date.isBefore(LocalDate.now())) { - throw new Exception("Date specified must be a current or a future date"); - } - } - - private void parsePriority(String priority) throws Exception { - try { - this.priority = Integer.parseInt(priority.strip()); - } catch (NumberFormatException e) { - throw new Exception("Priority should be an integer"); - } - } - - private void parseEndTime(String endTime) throws Exception { - try { - this.endTime = LocalTime.parse(endTime.strip()); - } catch (DateTimeParseException e) { - throw new Exception("End time provided is invalid or in wrong format (Should be HH:MM)"); - } - } - - private void parseStartTime(String startTime) throws Exception { - try { - this.startTime = LocalTime.parse(startTime.strip()); - } catch (DateTimeParseException e) { - throw new Exception("Start time provided is invalid or in wrong format (Should be HH:MM)"); - } - } - - private void parseDate(String date) throws Exception { - try { - this.date = LocalDate.parse(date.strip()); - } catch (DateTimeParseException e) { - throw new Exception("Date provided is invalid or is in wrong format (Should be YYYY-MM-DD)"); - } - - } - - private void parseDescription(String description) { - this.description = description; - } - - /** - * Returns the information related to information in form of a string. - * - * @return eventInfo Contains information related to the event. - */ - public String getTaskInformation() { - String eventInfo = "[E] " + description + " at " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) - + " from " + startTime.toString() + " to " + endTime.toString(); - return eventInfo; - } - - /** - * Returns the priority of the specified event. - * - * @return Priority of event. - */ - public int getPriority() { - return priority; - } - - /** - * Returns the date of the event. - * - * @return Date of event. - */ - public LocalDate getDate() { - return date; - } - - /** - * Used to identify if the string contains the keyword specified in its description. - * - * @param keyword The keyword to be matched with the description. - * @return containsKeyword Indicates the presence/absence of keyword in the event's description. - * @throws Exception If keyword entered is empty. - */ - public boolean hasKeyword(String keyword) throws Exception { - if (keyword.equals("")) { - throw new Exception("Keyword is empty"); - } - boolean containsKeyword = description.contains(keyword); - return containsKeyword; - } - - /** - * Returns the event in the format used to store it in the data file. - * - * @return formattedEventDetails Contains the event details in the required format. - */ - public String getFormattedDetails() { - String formattedEventDetails = "E#" + description + "#" + date + "#" + startTime + "#" + endTime + "#" - + priority + "\n"; - return formattedEventDetails; - } -} diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 69f45298d..42a3d489c 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -55,7 +55,7 @@ public class Ui { + " your task list! If you are in the mood to mug and you" + " want to start your study area list, enter \"study\" !If" + " you want to exit, enter \"bye\" !"; - public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; + public static final String WRONG_INPUT = "Wrong input! Please enter either \"task\" or \"study\" only!"; public static final String TASK_COMMAND = "task"; public static final String STUDY_COMMAND = "study"; public static final String GOODBYE_MESSAGE = " Goodbye! Hope to see you again!"; @@ -142,6 +142,16 @@ public String getUserIn() { return this.in.nextLine(); } + /** + * This method allows for other classes to get the integer given by the User as input. + * + * @return int input from user. + */ + public int getIntegerInput() { + return this.in.nextInt(); + } + + /** * This method closes the Input Stream after usage is completed. */ @@ -224,6 +234,14 @@ public void printWelcomeMessage() { printLine(); } + /** + * Prints the string without a new line character. + * @param line The line to be printed. + */ + public void print(String line) { + this.out.print(line); + } + /** * Prints an empty line. */ diff --git a/src/test/java/task/event/TaskListTest.java b/src/test/java/task/event/TaskListTest.java index 0f09db8d9..28fdd0585 100644 --- a/src/test/java/task/event/TaskListTest.java +++ b/src/test/java/task/event/TaskListTest.java @@ -1,6 +1,7 @@ package task.event; import org.junit.jupiter.api.Test; +import task.Event; import ui.Ui; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/task/event/TaskTest.java b/src/test/java/task/event/TaskTest.java index b074ef8d7..5050280bc 100644 --- a/src/test/java/task/event/TaskTest.java +++ b/src/test/java/task/event/TaskTest.java @@ -1,6 +1,7 @@ package task.event; import org.junit.jupiter.api.Test; +import task.Event; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; From feed18cb2d1394e999b7af57d76bf202a15efd2e Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 10:55:54 +0800 Subject: [PATCH 080/435] Refactor code --- library/taskList.txt | 5 +- src/main/java/command/AddDeadlineCommand.java | 2 +- src/main/java/command/AddEventCommand.java | 2 +- src/main/java/command/ClearCommand.java | 2 +- src/main/java/command/Command.java | 2 +- src/main/java/command/CountdownCommand.java | 2 +- src/main/java/command/DeleteCommand.java | 2 +- src/main/java/command/EditCommand.java | 2 +- src/main/java/command/HelpCommand.java | 2 +- .../java/command/PriorityViewCommand.java | 2 +- src/main/java/command/SearchCommand.java | 2 +- src/main/java/command/TaskCommand.java | 2 +- src/main/java/command/ViewCommand.java | 2 +- .../command/IndexNotIntegerException.java | 2 +- src/main/java/parser/Parser.java | 12 ++- src/main/java/seedu/duke/Duke.java | 2 +- src/main/java/ui/Ui.java | 86 ++++++++++++------- src/test/java/task/event/TaskListTest.java | 4 +- 18 files changed, 83 insertions(+), 52 deletions(-) diff --git a/library/taskList.txt b/library/taskList.txt index b6448d4c8..c250d7656 100644 --- a/library/taskList.txt +++ b/library/taskList.txt @@ -1,2 +1,3 @@ -E#Hello#2020-04-05#10:00#13:00#2 -D#asdafs#2020-04-05#12:00#121 +D#homework #2020-07-06#12:00#2 +D#Hi#2020-07-05#12:00#2 +E#meeting #2020-05-06#12:00#14:00#1 diff --git a/src/main/java/command/AddDeadlineCommand.java b/src/main/java/command/AddDeadlineCommand.java index 82cc098e5..7600204e3 100644 --- a/src/main/java/command/AddDeadlineCommand.java +++ b/src/main/java/command/AddDeadlineCommand.java @@ -2,7 +2,7 @@ import exception.command.EventDetailsNotProvidedException; import task.Deadline; -import task.event.TaskList; +import task.TaskList; import ui.Ui; /** diff --git a/src/main/java/command/AddEventCommand.java b/src/main/java/command/AddEventCommand.java index b2ecde028..9e45950cd 100644 --- a/src/main/java/command/AddEventCommand.java +++ b/src/main/java/command/AddEventCommand.java @@ -2,7 +2,7 @@ import exception.command.EventDetailsNotProvidedException; import task.Event; -import task.event.TaskList; +import task.TaskList; import ui.Ui; /** diff --git a/src/main/java/command/ClearCommand.java b/src/main/java/command/ClearCommand.java index 786c8a1c0..46c78c9cf 100644 --- a/src/main/java/command/ClearCommand.java +++ b/src/main/java/command/ClearCommand.java @@ -1,7 +1,7 @@ package command; import exception.command.MisuseOfClearCommandException; -import task.event.TaskList; +import task.TaskList; import ui.Ui; /** diff --git a/src/main/java/command/Command.java b/src/main/java/command/Command.java index 361ce1afc..3bf2d0276 100644 --- a/src/main/java/command/Command.java +++ b/src/main/java/command/Command.java @@ -1,6 +1,6 @@ package command; -import task.event.TaskList; +import task.TaskList; import ui.Ui; /** diff --git a/src/main/java/command/CountdownCommand.java b/src/main/java/command/CountdownCommand.java index ba2380881..21e50c32c 100644 --- a/src/main/java/command/CountdownCommand.java +++ b/src/main/java/command/CountdownCommand.java @@ -1,7 +1,7 @@ package command; import exception.command.MisuseOfCountdownCommandException; -import task.event.TaskList; +import task.TaskList; import ui.Ui; /** diff --git a/src/main/java/command/DeleteCommand.java b/src/main/java/command/DeleteCommand.java index fd3ad83e7..dee9edeb2 100644 --- a/src/main/java/command/DeleteCommand.java +++ b/src/main/java/command/DeleteCommand.java @@ -2,7 +2,7 @@ import exception.command.DeleteCommandMissingIndexException; import exception.command.IndexNotIntegerException; -import task.event.TaskList; +import task.TaskList; import ui.Ui; /** diff --git a/src/main/java/command/EditCommand.java b/src/main/java/command/EditCommand.java index 287240976..e7b845ca1 100644 --- a/src/main/java/command/EditCommand.java +++ b/src/main/java/command/EditCommand.java @@ -2,7 +2,7 @@ import exception.command.EditCommandMissingIndexException; import exception.command.IndexNotIntegerException; -import task.event.TaskList; +import task.TaskList; import ui.Ui; /** diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java index df755864f..88396124c 100644 --- a/src/main/java/command/HelpCommand.java +++ b/src/main/java/command/HelpCommand.java @@ -1,6 +1,6 @@ package command; -import task.event.TaskList; +import task.TaskList; import ui.Ui; /** diff --git a/src/main/java/command/PriorityViewCommand.java b/src/main/java/command/PriorityViewCommand.java index 6e911a8ef..227d961f8 100644 --- a/src/main/java/command/PriorityViewCommand.java +++ b/src/main/java/command/PriorityViewCommand.java @@ -1,7 +1,7 @@ package command; import exception.command.MisuseOfPriorityCommandException; -import task.event.TaskList; +import task.TaskList; import ui.Ui; /** diff --git a/src/main/java/command/SearchCommand.java b/src/main/java/command/SearchCommand.java index 1bd9c07c5..d67ffa196 100644 --- a/src/main/java/command/SearchCommand.java +++ b/src/main/java/command/SearchCommand.java @@ -1,7 +1,7 @@ package command; import exception.command.SearchMissingTermsException; -import task.event.TaskList; +import task.TaskList; import ui.Ui; /** diff --git a/src/main/java/command/TaskCommand.java b/src/main/java/command/TaskCommand.java index d4ab823ee..095163f65 100644 --- a/src/main/java/command/TaskCommand.java +++ b/src/main/java/command/TaskCommand.java @@ -1,7 +1,7 @@ package command; import parser.Parser; -import task.event.TaskList; +import task.TaskList; import ui.Ui; import static ui.Ui.BYE_COMMAND; diff --git a/src/main/java/command/ViewCommand.java b/src/main/java/command/ViewCommand.java index 4469affef..fdb5931f7 100644 --- a/src/main/java/command/ViewCommand.java +++ b/src/main/java/command/ViewCommand.java @@ -1,7 +1,7 @@ package command; import exception.command.MisuseOfViewCommandException; -import task.event.TaskList; +import task.TaskList; import ui.Ui; /** diff --git a/src/main/java/exception/command/IndexNotIntegerException.java b/src/main/java/exception/command/IndexNotIntegerException.java index bc897d706..3eb58ff77 100644 --- a/src/main/java/exception/command/IndexNotIntegerException.java +++ b/src/main/java/exception/command/IndexNotIntegerException.java @@ -5,6 +5,6 @@ public class IndexNotIntegerException extends CustomException { public IndexNotIntegerException() { super("Enter a valid integer index (1-based) to delete/edit the corresponding event " - + "(format: delete index)"); + + "(format: delete/edit index)"); } } \ No newline at end of file diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java index d41d931eb..64914e5cf 100644 --- a/src/main/java/parser/Parser.java +++ b/src/main/java/parser/Parser.java @@ -1,6 +1,16 @@ package parser; -import command.*; +import command.AddDeadlineCommand; +import command.AddEventCommand; +import command.ClearCommand; +import command.Command; +import command.CountdownCommand; +import command.DeleteCommand; +import command.EditCommand; +import command.HelpCommand; +import command.PriorityViewCommand; +import command.SearchCommand; +import command.ViewCommand; /** * This class is used to parse the user input into executable commands. diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index d118ae7d6..53d609344 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -7,7 +7,7 @@ import resourceloader.StudyAreaLoader; import studyarea.IllegalStudyAreaException; import studyarea.StudyAreaList; -import task.event.TaskList; +import task.TaskList; import ui.Ui; import java.io.File; diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 42a3d489c..da49c9767 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -2,7 +2,6 @@ import studyarea.StudyArea; -import java.io.File; import java.io.InputStream; import java.io.PrintStream; import java.util.Scanner; @@ -19,7 +18,7 @@ public class Ui { public static final String MISSING_STUDY_AREA_DATA = "locations.txt is missing"; public static final String BYE_COMMAND = "bye"; - public static final String BYE_MESSAGE = "Bye!!!!!!"; + public static final String BYE_MESSAGE = "Exiting task interface"; public static final String LINE = "_______________________________________________________________________________" + "_________________________"; public static final int MAX_LINE_LENGTH = 55; @@ -49,6 +48,39 @@ public class Ui { public static final String INCONSISTENT_DATA_STORAGE = "Data is wrongly stored in locations.txt"; public static final String HELP_COMMAND = "help"; public static final String TAB = "\t "; + public static final String HELP_DESCRIPTION_20 = TAB + "*There are 4 levels of priority, with 1 being the most " + + "urgent, and 4 being the least urgent"; + public static final String HELP_DESCRIPTION_19 = TAB + "*All timing should follow 24 hour clock"; + public static final String HELP_DESCRIPTION_18 = TAB + "*All dates should follow YYYY-MM-DD format"; + public static final String HELP_DESCRIPTION_17 = TAB + "Notes:"; + public static final String HELP_DESCRIPTION_16 = TAB + "bye --------------------------------------- Terminate task" + + " interface"; + public static final String HELP_DESCRIPTION_15 = TAB + "help -------------------------------------- View List Of " + + "Commands Supported"; + public static final String HELP_DESCRIPTION_14 = TAB + "edit -------------- Edit the task"; + public static final String HELP_DESCRIPTION_13 = TAB + "delete ------------ Delete the " + + "task"; + public static final String HELP_DESCRIPTION_12 = TAB + "search ----------- View existing " + + "task that contains the keyword"; + public static final String HELP_DESCRIPTION_11 = TAB + "clear ------------------------------------- Delete" + + " all tasks"; + public static final String HELP_DESCRIPTION_10 = TAB + "countdown --------------------------------- View existing" + + " tasks based on days left"; + public static final String HELP_DESCRIPTION_9 = TAB + "priority_view ----------------------------- View existing " + + "tasks based on priority"; + public static final String HELP_DESCRIPTION_8 = TAB + "view -------------------------------------- View existing" + + " events"; + public static final String HELP_DESCRIPTION_7 = TAB + "------------------------------------------- Create a new " + + "deadline"; + public static final String HELP_DESCRIPTION_5 = TAB + "deadline /d /t /p " + + ""; + public static final String HELP_DESCRIPTION_4 = TAB + "------------------------------------------- Create a new " + + "event"; + public static final String HELP_DESCRIPTION_3 = TAB + "event /d /s " + + "/e /p "; + public static final String HELP_DESCRIPTION_2 = TAB + "Please enter the keywords followed by the information" + + " shown in the brackets"; + public static final String HELP_DESCRIPTION_1 = TAB + "OrgaNice! Supports the following commands"; public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"task\" to start\n" @@ -234,14 +266,6 @@ public void printWelcomeMessage() { printLine(); } - /** - * Prints the string without a new line character. - * @param line The line to be printed. - */ - public void print(String line) { - this.out.print(line); - } - /** * Prints an empty line. */ @@ -254,29 +278,25 @@ public void printEmptyLine() { */ public void printHelp() { printLine(); - this.out.println(TAB + "OrgaNice! Supports the following commands"); - this.out.println(TAB + "Please enter the keywords followed by the information shown in the brackets"); - this.out.println(TAB + "event /d /s /e /p "); - this.out.println(TAB + "deadline /d /t /p "); - this.out.println(TAB + "------------------------------------------- Create a new event"); - this.out.println(TAB + "view -------------------------------------- View existing events"); - this.out.println(TAB + "priority_view ----------------------------- View existing events based " - + "on priority"); - this.out.println(TAB + "countdown --------------------------------- View existing events based on" - + " days left"); - this.out.println(TAB + "clear ------------------------------------- Delete all events"); - this.out.println(TAB + "search ----------- View existing events that contains " - + "the keyword"); - this.out.println(TAB + "delete ------------ Delete the event"); - this.out.println(TAB + "help -------------------------------------- View List Of Commands Supported"); - this.out.println(TAB + "bye --------------------------------------- Terminate program"); - this.out.println(TAB + "Notes:"); - this.out.println(TAB + "*All dates should follow YYYY-MM-DD format"); - this.out.println(TAB + "*All timing should follow 24 hour clock"); - this.out.println(TAB + "*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " - + "least urgent"); + this.out.println(HELP_DESCRIPTION_1); + this.out.println(HELP_DESCRIPTION_2); + this.out.println(HELP_DESCRIPTION_3); + this.out.println(HELP_DESCRIPTION_4); + this.out.println(HELP_DESCRIPTION_5); + this.out.println(HELP_DESCRIPTION_7); + this.out.println(HELP_DESCRIPTION_8); + this.out.println(HELP_DESCRIPTION_9); + this.out.println(HELP_DESCRIPTION_10); + this.out.println(HELP_DESCRIPTION_11); + this.out.println(HELP_DESCRIPTION_12); + this.out.println(HELP_DESCRIPTION_13); + this.out.println(HELP_DESCRIPTION_14); + this.out.println(HELP_DESCRIPTION_15); + this.out.println(HELP_DESCRIPTION_16); + this.out.println(HELP_DESCRIPTION_17); + this.out.println(HELP_DESCRIPTION_18); + this.out.println(HELP_DESCRIPTION_19); + this.out.println(HELP_DESCRIPTION_20); printLine(); } diff --git a/src/test/java/task/event/TaskListTest.java b/src/test/java/task/event/TaskListTest.java index 28fdd0585..91a7b29c5 100644 --- a/src/test/java/task/event/TaskListTest.java +++ b/src/test/java/task/event/TaskListTest.java @@ -13,10 +13,10 @@ class TaskListTest { Ui ui = new Ui(); - task.event.TaskList taskList; + task.TaskList taskList; public TaskListTest() throws Exception { - taskList = new task.event.TaskList(); + taskList = new task.TaskList(); taskList.addTask(new Event("Team Meeting", "2020-03-21", "09:00", "17:00", "1"),ui); } From 15dcad2364e8ec861b625d2461c87577bd79a5f2 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 10:56:33 +0800 Subject: [PATCH 081/435] Add support to show number of days left during countdown command --- src/main/java/task/Deadline.java | 22 +++++++++- src/main/java/task/Event.java | 14 +++++++ src/main/java/task/Task.java | 1 + src/main/java/task/TaskList.java | 55 +++++++++++++++--------- text-ui-test/EXPECTED.TXT | 72 ++++++++++++++++++++------------ 5 files changed, 117 insertions(+), 47 deletions(-) diff --git a/src/main/java/task/Deadline.java b/src/main/java/task/Deadline.java index 5a8abf8f5..ab1ae8f53 100644 --- a/src/main/java/task/Deadline.java +++ b/src/main/java/task/Deadline.java @@ -6,8 +6,11 @@ import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoUnit; -import static task.Event.*; +import static task.Event.EDIT_DATE; +import static task.Event.EDIT_DESCRIPTION; +import static task.Event.ERROR_MESSAGE; /** * Represents an deadline and contains the related functions. @@ -45,6 +48,20 @@ public Deadline(String description, String date, String dueTime, String priority parseDate(date); parseDueTime(dueTime); parsePriority(priority); + if (this.date.isBefore(LocalDate.now())) { + throw new Exception("Date specified must be a current or a future date"); + } + } + + + /** + * Returns the number of days left till the event. + * + * @return Number of days till deadline. + */ + @Override + public long numberOfDaysLeft() { + return ChronoUnit.DAYS.between(LocalDate.now(),this.date); } private void parsePriority(String priority) throws Exception { @@ -200,6 +217,9 @@ private void editDate(Ui ui) { String newDateString = ui.getUserIn(); try { parseDate(newDateString); + if (this.date.isBefore(LocalDate.now())) { + throw new Exception("Date specified must be a current or a future date"); + } } catch (Exception e) { ui.printMessage(e.getMessage()); exceptionEncountered = true; diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java index 01770cc9a..d2eeca81a 100644 --- a/src/main/java/task/Event.java +++ b/src/main/java/task/Event.java @@ -6,6 +6,7 @@ import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoUnit; /** * Represents an event and contains the related functions. @@ -107,6 +108,16 @@ public String getTaskInformation() { return eventInfo; } + /** + * Returns the number of days left till the event. + * + * @return Number of days till event. + */ + @Override + public long numberOfDaysLeft() { + return ChronoUnit.DAYS.between(LocalDate.now(),this.date); + } + /** * Returns the priority of the specified event. * @@ -241,6 +252,9 @@ private void editDate(Ui ui) { String newDateString = ui.getUserIn(); try { parseDate(newDateString); + if (this.date.isBefore(LocalDate.now())) { + throw new Exception("Date specified must be a current or a future date"); + } } catch (Exception e) { ui.printMessage(e.getMessage()); exceptionEncountered = true; diff --git a/src/main/java/task/Task.java b/src/main/java/task/Task.java index c4ccbb843..c4eb0fe92 100644 --- a/src/main/java/task/Task.java +++ b/src/main/java/task/Task.java @@ -16,4 +16,5 @@ public abstract class Task { public abstract String getTaskInformation(); + public abstract long numberOfDaysLeft(); } diff --git a/src/main/java/task/TaskList.java b/src/main/java/task/TaskList.java index 0a88a1eac..71cd8e902 100644 --- a/src/main/java/task/TaskList.java +++ b/src/main/java/task/TaskList.java @@ -1,12 +1,10 @@ -package task.event; +package task; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import task.Event; -import task.Task; -import task.Deadline; import ui.Ui; /** @@ -66,11 +64,15 @@ public void addTask(Task newTask, Ui ui) { */ public void listTasks(Ui ui) { ui.printLine(); - ui.printMessage("Here is the list of events added so far:"); - int eventNumber = 1; - for (Task task : tasks) { - ui.printMessage(eventNumber + ") " + task.getTaskInformation()); - eventNumber++; + if (tasks.size() > 0) { + ui.printMessage("Here is the list of events added so far:"); + int eventNumber = 1; + for (Task task : tasks) { + ui.printMessage(eventNumber + ") " + task.getTaskInformation()); + eventNumber++; + } + } else { + ui.printMessage("The list is empty."); } ui.printLine(); } @@ -169,15 +171,21 @@ public void priorityView(Ui ui) { tasksSortedByPriority.sort(Comparator.comparingInt(Task::getPriority)); Collections.reverse(tasksSortedByPriority); ui.printLine(); + if (tasks.size() > 0) { + printTasksSortedByPriority(ui, tasksSortedByPriority); + } else { + ui.printMessage("The list is empty."); + } + ui.printLine(); + } + + private void printTasksSortedByPriority(Ui ui, ArrayList tasksSortedByPriority) { int taskNumber = 1; + ui.printMessage("Here is the list of tasks added so far displayed in decreasing order of priority:"); for (Task task : tasksSortedByPriority) { ui.printMessage(taskNumber + ") " + task.getTaskInformation()); taskNumber++; } - if (taskNumber == 1) { - ui.printMessage("The list is empty."); - } - ui.printLine(); } /** @@ -189,17 +197,26 @@ public void countdownView(Ui ui) { ArrayList tasksSortedByDate = tasks; tasksSortedByDate.sort(Comparator.comparing(Task::getDate)); ui.printLine(); - int taskNumber = 1; - for (Task task : tasksSortedByDate) { - ui.printMessage(taskNumber + ") " + task.getTaskInformation()); - taskNumber++; - } - if (taskNumber == 1) { + if (tasks.size() > 0) { + printTasksSortedByDate(ui, tasksSortedByDate); + } else { ui.printMessage("The list is empty."); } ui.printLine(); } + private void printTasksSortedByDate(Ui ui, ArrayList tasksSortedByDate) { + int taskNumber = 1; + ui.printMessage("Here is the list of tasks with sorted based on the number of days left:"); + for (Task task : tasksSortedByDate) { + if (!task.getDate().isBefore(LocalDate.now())) { + ui.printMessage(taskNumber + ") " + task.getTaskInformation() + " ---> " + task.numberOfDaysLeft() + + " day(s) left"); + taskNumber++; + } + } + } + /** * Displays the list of tasks containing the keyword. * diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 560b7cea6..f6f2e0547 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -21,16 +21,18 @@ ________________________________________________________________________________ OrgaNice! Supports the following commands Please enter the keywords followed by the information shown in the brackets event /d /s /e /p - deadline /d /t /p ------------------------------------------- Create a new event + deadline /d /t /p + ------------------------------------------- Create a new deadline view -------------------------------------- View existing events - priority_view ----------------------------- View existing events based on priority - countdown --------------------------------- View existing events based on days left - clear ------------------------------------- Delete all events - search ----------- View existing events that contains the keyword - delete ------------ Delete the event + priority_view ----------------------------- View existing tasks based on priority + countdown --------------------------------- View existing tasks based on days left + clear ------------------------------------- Delete all tasks + search ----------- View existing task that contains the keyword + delete ------------ Delete the task + edit -------------- Edit the task help -------------------------------------- View List Of Commands Supported - bye --------------------------------------- Terminate program + bye --------------------------------------- Terminate task interface Notes: *All dates should follow YYYY-MM-DD format *All timing should follow 24 hour clock @@ -42,20 +44,26 @@ ________________________________________________________________________________ ________________________________________________________________________________________________________ A new event with the following information has been added. - [E] meeting at May 5 2020 from 12:00 to 13:00 + [E] meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ Here is the list of events added so far: - 1) [E] meeting at May 5 2020 from 12:00 to 13:00 + 1) [E] meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ A new event with the following information has been added. - [D] assignment on May 2 2020 at 14:00 + [D] assignment on May 2 2020 at 14:00 with priority 2 ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ - 1) [D] assignment on May 2 2020 at 14:00 - 2) [E] meeting at May 5 2020 from 12:00 to 13:00 + Here is the list of tasks added so far displayed in + decreasing order of priority: + 1) [D] assignment on May 2 2020 at 14:00 with priority + 2 + 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ Invalid index entered. Please enter a valid index to be @@ -65,8 +73,8 @@ ________________________________________________________________________________ Index 1 out of bounds for length 1 ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ - Enter a valid integer index (1-based) to delete the - corresponding event (format: delete index) + Enter a valid integer index (1-based) to delete/edit + the corresponding event (format: delete/edit index) ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ Event details are not provided @@ -78,11 +86,15 @@ ________________________________________________________________________________ Invalid command entered, Please enter a valid command ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ - 1) [D] assignment on May 2 2020 at 14:00 - 2) [E] meeting at May 5 2020 from 12:00 to 13:00 + Here is the list of tasks with sorted based on the + number of days left: + 1) [D] assignment on May 2 2020 at 14:00 with priority + 2 ---> 49 day(s) left + 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 ---> 52 day(s) left ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ - Bye!!!!!! + Exiting task interface ________________________________________________________________________________________________________ Please enter "event" to continue with your event list or "study" to continue with your study area list. To @@ -92,16 +104,18 @@ ________________________________________________________________________________ OrgaNice! Supports the following commands Please enter the keywords followed by the information shown in the brackets event /d /s /e /p - deadline /d /t /p ------------------------------------------- Create a new event + deadline /d /t /p + ------------------------------------------- Create a new deadline view -------------------------------------- View existing events - priority_view ----------------------------- View existing events based on priority - countdown --------------------------------- View existing events based on days left - clear ------------------------------------- Delete all events - search ----------- View existing events that contains the keyword - delete ------------ Delete the event + priority_view ----------------------------- View existing tasks based on priority + countdown --------------------------------- View existing tasks based on days left + clear ------------------------------------- Delete all tasks + search ----------- View existing task that contains the keyword + delete ------------ Delete the task + edit -------------- Edit the task help -------------------------------------- View List Of Commands Supported - bye --------------------------------------- Terminate program + bye --------------------------------------- Terminate task interface Notes: *All dates should follow YYYY-MM-DD format *All timing should follow 24 hour clock @@ -112,11 +126,15 @@ ________________________________________________________________________________ be :countdown ) ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ - 1) [D] assignment on May 2 2020 at 14:00 - 2) [E] meeting at May 5 2020 from 12:00 to 13:00 + Here is the list of tasks with sorted based on the + number of days left: + 1) [D] assignment on May 2 2020 at 14:00 with priority + 2 ---> 49 day(s) left + 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 ---> 52 day(s) left ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ - Bye!!!!!! + Exiting task interface ________________________________________________________________________________________________________ Please enter "event" to continue with your event list or "study" to continue with your study area list. To From 26b7fd39b9f9ab406a220896d468aead2cd082e6 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 11:01:43 +0800 Subject: [PATCH 082/435] Update JUnit tests --- src/test/java/parser/ParserTest.java | 4 ++-- src/test/java/task/event/TaskTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/parser/ParserTest.java b/src/test/java/parser/ParserTest.java index f3f2be54a..4933862c8 100644 --- a/src/test/java/parser/ParserTest.java +++ b/src/test/java/parser/ParserTest.java @@ -135,8 +135,8 @@ void parseCommand_invalidDeleteCommand_throwException() { command = parser.parseCommand("delete one"); fail("Invalid delete command not identified"); } catch (Exception exception) { - assertEquals("Enter a valid integer index (1-based) to delete the corresponding event " - + "(format: delete index)", + assertEquals("Enter a valid integer index (1-based) to delete/edit the corresponding event " + + "(format: delete/edit index)", exception.getMessage()); } } diff --git a/src/test/java/task/event/TaskTest.java b/src/test/java/task/event/TaskTest.java index 5050280bc..5763c8870 100644 --- a/src/test/java/task/event/TaskTest.java +++ b/src/test/java/task/event/TaskTest.java @@ -13,7 +13,7 @@ class TaskTest { @Test void eventInformation() throws Exception { - assertEquals("[E] Team Meeting at Mar 21 2020 from 09:00 to 17:00", + assertEquals("[E] Team Meeting at Mar 21 2020 from 09:00 to 17:00 with priority 1", new Event("Team Meeting", "2020-03-21", "09:00", "17:00", "1").getTaskInformation()); } From 972819b92ae8184808495ce59f944a5cf4e77fbb Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 11:37:45 +0800 Subject: [PATCH 083/435] Refactor code --- src/main/java/task/TaskList.java | 26 ++++++-- src/main/java/ui/Ui.java | 6 +- text-ui-test/EXPECTED.TXT | 100 +++++++++++++++++++++++++++--- text-ui-test/input.txt | 16 +++++ text-ui-test/library/taskList.txt | 2 +- 5 files changed, 131 insertions(+), 19 deletions(-) diff --git a/src/main/java/task/TaskList.java b/src/main/java/task/TaskList.java index 71cd8e902..a26c2290f 100644 --- a/src/main/java/task/TaskList.java +++ b/src/main/java/task/TaskList.java @@ -225,18 +225,34 @@ private void printTasksSortedByDate(Ui ui, ArrayList tasksSortedByDate) { * @throws Exception If the keyword is empty. */ public void searchTasks(String keyword, Ui ui) throws Exception { - int taskNumber = 1; + boolean hasMatchedTask = checkForMatchedTasks(keyword); + if (hasMatchedTask) { + printMatchedTasks(keyword, ui); + } else { + ui.printMessage("The list is empty."); + } ui.printLine(); + } + + private boolean checkForMatchedTasks(String keyword) throws Exception { + boolean hasMatchedTask = false; + for (Task task : tasks) { + if (task.hasKeyword(keyword)) { + hasMatchedTask = true; + break; + } + } + return hasMatchedTask; + } + + private void printMatchedTasks(String keyword, Ui ui) throws Exception { + int taskNumber = 1; for (Task task : tasks) { if (task.hasKeyword(keyword)) { ui.printMessage(taskNumber + ") " + task.getTaskInformation()); taskNumber++; } } - if (taskNumber == 1) { - ui.printMessage("The list is empty."); - } - ui.printLine(); } } diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index da49c9767..f2ffbde25 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -57,10 +57,10 @@ public class Ui { + " interface"; public static final String HELP_DESCRIPTION_15 = TAB + "help -------------------------------------- View List Of " + "Commands Supported"; - public static final String HELP_DESCRIPTION_14 = TAB + "edit -------------- Edit the task"; - public static final String HELP_DESCRIPTION_13 = TAB + "delete ------------ Delete the " + public static final String HELP_DESCRIPTION_14 = TAB + "edit --------------- Edit the task"; + public static final String HELP_DESCRIPTION_13 = TAB + "delete ------------- Delete the " + "task"; - public static final String HELP_DESCRIPTION_12 = TAB + "search ----------- View existing " + public static final String HELP_DESCRIPTION_12 = TAB + "search ------------ View existing " + "task that contains the keyword"; public static final String HELP_DESCRIPTION_11 = TAB + "clear ------------------------------------- Delete" + " all tasks"; diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index f6f2e0547..7147ee072 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -28,9 +28,9 @@ ________________________________________________________________________________ priority_view ----------------------------- View existing tasks based on priority countdown --------------------------------- View existing tasks based on days left clear ------------------------------------- Delete all tasks - search ----------- View existing task that contains the keyword - delete ------------ Delete the task - edit -------------- Edit the task + search ------------ View existing task that contains the keyword + delete ------------- Delete the task + edit --------------- Edit the task help -------------------------------------- View List Of Commands Supported bye --------------------------------------- Terminate task interface Notes: @@ -65,6 +65,24 @@ ________________________________________________________________________________ 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 ________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Here is the list of events added so far: + 1) [D] assignment on May 2 2020 at 14:00 with priority + 2 + 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + The search string entered is empty. +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Empty Line entered, Please enter a valid line +________________________________________________________________________________________________________ + 1) [E] meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 +________________________________________________________________________________________________________ + The list is empty. +________________________________________________________________________________________________________ ________________________________________________________________________________________________________ Invalid index entered. Please enter a valid index to be deleted @@ -76,6 +94,68 @@ ________________________________________________________________________________ Enter a valid integer index (1-based) to delete/edit the corresponding event (format: delete/edit index) ________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Here is the list of events added so far: + 1) [D] assignment on May 2 2020 at 14:00 with priority + 2 + 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + The event details are as follows: + [E] meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 + Which field of the event to edit? (Enter Corresponding + Number) + 1. Description + 2. Date + 3. Start Time + 4. End Time + 5. Priority + + Please enter a valid number + Please enter a valid number + Enter new description: + Updated Details: + [E] team meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + The task at the mentioned index has been edited + successfully +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + Here is the list of events added so far: + 1) [D] assignment on May 2 2020 at 14:00 with priority + 2 + 2) [E] team meeting at May 5 2020 from 12:00 to 13:00 + with priority 1 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + The event details are as follows: + [E] team meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 + Which field of the event to edit? (Enter Corresponding + Number) + 1. Description + 2. Date + 3. Start Time + 4. End Time + 5. Priority + + Enter new Date: + Date specified must be a current or a future date + Enter new Date: + Updated Details: + [E] team meeting at Jun 6 2020 from 12:00 to 13:00 with + priority 1 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + The task at the mentioned index has been edited + successfully +________________________________________________________________________________________________________ ________________________________________________________________________________________________________ Event details are not provided ________________________________________________________________________________________________________ @@ -90,8 +170,8 @@ ________________________________________________________________________________ number of days left: 1) [D] assignment on May 2 2020 at 14:00 with priority 2 ---> 49 day(s) left - 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with - priority 1 ---> 52 day(s) left + 2) [E] team meeting at Jun 6 2020 from 12:00 to 13:00 + with priority 1 ---> 84 day(s) left ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ Exiting task interface @@ -111,9 +191,9 @@ ________________________________________________________________________________ priority_view ----------------------------- View existing tasks based on priority countdown --------------------------------- View existing tasks based on days left clear ------------------------------------- Delete all tasks - search ----------- View existing task that contains the keyword - delete ------------ Delete the task - edit -------------- Edit the task + search ------------ View existing task that contains the keyword + delete ------------- Delete the task + edit --------------- Edit the task help -------------------------------------- View List Of Commands Supported bye --------------------------------------- Terminate task interface Notes: @@ -130,8 +210,8 @@ ________________________________________________________________________________ number of days left: 1) [D] assignment on May 2 2020 at 14:00 with priority 2 ---> 49 day(s) left - 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with - priority 1 ---> 52 day(s) left + 2) [E] team meeting at Jun 6 2020 from 12:00 to 13:00 + with priority 1 ---> 84 day(s) left ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ Exiting task interface diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 5e4d28f31..61ad4cd64 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -5,9 +5,25 @@ event meeting /d 2020-05-05 /s 12:00 /e 13:00 /p 1 view deadline assignment /d 2020-05-02 /t 14:00 /p 2 priority_view +view +search + +search meet +search homework delete 3 event team meeting delete one +view +edit 2 +6 +-1 +1 +team meeting +view +edit 2 +2 +2020-01-01 +2020-06-06 event view list task diff --git a/text-ui-test/library/taskList.txt b/text-ui-test/library/taskList.txt index 840faf7dc..fa0db46bf 100644 --- a/text-ui-test/library/taskList.txt +++ b/text-ui-test/library/taskList.txt @@ -1,2 +1,2 @@ D#assignment #2020-05-02#14:00#2 -E#meeting #2020-05-05#12:00#13:00#1 +E#team meeting#2020-06-06#12:00#13:00#1 From f5a180db9296ec12f3e113e4361ebd589ced2b34 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sat, 14 Mar 2020 11:49:27 +0800 Subject: [PATCH 084/435] add Dictionary --- library/dictionary.txt | 10 +++++ library/locations.txt | 25 +++++++---- src/main/java/studyarea/Dictionary.java | 59 +++++++++++++++++++++++++ text-ui-test/EXPECTED.TXT | 4 +- text-ui-test/library/eventList.txt | 0 text-ui-test/library/locations.txt | 0 6 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 library/dictionary.txt create mode 100644 src/main/java/studyarea/Dictionary.java delete mode 100644 text-ui-test/library/eventList.txt delete mode 100644 text-ui-test/library/locations.txt diff --git a/library/dictionary.txt b/library/dictionary.txt new file mode 100644 index 000000000..e644c92a5 --- /dev/null +++ b/library/dictionary.txt @@ -0,0 +1,10 @@ +engineering~eng~engin~engine~foe +utown~university town~u-town~u town +maccommons~mccommons~mac commons +education resource centre~erc +stephen riady centre~stephen~riady~src +ocbc~frank~frank by ocbc +starbucks~bucks~bux~sbux +pc commons~pccommons~pccommon +yih~yusof ishak~yusof~ishak +supersnacks~super snacks~super snack diff --git a/library/locations.txt b/library/locations.txt index 42de138ad..25cc285e0 100644 --- a/library/locations.txt +++ b/library/locations.txt @@ -1,8 +1,17 @@ -MacCommons~2 College Ave West Education Resource Centre~Utown~true~true~5 -OCBC~2 College Ave West, Stephen Riady Centre~Utown~true~false~2 -EA Level 3~9 Engineering Drive 1,EA~Engineering~true~true~4 -EA Level 2~9 Engineering Drive 1~Engineering~true~true~4 -EA Level 1~9 Engineering Drive 1~Engineering~true~true~4 -EA Level 4~9 Engineering Drive 1, Outside Staff Offices~Engineering~true~false~6 -EA Level 5~9 Engineering Drive 1, Outside of the door beside EA05~Engineering~true~false~4 -EA Level 6~9 Engineering Drive 1, EA06-23~Engineering~true~true~4 \ No newline at end of file +Opposite Town Green (Outside Starbucks)~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~4 +Starbucks~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~5 +MacCommons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 +PC Commons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 +Ian and Peony Ferguson Study~2 College Ave West Education Resource Centre, Level 3~Utown~true~true~4 +The Study~2 College Ave West Education Resource Centre, Level 2~Utown~true~true~5 +Town Plaza Seminar Rooms Waiting Area~2 College Ave West, Town Plaza, Level 2~Utown~true~true~4 +OCBC~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~false~2 +SuperSnacks~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~true~4 +EA Level 1~9 Engineering Drive 1,EA, Level 1~Engineering~true~true~4 +EA Level 2~9 Engineering Drive 1,EA, Level 2~Engineering~true~true~4 +EA Level 3~9 Engineering Drive 1,EA, Level 3~Engineering~true~true~4 +EA Level 4~9 Engineering Drive 1,EA, Level 4, Outside Staff Offices~Engineering~true~false~6 +EA Level 5~9 Engineering Drive 1,EA, Level 5, Outside of the door beside EA05~Engineering~true~false~4 +EA Level 6~9 Engineering Drive 1,EA, Level 6, EA06-23~Engineering~true~true~4 +Central Library~Central Library 12 Kent Ridge Crescent~-~true~true~5 +YIH Study Room~Yusof Ishak House, Level 2~-~true~true~4 \ No newline at end of file diff --git a/src/main/java/studyarea/Dictionary.java b/src/main/java/studyarea/Dictionary.java new file mode 100644 index 000000000..dccc7f14a --- /dev/null +++ b/src/main/java/studyarea/Dictionary.java @@ -0,0 +1,59 @@ +package studyarea; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +import java.util.Scanner; + +public class SearchKeyDictionary { + + private static HashMap> dictionary = new HashMap<>(); + + public static void loadDictionary(){ + for(String temp : ENGINEERING){ + dictionary.put(temp, "engineering"); + } + for(String temp : ENGINEERING){ + dictionary.put(temp, "engineering"); + } + } + + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + loadDictionary(); + System.out.println("Engine: 0, Utown: 1 , Computing: 2 "); + System.out.println("Search by faculty: "); + + while (true) { + String input = in.nextLine(); + if(input.equals("bye")){ + break; + } + int index = 0; + String searchedFac = null; + for (HashSet faculty : Dictionary) { + if (faculty.contains(input)) { + break; + } + index++; + } + switch (index) { + case 0: + searchedFac = "Engineering"; + break; + case 1: + searchedFac = "Utown"; + break; + case 2: + searchedFac = "Computing"; + break; + default: + searchedFac = "not found"; + break; + } + System.out.println("Faculty searched is: " + searchedFac); + + } + } +} diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 0a7d67f55..ca7917837 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -14,8 +14,8 @@ ________________________________________________________________________________ Hello James Gosling! Welcome to OrgaNice! To start, enter "event" to start your event list! If you are in the mood to mug and you - want to start your study area list, enter "study" !If - you want to exit, enter "bye" ! + want to start your study area list, enter "study" !If you + want to exit, enter "bye" ! ____________________________________________________________________________________ ____________________________________________________________________________________ Goodbye! Hope to see you again! diff --git a/text-ui-test/library/eventList.txt b/text-ui-test/library/eventList.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/text-ui-test/library/locations.txt b/text-ui-test/library/locations.txt deleted file mode 100644 index e69de29bb..000000000 From 36c0a4d9a6f77c625e85e35d45bc60975d172806 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sat, 14 Mar 2020 11:51:40 +0800 Subject: [PATCH 085/435] add changes due to dictionary --- src/main/java/command/StudyAreaCommand.java | 33 +++-- src/main/java/resourceloader/EventLoader.java | 1 + .../java/resourceloader/StudyAreaLoader.java | 13 +- src/main/java/studyarea/Dictionary.java | 89 ++++++----- .../studyarea/IllegalStudyAreaException.java | 2 - src/main/java/studyarea/StudyArea.java | 5 +- src/main/java/studyarea/StudyAreaList.java | 138 +++++++++--------- src/main/java/ui/Ui.java | 3 +- text-ui-test/ACTUAL.TXT | 47 ------ 9 files changed, 143 insertions(+), 188 deletions(-) delete mode 100644 text-ui-test/ACTUAL.TXT diff --git a/src/main/java/command/StudyAreaCommand.java b/src/main/java/command/StudyAreaCommand.java index 25ac5d9e0..ad35eb78a 100644 --- a/src/main/java/command/StudyAreaCommand.java +++ b/src/main/java/command/StudyAreaCommand.java @@ -4,8 +4,10 @@ import studyarea.StudyArea; import studyarea.StudyAreaList; import ui.Ui; + import java.util.ArrayList; + /** * This is the StudyAreaCommand class. It executes the StudyArea Search function and interact with Users accordingly. */ @@ -46,26 +48,25 @@ public static boolean filterCommand(String command, StudyAreaList studyAreaList, throw new IllegalStudyAreaException(Ui.EMPTY_LOCATION); } else { switch (command) { - case Ui.BYE_COMMAND: - ui.printMessage(Ui.END_MESSAGE); - return false; - case Ui.HELP_COMMAND: - ui.printMessage(Ui.FLAGS); - break; - default: - try { - ArrayList availStudyAreas = studyAreaList.searchList(command); - printList(availStudyAreas, ui); - ui.printMessage(Ui.PROMPT_USER); - } catch (IllegalStudyAreaException e) { - ui.printMessage(e.getMessage()); - } - break; + case Ui.BYE_COMMAND: + ui.printMessage(Ui.END_MESSAGE); + return false; + case Ui.HELP_COMMAND: + ui.printMessage(Ui.FLAGS); + break; + default: + try { + ArrayList availStudyAreas = studyAreaList.searchList(command); + printList(availStudyAreas, ui); + ui.printMessage(Ui.PROMPT_USER); + } catch (IllegalStudyAreaException e) { + ui.printMessage(e.getMessage()); + } + break; } } return true; } - /** * Executes the StudyArea search feature. * @param ui This allows for StudyAreaCommand to interact with Users. diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java index 2e8bb85b5..2c875301d 100644 --- a/src/main/java/resourceloader/EventLoader.java +++ b/src/main/java/resourceloader/EventLoader.java @@ -89,6 +89,7 @@ private void createNewDataFile() { Files.createDirectories(fileDirectory); Files.createFile(Paths.get(filePath)); Files.createFile(Paths.get(Ui.FILE_PATH_STUDYAREAS)); + Files.createFile(Paths.get(Ui.FILE_PATH_DICTIONARY)); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index 8bdbe08a2..ad52b3f5b 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -1,5 +1,6 @@ package resourceloader; +import studyarea.Dictionary; import studyarea.IllegalStudyAreaException; import studyarea.StudyArea; import ui.Ui; @@ -23,13 +24,16 @@ public StudyAreaLoader(String url) throws IllegalStudyAreaException { } /** - * Loads url into file. + * Loads content from location.txt and dictionary.txt. */ - public void loadFile() throws IllegalStudyAreaException { + public void loadFile() throws IllegalStudyAreaException{ try { this.file = new File(this.url); - } catch (Exception e) { + Dictionary.loadDictionary(); + } catch (NullPointerException e) { throw new IllegalStudyAreaException(Ui.MISSING_STUDY_AREA_DATA); + } catch (FileNotFoundException e) { + throw new IllegalStudyAreaException(e.getMessage()); } } @@ -49,7 +53,8 @@ public ArrayList pushToDatabase() throws IllegalStudyAreaException, F String detailsOfLocation = input.nextLine(); String[] detailsBuffer = detailsOfLocation.split(DIVIDER); if (detailsBuffer.length != 6) { - throw new IllegalStudyAreaException(Ui.INCONSISTENT_DATA_STORAGE); + String name = detailsBuffer[0]; + throw new IllegalStudyAreaException(Ui.INCONSISTENT_DATA_STORAGE + "at " + name); } StudyArea studyArea = new StudyArea(detailsBuffer[0], detailsBuffer[1], detailsBuffer[2], Boolean.parseBoolean(detailsBuffer[3]), Boolean.parseBoolean(detailsBuffer[4]), diff --git a/src/main/java/studyarea/Dictionary.java b/src/main/java/studyarea/Dictionary.java index dccc7f14a..e2676e7df 100644 --- a/src/main/java/studyarea/Dictionary.java +++ b/src/main/java/studyarea/Dictionary.java @@ -1,59 +1,54 @@ package studyarea; -import java.util.ArrayList; -import java.util.Arrays; +import java.io.File; +import java.io.FileNotFoundException; import java.util.HashMap; - import java.util.Scanner; -public class SearchKeyDictionary { - - private static HashMap> dictionary = new HashMap<>(); - - public static void loadDictionary(){ - for(String temp : ENGINEERING){ - dictionary.put(temp, "engineering"); - } - for(String temp : ENGINEERING){ - dictionary.put(temp, "engineering"); +/** + * This class allows for User to loosely search certain names, address or faculties of StudyAreas. + */ +public class Dictionary { + + private static final String FILEPATH = "library\\dictionary.txt"; + private static final String DELIMITER = "~"; + private static HashMap dictionary = new HashMap<>(); + + /** + * This method loads the dictionary mapping from dictionary.text. + * @throws FileNotFoundException if the file cannot be found. + */ + + public static void loadDictionary() throws FileNotFoundException { + Scanner in = new Scanner(new File(FILEPATH)); + while(in.hasNextLine()){ + String userIn = in.nextLine(); + String[] buffer = userIn.split(DELIMITER); + int i = 0; + String out = null; + for(String value : buffer){ + if (i==0) { + out = value; + }else{ + dictionary.put(value, out); + } + i++; + } } + in.close(); } - public static void main(String[] args) { - Scanner in = new Scanner(System.in); - loadDictionary(); - System.out.println("Engine: 0, Utown: 1 , Computing: 2 "); - System.out.println("Search by faculty: "); - - while (true) { - String input = in.nextLine(); - if(input.equals("bye")){ - break; - } - int index = 0; - String searchedFac = null; - for (HashSet faculty : Dictionary) { - if (faculty.contains(input)) { - break; - } - index++; - } - switch (index) { - case 0: - searchedFac = "Engineering"; - break; - case 1: - searchedFac = "Utown"; - break; - case 2: - searchedFac = "Computing"; - break; - default: - searchedFac = "not found"; - break; - } - System.out.println("Faculty searched is: " + searchedFac); + /** + * This method finds a mapping from User input to a either StudyArea's name, address, or faculty. + * @param key this is the User input. + * @return either StudyArea's name, address, or faculty if mapping is found, else return null. + */ + public static String parseKey(String key){ //this method will be used within String.contains() method + String out = DELIMITER; // Since .contains() cannot have null as an argument, out is initialised + if(dictionary.containsKey(key)) { // with delimiter because mapped data does not contain delimiter. + out = dictionary.get(key); } + return out; } } diff --git a/src/main/java/studyarea/IllegalStudyAreaException.java b/src/main/java/studyarea/IllegalStudyAreaException.java index c86aceee5..4a6297618 100644 --- a/src/main/java/studyarea/IllegalStudyAreaException.java +++ b/src/main/java/studyarea/IllegalStudyAreaException.java @@ -9,6 +9,4 @@ public class IllegalStudyAreaException extends Exception { public IllegalStudyAreaException(String message) { super(message); } - - } \ No newline at end of file diff --git a/src/main/java/studyarea/StudyArea.java b/src/main/java/studyarea/StudyArea.java index d790c887d..b3f173188 100644 --- a/src/main/java/studyarea/StudyArea.java +++ b/src/main/java/studyarea/StudyArea.java @@ -98,8 +98,9 @@ public Integer getMaxPax() { * @return String value of all the attributes of the specific StudyArea. */ public String toString() { - String text = Ui.TAB + "Name: " + this.name + lineSeparator() + Ui.TAB - + "Address: " + this.address + lineSeparator() + Ui.TAB + String text = Ui.TAB + "Name: " + this.name + lineSeparator() + + Ui.formatMessage("Address: " + this.address, Ui.MAX_LINE_LENGTH) + + lineSeparator() + Ui.TAB + "Faculty: " + this.faculty + lineSeparator() + Ui.TAB + "Port: " + this.hasPort + lineSeparator() + Ui.TAB + "Indoor: " + this.isIndoor + lineSeparator() + Ui.TAB diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 99e258789..541d1abe9 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -24,13 +24,14 @@ public ArrayList getStudyAreaList() { return this.studyAreaList; } + /** * This method checks for duplicate flags. * @param flag this is the array of flags in the system. * @param index this is the index referring to the specific flag to check for duplicate. * @throws IllegalStudyAreaException if flag is not null, ie: if flag has already been mentioned. */ - public static void checkDuplicate(String[] flag, int index) throws IllegalStudyAreaException { + public void checkDuplicate(String[] flag, int index) throws IllegalStudyAreaException { if (flag[index] != null) { throw new IllegalStudyAreaException(Ui.DUPLICATE_FLAGS); } @@ -43,14 +44,14 @@ public static void checkDuplicate(String[] flag, int index) throws IllegalStudyA * @throws IllegalStudyAreaException if only flag is entered by user. */ - public static void checkOnlyFlag(String[] commands, int index) throws IllegalStudyAreaException { + public void checkOnlyFlag(String[] commands, int index) throws IllegalStudyAreaException { if (commands[index].length() == 1) { throw new IllegalStudyAreaException(Ui.ONLY_FLAG); } } /** - * This method assigns flags based on User input. + * This method validate flags based on User input. * * @param flags this is the array of flags. * @param commands this is the full command entered by Users. @@ -58,34 +59,34 @@ public static void checkOnlyFlag(String[] commands, int index) throws IllegalStu * @param isNotFlag this is the boolean value that checks if the command entered is a flag. * @throws IllegalStudyAreaException if user enters command wrongly. */ - public void checkFlag(String[] flags, String[] commands, int index, boolean isNotFlag) throws - IllegalStudyAreaException { + private void checkFlag(String[] flags, String[] commands, int index, boolean isNotFlag) throws + IllegalStudyAreaException { //isNotFlag is used to track previous instances of "-" - if (commands[index].equals(Ui.SIZE_FLAG)) { + if (commands[index].equals(Ui.SIZE_FLAG)) { // for instances of "-s", check if next string is integer or null. checkDuplicate(flags, 0); - try { + try { // try block is to test if command is integer int size = Integer.parseInt(commands[index + 1]); - } catch (NumberFormatException e) { + } catch (NumberFormatException e) { // catch if command is not integer then throw exception throw new IllegalStudyAreaException(Ui.NOT_INTEGER); - } catch (ArrayIndexOutOfBoundsException e) { + } catch (ArrayIndexOutOfBoundsException e) { // catch if no string exist after "-s" and throw exception throw new IllegalStudyAreaException(Ui.NO_SIZE_INDICATED); } - } else if (commands[index].contains(Ui.FLAG)) { - checkOnlyFlag(commands, index); - switch (commands[index].charAt(1)) { - case 'p': - checkDuplicate(flags, 2); - break; - case 'i': - case 'o': - checkDuplicate(flags, 3); - break; - default: - throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); + } else if (commands[index].contains(Ui.FLAG)) { // for instances "-" , + checkOnlyFlag(commands, index); // check if only "-" exist, if true, then throw exception + switch (commands[index].charAt(1)) { // if "-p", "-i" , "-o" then check if duplicate. Else, throw + case 'p': // exception for wrong usage of flag + checkDuplicate(flags, 2); + break; + case 'i': + case 'o': + checkDuplicate(flags, 3); + break; + default: + throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); } - } else { - if (!isNotFlag) { - throw new IllegalStudyAreaException(Ui.WRONG_FLAG_ARGUMENT_POSITION); + } else { // if no instances of "-" or "-s" + if (!isNotFlag) { // and if there exist previous instances of "-" (i.e: -p EA) + throw new IllegalStudyAreaException(Ui.WRONG_FLAG_ARGUMENT_POSITION); // throw exception } } } @@ -101,7 +102,7 @@ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException String[] flags = new String[5]; StringBuilder name = new StringBuilder(); - boolean isNotFlag = true; + boolean isNotFlag = true; // to keep track of instance "-" is input. for (int i = 0; i < commands.length; i++) { if (commands[i].equals(Ui.SIZE_FLAG)) { isNotFlag = false; // update isNotFlag as false because command is a flag @@ -113,27 +114,25 @@ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException isNotFlag = false; checkFlag(flags, commands, i,false); switch (commands[i].charAt(1)) { - case 'p': - flags[2] = Ui.PORTS_FLAG; - break; - case 'i': - flags[3] = Ui.INDOOR_FLAG; - break; - case 'o': - flags[3] = Ui.OUTDOOR_FLAG; - break; - default: - throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); + case 'p': + flags[2] = Ui.PORTS_FLAG; + break; + case 'i': + flags[3] = Ui.INDOOR_FLAG; + break; + case 'o': + flags[3] = Ui.OUTDOOR_FLAG; + break; + default: + throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); } - } else { - if (isNotFlag) { - checkFlag(flags, commands, i, true); - name.append(commands[i]).append(Ui.SPACE); - flags[4] = name.toString().trim(); + } else { // if no previous instances of "-" + if (isNotFlag) { // and if input is not a flag + name.append(commands[i]).append(Ui.SPACE); // concatenate subsequent input that pass the control + flags[4] = name.toString().trim(); // flag } else { - checkFlag(flags, commands, i, false); - } - + checkFlag(flags, commands, i, false); // if has previous instances of "-" and input is not + } // flag, pass false to throw exception. } } return flags; @@ -142,17 +141,20 @@ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException /** * Checks if search key is found in Study Area's Name and Faculty attributes. * @param name This is the Study Area's Name Attribute. + * @param address This is the Study Area's Address Attribute. * @param faculty This is the Study Area's Faculty Attribute. * @param key This is the search key entered by User. * @return True if can be found in either case. False if not found in both cases. */ - public static boolean containsKey(String name, String faculty, String key) { - if (name.toLowerCase().contains(key.toLowerCase())) { //toLowerCase() so casing does not affect matching. + public static boolean containsKey(String name, String address ,String faculty, String key) { + if (name.contains(key) || name.contains(Dictionary.parseKey(key))) { + return true; + } + if (address.contains(key) || address.contains(Dictionary.parseKey(key))) { return true; } - return faculty.toLowerCase().contains(key.toLowerCase()); // if first check is false, return true depends on - // second check. + return faculty.contains((key)) || faculty.contains(Dictionary.parseKey(key)); } /** @@ -162,9 +164,7 @@ public static boolean containsKey(String name, String faculty, String key) { * @return ArrayList of StudyAreas * @throws IllegalStudyAreaException if User enters invalid commands. */ - public ArrayList searchList(String userIn) throws IllegalStudyAreaException { - try { String[] temp = userIn.split(Ui.MULTIPLE_WHITE_SPACES); String[] flags = getFlagsInfo(temp); ArrayList availStudyAreas = new ArrayList<>(); @@ -173,22 +173,25 @@ public ArrayList searchList(String userIn) throws IllegalStudyAreaExc for (String flag : flags) { if (flag != null && isAvail) { switch (flag) { - case Ui.PORTS_FLAG: - isAvail = studyArea.hasPort(); - break; - case Ui.INDOOR_FLAG: - isAvail = studyArea.isIndoor(); - break; - case Ui.OUTDOOR_FLAG: - isAvail = !studyArea.isIndoor(); - break; - case Ui.SIZE_FLAG: - isAvail = Integer.toString(studyArea.getMaxPax()).equals(flags[1]); - flags[1] = null; //so as to skip iteration on flags[1]. - break; - default: - isAvail = containsKey(studyArea.getName(), studyArea.getFaculty(), flags[4]); - break; + case Ui.PORTS_FLAG: + isAvail = studyArea.hasPort(); + break; + case Ui.INDOOR_FLAG: + isAvail = studyArea.isIndoor(); + break; + case Ui.OUTDOOR_FLAG: + isAvail = !studyArea.isIndoor(); + break; + case Ui.SIZE_FLAG: // allows user to find by capacity <= MaxPax + isAvail = studyArea.getMaxPax()>=Integer.parseInt(flags[1]); + flags[1] = null; //so as to skip iteration on flags[1]. + break; + default: + isAvail = containsKey(studyArea.getName().toLowerCase(),// toLowerCase() so casing does + studyArea.getAddress().toLowerCase(), // not affect matching + studyArea.getFaculty().toLowerCase(), + flags[4].toLowerCase()); + break; } } } @@ -197,8 +200,5 @@ public ArrayList searchList(String userIn) throws IllegalStudyAreaExc } } return availStudyAreas; - } catch (Exception e) { - throw new IllegalStudyAreaException(e.getMessage()); - } } } \ No newline at end of file diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 2f381049e..d36ef34a5 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -19,12 +19,13 @@ public class Ui { public static final String FILE_PATH_EVENTS = "library" + File.separator + "eventList.txt"; public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; + public static final String FILE_PATH_DICTIONARY = "library" + File.separator + "dictionary.txt"; public static final String MISSING_STUDY_AREA_DATA = "locations.txt is missing"; public static final String BYE_COMMAND = "bye"; public static final String BYE_MESSAGE = "Bye!!!!!!"; public static final String LINE = "_______________________________________________________________________________" + "_____"; - public static final int MAX_LINE_LENGTH = 55; + public static final int MAX_LINE_LENGTH = 58; public static final String FLAG = "-"; public static final String MULTIPLE_WHITE_SPACES = "\\s+"; public static final String DUPLICATE_FLAGS = "Duplicate flags entered!"; diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT deleted file mode 100644 index 0a7d67f55..000000000 --- a/text-ui-test/ACTUAL.TXT +++ /dev/null @@ -1,47 +0,0 @@ -Hello from -_______/\\\\\_____________________________________________________/\\\\\_____/\\\____________________________________________/\\\____________ -______/\\\///\\\__________________________________________________\/\\\\\\___\/\\\__________________________________________/\\\\\\\_________ -_____/\\\/__\///\\\____________________/\\\\\\\\___________________\/\\\/\\\__\/\\\___/\\\__________________________________/\\\\\\\\\_______ -_____/\\\______\//\\\___/\\/\\\\\\\____/\\\////\\\___/\\\\\\\\\_____\/\\\//\\\_\/\\\__\///_______/\\\\\\\\______/\\\\\\\\___\//\\\\\\\_______ -_____\/\\\_______\/\\\__\/\\\/////\\\__\//\\\\\\\\\__\////////\\\____\/\\\\//\\\\/\\\___/\\\____/\\\//////_____/\\\/////\\\___\//\\\\\_______ -______\//\\\______/\\\___\/\\\___\///____\///////\\\____/\\\\\\\\\\___\/\\\_\//\\\/\\\__\/\\\___/\\\___________/\\\\\\\\\\\_____\//\\\_______ -________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\//\\\\\\__\/\\\__\//\\\_________\//\\///////_______\///_______ -____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ -______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ -What is your name? -____________________________________________________________________________________ -____________________________________________________________________________________ - Hello James Gosling! - Welcome to OrgaNice! To start, enter "event" to start - your event list! If you are in the mood to mug and you - want to start your study area list, enter "study" !If - you want to exit, enter "bye" ! -____________________________________________________________________________________ -____________________________________________________________________________________ - Goodbye! Hope to see you again! - `````````````````````````````````````````````````````````` - ````````````````````````````````:v(v'````````````````````` - ```````````````````````````,)4|ex` `L}```````````````````` - `````````````````````````!s"'h `M: ^z_;)T``````````````` - `````````````````````````Z u|}Z: "}`````````````` - ``````````````````````:=?) 'B?L'``````````` - `````````````````````'Z ;Yp"``````````` - `````````````````````.e ?_``````````` - ```````````````````'QDGH .5```````````` - ````````````````````I#g' '_` ||```````````` - ```````````:mX_``````YhL` `'q!` ? h```````````` - ```````````'Qbs)|L=_V" 'Y} ^'q@&b=c=_` ,Z```````````` - ````````````q> 'T, ,o" ;"@c. .sVx~````````````` - ````````````c! "bh` `,p z:`````````````` - `````````````q. ngDQmh8s X'`````````````` - ``````````````LY" :n}>``b; _V``````````````` - ````````````````q?, ?; "V```````````````` - ``````````````KvR ' )x_````````````````` - ``````````````zjL GLY"``````````````````` - ```````````````M .I)`````````````````````` - ```````````````Lz `D:`````````````````````` - ``````````````vu` (I)_;"". P.````````````````````` - ``````````````p :X.':^,"=n "q`````````````````````` - `````````````)0X?^:)I````````m' :j`````````````````````` - `````````````.IGD8k'`````````<&G55M``````````````````````` - `````````````````````````````````````````````````````````` From cab3c2f9aa5f63c828b04ff025d33ebd5b3fcfb6 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sat, 14 Mar 2020 12:19:47 +0800 Subject: [PATCH 086/435] Edit Javadoc Comments --- src/main/java/command/StudyAreaCommand.java | 31 ++--- src/main/java/event/EventList.java | 1 - .../java/resourceloader/StudyAreaLoader.java | 3 +- src/main/java/studyarea/Dictionary.java | 12 +- src/main/java/studyarea/StudyAreaList.java | 117 +++++++++--------- 5 files changed, 85 insertions(+), 79 deletions(-) diff --git a/src/main/java/command/StudyAreaCommand.java b/src/main/java/command/StudyAreaCommand.java index ad35eb78a..5ae92d245 100644 --- a/src/main/java/command/StudyAreaCommand.java +++ b/src/main/java/command/StudyAreaCommand.java @@ -48,25 +48,26 @@ public static boolean filterCommand(String command, StudyAreaList studyAreaList, throw new IllegalStudyAreaException(Ui.EMPTY_LOCATION); } else { switch (command) { - case Ui.BYE_COMMAND: - ui.printMessage(Ui.END_MESSAGE); - return false; - case Ui.HELP_COMMAND: - ui.printMessage(Ui.FLAGS); - break; - default: - try { - ArrayList availStudyAreas = studyAreaList.searchList(command); - printList(availStudyAreas, ui); - ui.printMessage(Ui.PROMPT_USER); - } catch (IllegalStudyAreaException e) { - ui.printMessage(e.getMessage()); - } - break; + case Ui.BYE_COMMAND: + ui.printMessage(Ui.END_MESSAGE); + return false; + case Ui.HELP_COMMAND: + ui.printMessage(Ui.FLAGS); + break; + default: + try { + ArrayList availStudyAreas = studyAreaList.searchList(command); + printList(availStudyAreas, ui); + ui.printMessage(Ui.PROMPT_USER); + } catch (IllegalStudyAreaException e) { + ui.printMessage(e.getMessage()); + } + break; } } return true; } + /** * Executes the StudyArea search feature. * @param ui This allows for StudyAreaCommand to interact with Users. diff --git a/src/main/java/event/EventList.java b/src/main/java/event/EventList.java index f566ec8b4..7b454a182 100644 --- a/src/main/java/event/EventList.java +++ b/src/main/java/event/EventList.java @@ -75,7 +75,6 @@ public void listEvents(Ui ui) { * * @param ui This allows Event List class to interact with User. * @param index The index (1-based) of the event to be deleted. - * @throws Exception If the index specified is invalid. */ public void deleteEvent(int index, Ui ui) { ui.printLine(); diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index ad52b3f5b..9340581b1 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -25,8 +25,9 @@ public StudyAreaLoader(String url) throws IllegalStudyAreaException { /** * Loads content from location.txt and dictionary.txt. + * @throws IllegalStudyAreaException if file is not found. */ - public void loadFile() throws IllegalStudyAreaException{ + public void loadFile() throws IllegalStudyAreaException { try { this.file = new File(this.url); Dictionary.loadDictionary(); diff --git a/src/main/java/studyarea/Dictionary.java b/src/main/java/studyarea/Dictionary.java index e2676e7df..2b7fffd6d 100644 --- a/src/main/java/studyarea/Dictionary.java +++ b/src/main/java/studyarea/Dictionary.java @@ -21,15 +21,15 @@ public class Dictionary { public static void loadDictionary() throws FileNotFoundException { Scanner in = new Scanner(new File(FILEPATH)); - while(in.hasNextLine()){ + while (in.hasNextLine()) { String userIn = in.nextLine(); String[] buffer = userIn.split(DELIMITER); int i = 0; String out = null; - for(String value : buffer){ - if (i==0) { + for (String value : buffer) { + if (i == 0) { out = value; - }else{ + } else { dictionary.put(value, out); } i++; @@ -44,9 +44,9 @@ public static void loadDictionary() throws FileNotFoundException { * @return either StudyArea's name, address, or faculty if mapping is found, else return null. */ - public static String parseKey(String key){ //this method will be used within String.contains() method + public static String parseKey(String key) { //this method will be used within String.contains() method String out = DELIMITER; // Since .contains() cannot have null as an argument, out is initialised - if(dictionary.containsKey(key)) { // with delimiter because mapped data does not contain delimiter. + if (dictionary.containsKey(key)) { // with delimiter because mapped data does not contain delimiter. out = dictionary.get(key); } return out; diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 541d1abe9..4259462a3 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -31,7 +31,7 @@ public ArrayList getStudyAreaList() { * @param index this is the index referring to the specific flag to check for duplicate. * @throws IllegalStudyAreaException if flag is not null, ie: if flag has already been mentioned. */ - public void checkDuplicate(String[] flag, int index) throws IllegalStudyAreaException { + public static void checkDuplicate(String[] flag, int index) throws IllegalStudyAreaException { if (flag[index] != null) { throw new IllegalStudyAreaException(Ui.DUPLICATE_FLAGS); } @@ -44,7 +44,7 @@ public void checkDuplicate(String[] flag, int index) throws IllegalStudyAreaExce * @throws IllegalStudyAreaException if only flag is entered by user. */ - public void checkOnlyFlag(String[] commands, int index) throws IllegalStudyAreaException { + public static void checkOnlyFlag(String[] commands, int index) throws IllegalStudyAreaException { if (commands[index].length() == 1) { throw new IllegalStudyAreaException(Ui.ONLY_FLAG); } @@ -74,15 +74,15 @@ private void checkFlag(String[] flags, String[] commands, int index, boolean isN } else if (commands[index].contains(Ui.FLAG)) { // for instances "-" , checkOnlyFlag(commands, index); // check if only "-" exist, if true, then throw exception switch (commands[index].charAt(1)) { // if "-p", "-i" , "-o" then check if duplicate. Else, throw - case 'p': // exception for wrong usage of flag - checkDuplicate(flags, 2); - break; - case 'i': - case 'o': - checkDuplicate(flags, 3); - break; - default: - throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); + case 'p': // exception for wrong usage of flag + checkDuplicate(flags, 2); + break; + case 'i': + case 'o': + checkDuplicate(flags, 3); + break; + default: + throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); } } else { // if no instances of "-" or "-s" if (!isNotFlag) { // and if there exist previous instances of "-" (i.e: -p EA) @@ -95,7 +95,12 @@ private void checkFlag(String[] flags, String[] commands, int index, boolean isN * Obtains all the supported flags in this organiser app. * * @param commands This is the User commands that has been split by spaces. - * @return String Array of a fixed size of 5 + * @return special purpose String Array of a fixed size of 5 and fixed values where :
+ * index 0 : "-s"
+ * index 1 : Integer value of the size indicated.
+ * index 2 : "-p"
+ * index 3 : "-i" or "-o" , depends on user input
+ * index 4: search key entered by User
* @throws IllegalStudyAreaException when arguments for flags are invalid. */ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException { @@ -114,17 +119,17 @@ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException isNotFlag = false; checkFlag(flags, commands, i,false); switch (commands[i].charAt(1)) { - case 'p': - flags[2] = Ui.PORTS_FLAG; - break; - case 'i': - flags[3] = Ui.INDOOR_FLAG; - break; - case 'o': - flags[3] = Ui.OUTDOOR_FLAG; - break; - default: - throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); + case 'p': + flags[2] = Ui.PORTS_FLAG; + break; + case 'i': + flags[3] = Ui.INDOOR_FLAG; + break; + case 'o': + flags[3] = Ui.OUTDOOR_FLAG; + break; + default: + throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); } } else { // if no previous instances of "-" if (isNotFlag) { // and if input is not a flag @@ -147,9 +152,9 @@ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException * @return True if can be found in either case. False if not found in both cases. */ - public static boolean containsKey(String name, String address ,String faculty, String key) { + public static boolean containsKey(String name, String address, String faculty, String key) { if (name.contains(key) || name.contains(Dictionary.parseKey(key))) { - return true; + return true; } if (address.contains(key) || address.contains(Dictionary.parseKey(key))) { return true; @@ -165,40 +170,40 @@ public static boolean containsKey(String name, String address ,String faculty, S * @throws IllegalStudyAreaException if User enters invalid commands. */ public ArrayList searchList(String userIn) throws IllegalStudyAreaException { - String[] temp = userIn.split(Ui.MULTIPLE_WHITE_SPACES); - String[] flags = getFlagsInfo(temp); - ArrayList availStudyAreas = new ArrayList<>(); - for (StudyArea studyArea : this.studyAreaList) { - boolean isAvail = true; - for (String flag : flags) { - if (flag != null && isAvail) { - switch (flag) { - case Ui.PORTS_FLAG: - isAvail = studyArea.hasPort(); - break; - case Ui.INDOOR_FLAG: - isAvail = studyArea.isIndoor(); - break; - case Ui.OUTDOOR_FLAG: - isAvail = !studyArea.isIndoor(); - break; - case Ui.SIZE_FLAG: // allows user to find by capacity <= MaxPax - isAvail = studyArea.getMaxPax()>=Integer.parseInt(flags[1]); - flags[1] = null; //so as to skip iteration on flags[1]. - break; - default: - isAvail = containsKey(studyArea.getName().toLowerCase(),// toLowerCase() so casing does - studyArea.getAddress().toLowerCase(), // not affect matching - studyArea.getFaculty().toLowerCase(), - flags[4].toLowerCase()); - break; + String[] temp = userIn.split(Ui.MULTIPLE_WHITE_SPACES); + String[] flags = getFlagsInfo(temp); + ArrayList availStudyAreas = new ArrayList<>(); + for (StudyArea studyArea : this.studyAreaList) { + boolean isAvail = true; + for (String flag : flags) { + if (flag != null && isAvail) { + switch (flag) { + case Ui.PORTS_FLAG: + isAvail = studyArea.hasPort(); + break; + case Ui.INDOOR_FLAG: + isAvail = studyArea.isIndoor(); + break; + case Ui.OUTDOOR_FLAG: + isAvail = !studyArea.isIndoor(); + break; + case Ui.SIZE_FLAG: // allows user to find by capacity <= MaxPax + if (flags[1] != null) { + isAvail = Integer.parseInt(flags[1]) >= studyArea.getMaxPax(); } + flags[1] = null; //so as to skip iteration on flags[1]. + break; + default: // toLowerCase() so casing does not affect matching + isAvail = containsKey(studyArea.getName().toLowerCase(), studyArea.getAddress().toLowerCase(), + studyArea.getFaculty().toLowerCase(), flags[4].toLowerCase()); + break; } } - if (isAvail) { - availStudyAreas.add(studyArea); - } } - return availStudyAreas; + if (isAvail) { + availStudyAreas.add(studyArea); + } + } + return availStudyAreas; } } \ No newline at end of file From 9721afe96e2dfb2d46ef0158ea2f57a88fc5e038 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sat, 14 Mar 2020 12:52:54 +0800 Subject: [PATCH 087/435] refactor expected.txt --- text-ui-test/{EXPECTED.TXT => EXPECTED2.TXT} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename text-ui-test/{EXPECTED.TXT => EXPECTED2.TXT} (100%) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED2.TXT similarity index 100% rename from text-ui-test/EXPECTED.TXT rename to text-ui-test/EXPECTED2.TXT From 2d773706353b7d34b0c4fcb263b0bd1f19b69a44 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sat, 14 Mar 2020 12:53:56 +0800 Subject: [PATCH 088/435] refactor again --- text-ui-test/{EXPECTED2.TXT => EXPECTED.TXT} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename text-ui-test/{EXPECTED2.TXT => EXPECTED.TXT} (100%) diff --git a/text-ui-test/EXPECTED2.TXT b/text-ui-test/EXPECTED.TXT similarity index 100% rename from text-ui-test/EXPECTED2.TXT rename to text-ui-test/EXPECTED.TXT From ca2967b2ea39eb6b0943cd971959afcb72ca7b33 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sat, 14 Mar 2020 13:05:54 +0800 Subject: [PATCH 089/435] Recitfy runtest check --- text-ui-test/library/dictionary.txt | 0 text-ui-test/library/eventList.txt | 0 text-ui-test/library/locations.txt | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 text-ui-test/library/dictionary.txt create mode 100644 text-ui-test/library/eventList.txt create mode 100644 text-ui-test/library/locations.txt diff --git a/text-ui-test/library/dictionary.txt b/text-ui-test/library/dictionary.txt new file mode 100644 index 000000000..e69de29bb diff --git a/text-ui-test/library/eventList.txt b/text-ui-test/library/eventList.txt new file mode 100644 index 000000000..e69de29bb diff --git a/text-ui-test/library/locations.txt b/text-ui-test/library/locations.txt new file mode 100644 index 000000000..e69de29bb From d5926c911bd34edcdb40dd78c3977c693b21739f Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sat, 14 Mar 2020 13:21:56 +0800 Subject: [PATCH 090/435] edit file path --- src/main/java/studyarea/Dictionary.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/studyarea/Dictionary.java b/src/main/java/studyarea/Dictionary.java index 2b7fffd6d..bb491a588 100644 --- a/src/main/java/studyarea/Dictionary.java +++ b/src/main/java/studyarea/Dictionary.java @@ -10,7 +10,7 @@ */ public class Dictionary { - private static final String FILEPATH = "library\\dictionary.txt"; + private static final String FILEPATH = "library" + File.separator + "dictionary.txt"; private static final String DELIMITER = "~"; private static HashMap dictionary = new HashMap<>(); From 135181ceb8d0d64c18a78501a8099485981fc9ac Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sat, 14 Mar 2020 18:09:25 +0800 Subject: [PATCH 091/435] Update text ui, remove EventLoader --- src/main/java/resourceloader/EventLoader.java | 115 --- text-ui-test/EXPECTED.TXT | 764 +++++++++++++++--- text-ui-test/library/dictionary.txt | 0 text-ui-test/library/locations.txt | 0 text-ui-test/library/taskList.txt | 2 - 5 files changed, 658 insertions(+), 223 deletions(-) delete mode 100644 src/main/java/resourceloader/EventLoader.java delete mode 100644 text-ui-test/library/dictionary.txt delete mode 100644 text-ui-test/library/locations.txt delete mode 100644 text-ui-test/library/taskList.txt diff --git a/src/main/java/resourceloader/EventLoader.java b/src/main/java/resourceloader/EventLoader.java deleted file mode 100644 index 2c875301d..000000000 --- a/src/main/java/resourceloader/EventLoader.java +++ /dev/null @@ -1,115 +0,0 @@ -package resourceloader; - -import event.Event; -import ui.Ui; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Scanner; - - -/** - * Handles the task of loading and storing events. - */ -public class EventLoader { - - /** Location of data file. */ - private String filePath; - /** Directory of data file. */ - private Path fileDirectory; - - /** - * Constructor for EventLoader object. - * Initialises the object with the file path provided. - * - * @param filePath The location of the data file. - */ - public EventLoader(String filePath) { - this.filePath = filePath; - this.fileDirectory = Paths.get(filePath).getParent(); - } - - - /** - * Reads the list of events stored previously and returns it as an ArrayList of Events. - * - * @return events The list of events stored previously. - */ - public ArrayList loadFile() { - ArrayList events = new ArrayList<>();; - File dataFile; - Scanner s; - Ui ui = new Ui(); - try { - dataFile = new File(filePath); - s = new Scanner(dataFile); - while (s.hasNext()) { - String eventDescription = s.nextLine(); - Event newEvent = parseEventDetails(eventDescription); - events.add(newEvent); - } - } catch (FileNotFoundException e) { - createNewDataFile(); - } catch (Exception e) { - ui.printLine(); - ui.printMessage(e.getMessage()); - ui.printLine(); - } - return events; - } - - /** - * Parses the Event details from the given string and returns a new event object with the specified details. - * - * @param taskDescription Contains all the details with regards to the Event. - * @return newEvent The new event created with the details provided. - */ - private Event parseEventDetails(String taskDescription) throws Exception { - String[] splitDescription = taskDescription.split("#", 5); - String description = splitDescription[0]; - String date = splitDescription[1]; - String startTime = splitDescription[2]; - String endTime = splitDescription[3]; - String priority = splitDescription[4]; - Event newEvent = new Event(description, date, startTime, endTime, priority); - return newEvent; - } - - - /** - * Creates a new data file when the application is run for the first time. - */ - private void createNewDataFile() { - try { - Files.createDirectories(fileDirectory); - Files.createFile(Paths.get(filePath)); - Files.createFile(Paths.get(Ui.FILE_PATH_STUDYAREAS)); - Files.createFile(Paths.get(Ui.FILE_PATH_DICTIONARY)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Saves the list of current tasks to the data file. - * - * @param events Represents the current list of events. - */ - public void saveEvents(ArrayList events) { - try { - FileWriter fw = new FileWriter(filePath); - for (Event event: events) { - fw.write(event.getFormattedDetails()); - } - fw.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 7147ee072..f2b325705 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -9,15 +9,15 @@ ________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\/ ____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ ______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ What is your name? -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Hello James Gosling! - Welcome to OrgaNice! To start, enter "task" to start - your task list! If you are in the mood to mug and you - want to start your study area list, enter "study" !If - you want to exit, enter "bye" ! -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ + Welcome to OrgaNice! To start, enter "task" to start your + event list! If you are in the mood to mug and you want to + start your study area list, enter "study" !If you want to + exit, enter "bye" ! +________________________________________________________________________________________________ +________________________________________________________________________________________________ OrgaNice! Supports the following commands Please enter the keywords followed by the information shown in the brackets event /d /s /e /p @@ -37,72 +37,67 @@ ________________________________________________________________________________ *All dates should follow YYYY-MM-DD format *All timing should follow 24 hour clock *There are 4 levels of priority, with 1 being the most urgent, and 4 being the least urgent -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The list of tasks is cleared. -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - A new event with the following information has been - added. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + A new event with the following information has been added. [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Here is the list of events added so far: 1) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - A new event with the following information has been - added. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + A new event with the following information has been added. [D] assignment on May 2 2020 at 14:00 with priority 2 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Here is the list of tasks added so far displayed in decreasing order of priority: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 + 1) [D] assignment on May 2 2020 at 14:00 with priority 2 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Here is the list of events added so far: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 + 1) [D] assignment on May 2 2020 at 14:00 with priority 2 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The search string entered is empty. -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Empty Line entered, Please enter a valid line -________________________________________________________________________________________________________ +________________________________________________________________________________________________ 1) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ +________________________________________________________________________________________________ The list is empty. -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Invalid index entered. Please enter a valid index to be deleted -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Index 1 out of bounds for length 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Enter a valid integer index (1-based) to delete/edit - the corresponding event (format: delete/edit index) -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Enter a valid integer index (1-based) to delete/edit the + corresponding event (format: delete/edit index) +________________________________________________________________________________________________ +________________________________________________________________________________________________ Here is the list of events added so far: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 + 1) [D] assignment on May 2 2020 at 14:00 with priority 2 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The event details are as follows: [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 @@ -120,20 +115,19 @@ ________________________________________________________________________________ Updated Details: [E] team meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The task at the mentioned index has been edited successfully -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Here is the list of events added so far: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 - 2) [E] team meeting at May 5 2020 from 12:00 to 13:00 - with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ + 1) [D] assignment on May 2 2020 at 14:00 with priority 2 + 2) [E] team meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 +________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The event details are as follows: [E] team meeting at May 5 2020 from 12:00 to 13:00 with priority 1 @@ -151,36 +145,36 @@ ________________________________________________________________________________ Updated Details: [E] team meeting at Jun 6 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The task at the mentioned index has been edited successfully -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Event details are not provided -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Wrong command used to view events (Should be :view ) -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Invalid command entered, Please enter a valid command -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Here is the list of tasks with sorted based on the - number of days left: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 ---> 49 day(s) left - 2) [E] team meeting at Jun 6 2020 from 12:00 to 13:00 - with priority 1 ---> 84 day(s) left -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Exiting task interface -________________________________________________________________________________________________________ - Please enter "event" to continue with your event list - or "study" to continue with your study area list. To - leave, enter "bye". -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here is the list of tasks with sorted based on the number + of days left: + 1) [D] assignment on May 2 2020 at 14:00 with priority 2 + ---> 49 day(s) left + 2) [E] team meeting at Jun 6 2020 from 12:00 to 13:00 with + priority 1 ---> 84 day(s) left +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Bye!!!!!! +________________________________________________________________________________________________ + Please enter "task" to continue with your event list or + "study" to continue with your study area list. To leave, + enter "bye". +________________________________________________________________________________________________ +________________________________________________________________________________________________ OrgaNice! Supports the following commands Please enter the keywords followed by the information shown in the brackets event /d /s /e /p @@ -200,27 +194,585 @@ ________________________________________________________________________________ *All dates should follow YYYY-MM-DD format *All timing should follow 24 hour clock *There are 4 levels of priority, with 1 being the most urgent, and 4 being the least urgent -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Wrong command used to view countdown of events (Should - be :countdown ) -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Here is the list of tasks with sorted based on the - number of days left: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 ---> 49 day(s) left - 2) [E] team meeting at Jun 6 2020 from 12:00 to 13:00 - with priority 1 ---> 84 day(s) left -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Exiting task interface -________________________________________________________________________________________________________ - Please enter "event" to continue with your event list - or "study" to continue with your study area list. To - leave, enter "bye". -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Wrong command used to view countdown of events (Should be + :countdown ) +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here is the list of tasks with sorted based on the number + of days left: + 1) [D] assignment on May 2 2020 at 14:00 with priority 2 + ---> 49 day(s) left + 2) [E] team meeting at Jun 6 2020 from 12:00 to 13:00 with + priority 1 ---> 84 day(s) left +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Bye!!!!!! +________________________________________________________________________________________________ + Please enter "task" to continue with your event list or + "study" to continue with your study area list. To leave, + enter "bye". +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Please enter the location for your desired study area. + Enter "help" for a list of supported flags. Flags should + only come after location, if a criteria for location is + entered. When you are done with the search, enter "bye". +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Location entered is empty! Please type a location to + search for StudyAreas! +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here is a list of supported flags! + -p for study areas + with ports + -i for study areas that are indoors + -i for + study areas that are outdoors + -s {size} for maximum + number of pax +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: Opposite Town Green (Outside Starbucks) + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Starbucks + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: MacCommons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: PC Commons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Ian and Peony Ferguson Study + Address: 2 College Ave West Education Resource Centre, + Level 3 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: The Study + Address: 2 College Ave West Education Resource Centre, + Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: OCBC + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 2 + __________________________________________________________ + __________________________________________________________ + Name: SuperSnacks + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: Opposite Town Green (Outside Starbucks) + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Starbucks + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 5 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Duplicate flags entered! +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Duplicate flags entered! +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: MacCommons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: PC Commons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Ian and Peony Ferguson Study + Address: 2 College Ave West Education Resource Centre, + Level 3 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: The Study + Address: 2 College Ave West Education Resource Centre, + Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Town Plaza Seminar Rooms Waiting Area + Address: 2 College Ave West, Town Plaza, Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: SuperSnacks + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 1 + Address: 9 Engineering Drive 1,EA, Level 1 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 2 + Address: 9 Engineering Drive 1,EA, Level 2 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 3 + Address: 9 Engineering Drive 1,EA, Level 3 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 6 + Address: 9 Engineering Drive 1,EA, Level 6, EA06-23 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Central Library + Address: Central Library 12 Kent Ridge Crescent + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: YIH Study Room + Address: Yusof Ishak House, Level 2 + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: Opposite Town Green (Outside Starbucks) + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Starbucks + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: MacCommons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: PC Commons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Ian and Peony Ferguson Study + Address: 2 College Ave West Education Resource Centre, + Level 3 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: The Study + Address: 2 College Ave West Education Resource Centre, + Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Town Plaza Seminar Rooms Waiting Area + Address: 2 College Ave West, Town Plaza, Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: OCBC + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 2 + __________________________________________________________ + __________________________________________________________ + Name: SuperSnacks + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 1 + Address: 9 Engineering Drive 1,EA, Level 1 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 2 + Address: 9 Engineering Drive 1,EA, Level 2 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 3 + Address: 9 Engineering Drive 1,EA, Level 3 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 4 + Address: 9 Engineering Drive 1,EA, Level 4, Outside Staff + Offices + Faculty: Engineering + Port: true + Indoor: false + Maximum number of Pax: 6 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 5 + Address: 9 Engineering Drive 1,EA, Level 5, Outside of the + door beside EA05 + Faculty: Engineering + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 6 + Address: 9 Engineering Drive 1,EA, Level 6, EA06-23 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Central Library + Address: Central Library 12 Kent Ridge Crescent + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: YIH Study Room + Address: Yusof Ishak House, Level 2 + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Max Size is not indicated. Please indicate accordingly! +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Argument used after size flag "-s" is not an integer +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Oops! Based on your criteria we were not able to find a + compatible study area! + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: Opposite Town Green (Outside Starbucks) + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Starbucks + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: MacCommons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: PC Commons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Ian and Peony Ferguson Study + Address: 2 College Ave West Education Resource Centre, + Level 3 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: The Study + Address: 2 College Ave West Education Resource Centre, + Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Town Plaza Seminar Rooms Waiting Area + Address: 2 College Ave West, Town Plaza, Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: OCBC + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 2 + __________________________________________________________ + __________________________________________________________ + Name: SuperSnacks + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 1 + Address: 9 Engineering Drive 1,EA, Level 1 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 2 + Address: 9 Engineering Drive 1,EA, Level 2 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 3 + Address: 9 Engineering Drive 1,EA, Level 3 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 4 + Address: 9 Engineering Drive 1,EA, Level 4, Outside Staff + Offices + Faculty: Engineering + Port: true + Indoor: false + Maximum number of Pax: 6 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 5 + Address: 9 Engineering Drive 1,EA, Level 5, Outside of the + door beside EA05 + Faculty: Engineering + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 6 + Address: 9 Engineering Drive 1,EA, Level 6, EA06-23 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Central Library + Address: Central Library 12 Kent Ridge Crescent + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: YIH Study Room + Address: Yusof Ishak House, Level 2 + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Please enter the flag along with "-" +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Flags indicated are wrongly used. Please enter "help" for + the supported flags! +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Thank you for using our study area search service! +________________________________________________________________________________________________ + Please enter "task" to continue with your event list or + "study" to continue with your study area list. To leave, + enter "bye". +________________________________________________________________________________________________ +________________________________________________________________________________________________ Goodbye! Hope to see you again! `````````````````````````````````````````````````````````` ````````````````````````````````:v(v'````````````````````` diff --git a/text-ui-test/library/dictionary.txt b/text-ui-test/library/dictionary.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/text-ui-test/library/locations.txt b/text-ui-test/library/locations.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/text-ui-test/library/taskList.txt b/text-ui-test/library/taskList.txt deleted file mode 100644 index fa0db46bf..000000000 --- a/text-ui-test/library/taskList.txt +++ /dev/null @@ -1,2 +0,0 @@ -D#assignment #2020-05-02#14:00#2 -E#team meeting#2020-06-06#12:00#13:00#1 From f4592415e05fa0252a2e7d708745369f8e40867b Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sat, 14 Mar 2020 18:11:32 +0800 Subject: [PATCH 092/435] Add Back Up Data, refactor changes and add exceptions --- src/main/java/command/StudyAreaCommand.java | 28 ++-- src/main/java/command/TaskCommand.java | 5 +- src/main/java/resourceloader/BackUpData.java | 40 +++++ .../java/resourceloader/StudyAreaLoader.java | 28 +++- src/main/java/resourceloader/TaskLoader.java | 5 +- src/main/java/seedu/duke/Duke.java | 13 +- src/main/java/studyarea/StudyArea.java | 18 +- src/main/java/studyarea/StudyAreaList.java | 93 +++++++---- src/main/java/task/TaskList.java | 1 - src/main/java/ui/Constants.java | 121 ++++++++++++++ src/main/java/ui/Ui.java | 156 ++++++------------ text-ui-test/input.txt | 17 ++ 12 files changed, 355 insertions(+), 170 deletions(-) create mode 100644 src/main/java/resourceloader/BackUpData.java create mode 100644 src/main/java/ui/Constants.java diff --git a/src/main/java/command/StudyAreaCommand.java b/src/main/java/command/StudyAreaCommand.java index 5ae92d245..733a12651 100644 --- a/src/main/java/command/StudyAreaCommand.java +++ b/src/main/java/command/StudyAreaCommand.java @@ -4,8 +4,16 @@ import studyarea.StudyArea; import studyarea.StudyAreaList; import ui.Ui; - import java.util.ArrayList; +import static ui.Constants.AVAILABLE_STUDY_AREAS; +import static ui.Constants.BYE_COMMAND; +import static ui.Constants.EMPTY_LIST; +import static ui.Constants.EMPTY_LOCATION; +import static ui.Constants.END_MESSAGE; +import static ui.Constants.FLAGS; +import static ui.Constants.HELP_COMMAND; +import static ui.Constants.PROMPT_USER; +import static ui.Constants.START_STUDY_AREA_SEARCH; /** @@ -21,9 +29,9 @@ public class StudyAreaCommand { */ public static void printList(ArrayList availStudyAreas, Ui ui) { if (availStudyAreas.isEmpty()) { - ui.printMessage(Ui.EMPTY_LIST); + ui.printMessage(EMPTY_LIST); } else { - ui.printMessage(Ui.AVAILABLE_STUDY_AREAS); + ui.printMessage(AVAILABLE_STUDY_AREAS); for (StudyArea studyArea : availStudyAreas) { ui.printStudyArea(studyArea); } @@ -45,20 +53,20 @@ public static boolean filterCommand(String command, StudyAreaList studyAreaList, command = command.trim(); if (command.isBlank()) { - throw new IllegalStudyAreaException(Ui.EMPTY_LOCATION); + throw new IllegalStudyAreaException(EMPTY_LOCATION); } else { switch (command) { - case Ui.BYE_COMMAND: - ui.printMessage(Ui.END_MESSAGE); + case BYE_COMMAND: + ui.printMessage(END_MESSAGE); return false; - case Ui.HELP_COMMAND: - ui.printMessage(Ui.FLAGS); + case HELP_COMMAND: + ui.printMessage(FLAGS); break; default: try { ArrayList availStudyAreas = studyAreaList.searchList(command); printList(availStudyAreas, ui); - ui.printMessage(Ui.PROMPT_USER); + ui.printMessage(PROMPT_USER); } catch (IllegalStudyAreaException e) { ui.printMessage(e.getMessage()); } @@ -75,7 +83,7 @@ public static boolean filterCommand(String command, StudyAreaList studyAreaList, */ public static void runCommands(StudyAreaList studyAreaList, Ui ui) { ui.printLine(); - ui.printMessage(Ui.START_STUDY_AREA_SEARCH); + ui.printMessage(START_STUDY_AREA_SEARCH); boolean status = true; while (status) { ui.printLine(); diff --git a/src/main/java/command/TaskCommand.java b/src/main/java/command/TaskCommand.java index 095163f65..9ff2519ce 100644 --- a/src/main/java/command/TaskCommand.java +++ b/src/main/java/command/TaskCommand.java @@ -3,7 +3,8 @@ import parser.Parser; import task.TaskList; import ui.Ui; -import static ui.Ui.BYE_COMMAND; +import static ui.Constants.BYE_COMMAND; +import static ui.Constants.BYE_MESSAGE; /** * Used to run all the functions related to tasks. @@ -36,7 +37,7 @@ public static void runCommands(TaskList taskList, Ui ui, Parser parser) { } ui.printLine(); - ui.printMessage(Ui.BYE_MESSAGE); + ui.printMessage(BYE_MESSAGE); ui.printLine(); } diff --git a/src/main/java/resourceloader/BackUpData.java b/src/main/java/resourceloader/BackUpData.java new file mode 100644 index 000000000..ec6234972 --- /dev/null +++ b/src/main/java/resourceloader/BackUpData.java @@ -0,0 +1,40 @@ +package resourceloader; + +/** + * This class contains all the back up data for Study Area Loader, in case locations.txt and dictionary.txt + * does not exist. + */ +class BackUpData { + static final String BACKUP_DICTIONARY = "engineering~eng~engin~engine~foe\n" + + "utown~university town~u-town~u town\n" + + "maccommons~mccommons~mac commons\n" + + "education resource centre~erc\n" + + "stephen riady centre~stephen~riady~src\n" + + "ocbc~frank~frank by ocbc\n" + + "starbucks~bucks~bux~sbux\n" + + "pc commons~pccommons~pccommon\n" + + "yih~yusof ishak~yusof~ishak\n" + + "supersnacks~super snacks~super snack"; + + static final String BACKUP_LOCATIONS = "Opposite Town Green (Outside Starbucks)~2 College Avenue West Education " + + "Resource Centre, Ground Level~Utown~true~false~4\n" + + "Starbucks~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~5\n" + + "MacCommons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5\n" + + "PC Commons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5\n" + + "Ian and Peony Ferguson Study~2 College Ave West Education Resource Centre, Level 3~Utown~" + + "true~true~4\n" + + "The Study~2 College Ave West Education Resource Centre, Level 2~Utown~true~true~5\n" + + "Town Plaza Seminar Rooms Waiting Area~2 College Ave West, Town Plaza, Level 2~Utown~true~" + + "true~4\n" + + "OCBC~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~false~2\n" + + "SuperSnacks~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~true~4\n" + + "EA Level 1~9 Engineering Drive 1,EA, Level 1~Engineering~true~true~4\n" + + "EA Level 2~9 Engineering Drive 1,EA, Level 2~Engineering~true~true~4\n" + + "EA Level 3~9 Engineering Drive 1,EA, Level 3~Engineering~true~true~4\n" + + "EA Level 4~9 Engineering Drive 1,EA, Level 4, Outside Staff Offices~Engineering~true~false~6\n" + + "EA Level 5~9 Engineering Drive 1,EA, Level 5, Outside of the door beside EA05~Engineering~true~" + + "false~4\n" + + "EA Level 6~9 Engineering Drive 1,EA, Level 6, EA06-23~Engineering~true~true~4\n" + + "Central Library~Central Library 12 Kent Ridge Crescent~-~true~true~5\n" + + "YIH Study Room~Yusof Ishak House, Level 2~-~true~true~4"; +} diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index 9340581b1..8e49e8ba6 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -3,11 +3,18 @@ import studyarea.Dictionary; import studyarea.IllegalStudyAreaException; import studyarea.StudyArea; -import ui.Ui; import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Scanner; +import static ui.Constants.FILE_PATH_DICTIONARY; +import static ui.Constants.FILE_PATH_STUDYAREAS; +import static ui.Constants.INCONSISTENT_DATA_STORAGE; +import static ui.Constants.MISSING_STUDY_AREA_DATA; /** * This class loads all the required information of Study Areas that is stored in location.txt. @@ -32,7 +39,7 @@ public void loadFile() throws IllegalStudyAreaException { this.file = new File(this.url); Dictionary.loadDictionary(); } catch (NullPointerException e) { - throw new IllegalStudyAreaException(Ui.MISSING_STUDY_AREA_DATA); + throw new IllegalStudyAreaException(MISSING_STUDY_AREA_DATA); } catch (FileNotFoundException e) { throw new IllegalStudyAreaException(e.getMessage()); } @@ -55,7 +62,7 @@ public ArrayList pushToDatabase() throws IllegalStudyAreaException, F String[] detailsBuffer = detailsOfLocation.split(DIVIDER); if (detailsBuffer.length != 6) { String name = detailsBuffer[0]; - throw new IllegalStudyAreaException(Ui.INCONSISTENT_DATA_STORAGE + "at " + name); + throw new IllegalStudyAreaException(INCONSISTENT_DATA_STORAGE + "at " + name); } StudyArea studyArea = new StudyArea(detailsBuffer[0], detailsBuffer[1], detailsBuffer[2], Boolean.parseBoolean(detailsBuffer[3]), Boolean.parseBoolean(detailsBuffer[4]), @@ -65,5 +72,20 @@ public ArrayList pushToDatabase() throws IllegalStudyAreaException, F input.close(); return buffer; } + + /** + * This method creates a new data file for locations.txt and dictionary.txt. + * @throws IOException if cannot create file. + */ + public static void createNewStudyAreaData() throws IOException { + Files.createFile(Paths.get(FILE_PATH_STUDYAREAS)); + Files.createFile(Paths.get(FILE_PATH_DICTIONARY)); + PrintWriter dataBuffer = new PrintWriter(new File(FILE_PATH_STUDYAREAS)); + dataBuffer.println(BackUpData.BACKUP_LOCATIONS); + dataBuffer.close(); + dataBuffer = new PrintWriter(new File(FILE_PATH_DICTIONARY)); + dataBuffer.println(BackUpData.BACKUP_DICTIONARY); + dataBuffer.close(); + } } diff --git a/src/main/java/resourceloader/TaskLoader.java b/src/main/java/resourceloader/TaskLoader.java index 50366f718..ee157d365 100644 --- a/src/main/java/resourceloader/TaskLoader.java +++ b/src/main/java/resourceloader/TaskLoader.java @@ -14,7 +14,8 @@ import java.util.ArrayList; import java.util.Scanner; -import static seedu.duke.Duke.FILE_PATH_STUDYAREAS; +import static ui.Constants.FILE_PATH_DICTIONARY; +import static ui.Constants.FILE_PATH_STUDYAREAS; /** @@ -134,7 +135,7 @@ private void createNewDataFile() { try { Files.createDirectories(fileDirectory); Files.createFile(Paths.get(filePath)); - Files.createFile(Paths.get(FILE_PATH_STUDYAREAS)); + StudyAreaLoader.createNewStudyAreaData(); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 53d609344..3a160c86c 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -9,9 +9,12 @@ import studyarea.StudyAreaList; import task.TaskList; import ui.Ui; - import java.io.File; import java.io.FileNotFoundException; +import static ui.Constants.DAB; +import static ui.Constants.GOODBYE_MESSAGE; +import static ui.Constants.INTERMEDIATE_MESSAGE; +import static ui.Constants.WRONG_INPUT; /** @@ -59,21 +62,21 @@ public void run() { break; case 1: TaskCommand.runCommands(taskList, ui, parser); - ui.printMessage(Ui.INTERMEDIATE_MESSAGE); + ui.printMessage(INTERMEDIATE_MESSAGE); break; case 2: StudyAreaCommand.runCommands(studyAreaList, ui); - ui.printMessage(Ui.INTERMEDIATE_MESSAGE); + ui.printMessage(INTERMEDIATE_MESSAGE); break; default: ui.printLine(); - ui.printMessage(Ui.WRONG_INPUT); + ui.printMessage(WRONG_INPUT); break; } ui.printLine(); } taskLoader.saveTasks(taskList.tasks); - ui.printMessage(Ui.GOODBYE_MESSAGE + Ui.DAB); + ui.printMessage(GOODBYE_MESSAGE + DAB); ui.close(); } diff --git a/src/main/java/studyarea/StudyArea.java b/src/main/java/studyarea/StudyArea.java index b3f173188..8c040487b 100644 --- a/src/main/java/studyarea/StudyArea.java +++ b/src/main/java/studyarea/StudyArea.java @@ -3,6 +3,8 @@ import ui.Ui; import static java.lang.System.lineSeparator; +import static ui.Constants.MAX_LINE_LENGTH; +import static ui.Constants.TAB; /** @@ -98,14 +100,14 @@ public Integer getMaxPax() { * @return String value of all the attributes of the specific StudyArea. */ public String toString() { - String text = Ui.TAB + "Name: " + this.name + lineSeparator() - + Ui.formatMessage("Address: " + this.address, Ui.MAX_LINE_LENGTH) - + lineSeparator() + Ui.TAB - + "Faculty: " + this.faculty + lineSeparator() + Ui.TAB - + "Port: " + this.hasPort + lineSeparator() + Ui.TAB - + "Indoor: " + this.isIndoor + lineSeparator() + Ui.TAB - + "Average number of Pax: " + this.maxPax; - String line = Ui.TAB + "__________________________________________________________"; + String text = TAB + "Name: " + this.name + lineSeparator() + + Ui.formatMessage("Address: " + this.address, MAX_LINE_LENGTH) + + lineSeparator() + TAB + + "Faculty: " + this.faculty + lineSeparator() + TAB + + "Port: " + this.hasPort + lineSeparator() + TAB + + "Indoor: " + this.isIndoor + lineSeparator() + TAB + + "Maximum number of Pax: " + this.maxPax; + String line = TAB + "__________________________________________________________"; return line + lineSeparator() + text + lineSeparator() + line; } diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 4259462a3..206d24d19 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -1,7 +1,20 @@ package studyarea; -import ui.Ui; import java.util.ArrayList; +import static ui.Constants.DUPLICATE_FLAGS; +import static ui.Constants.FLAG; +import static ui.Constants.INDOOR_FLAG; +import static ui.Constants.MULTIPLE_WHITE_SPACES; +import static ui.Constants.NON_POSITIVE_INTEGER; +import static ui.Constants.NOT_INTEGER; +import static ui.Constants.NO_SIZE_INDICATED; +import static ui.Constants.ONLY_FLAG; +import static ui.Constants.OUTDOOR_FLAG; +import static ui.Constants.PORTS_FLAG; +import static ui.Constants.SIZE_FLAG; +import static ui.Constants.SPACE; +import static ui.Constants.WRONG_FLAG_ARGUMENT_POSITION; +import static ui.Constants.WRONG_FLAG_USAGE; /** * This is the class that stores and manages all of the Study Areas in location.txt @@ -33,7 +46,7 @@ public ArrayList getStudyAreaList() { */ public static void checkDuplicate(String[] flag, int index) throws IllegalStudyAreaException { if (flag[index] != null) { - throw new IllegalStudyAreaException(Ui.DUPLICATE_FLAGS); + throw new IllegalStudyAreaException(DUPLICATE_FLAGS); } } @@ -46,10 +59,31 @@ public static void checkDuplicate(String[] flag, int index) throws IllegalStudyA public static void checkOnlyFlag(String[] commands, int index) throws IllegalStudyAreaException { if (commands[index].length() == 1) { - throw new IllegalStudyAreaException(Ui.ONLY_FLAG); + throw new IllegalStudyAreaException(ONLY_FLAG); } } + /** + * This method checks if the command after the size flag is a valid integer. + * @param commands this is the array of commands entered. + * @param index this is the index where the size flag is. + * @throws IllegalStudyAreaException if command entered is not a valid integer. + */ + public static void checkInteger(String[] commands, int index) throws IllegalStudyAreaException { + + try { // try block is to test if command is integer + int size = Integer.parseInt(commands[index + 1]); + if (size <= 0) { // check if integer is positive, else throw exception. + throw new IllegalStudyAreaException(NON_POSITIVE_INTEGER); + } + } catch (NumberFormatException e) { // catch if command is not integer then throw exception + throw new IllegalStudyAreaException(NOT_INTEGER); + } catch (ArrayIndexOutOfBoundsException e) { // catch if no string exist after "-s" and throw exception + throw new IllegalStudyAreaException(NO_SIZE_INDICATED); + } + + } + /** * This method validate flags based on User input. * @@ -59,19 +93,13 @@ public static void checkOnlyFlag(String[] commands, int index) throws IllegalStu * @param isNotFlag this is the boolean value that checks if the command entered is a flag. * @throws IllegalStudyAreaException if user enters command wrongly. */ - private void checkFlag(String[] flags, String[] commands, int index, boolean isNotFlag) throws + public static void checkFlag(String[] flags, String[] commands, int index, boolean isNotFlag) throws IllegalStudyAreaException { //isNotFlag is used to track previous instances of "-" - if (commands[index].equals(Ui.SIZE_FLAG)) { // for instances of "-s", check if next string is integer or null. + if (commands[index].equals(SIZE_FLAG)) { // for instances of "-s", check if next string is integer or null. checkDuplicate(flags, 0); - try { // try block is to test if command is integer - int size = Integer.parseInt(commands[index + 1]); - } catch (NumberFormatException e) { // catch if command is not integer then throw exception - throw new IllegalStudyAreaException(Ui.NOT_INTEGER); - } catch (ArrayIndexOutOfBoundsException e) { // catch if no string exist after "-s" and throw exception - throw new IllegalStudyAreaException(Ui.NO_SIZE_INDICATED); - } - } else if (commands[index].contains(Ui.FLAG)) { // for instances "-" , + checkInteger(commands, index); // check if subsequent command is a valid integer. + } else if (commands[index].contains(FLAG)) { // for instances "-" , checkOnlyFlag(commands, index); // check if only "-" exist, if true, then throw exception switch (commands[index].charAt(1)) { // if "-p", "-i" , "-o" then check if duplicate. Else, throw case 'p': // exception for wrong usage of flag @@ -82,11 +110,11 @@ private void checkFlag(String[] flags, String[] commands, int index, boolean isN checkDuplicate(flags, 3); break; default: - throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); + throw new IllegalStudyAreaException(WRONG_FLAG_USAGE); } } else { // if no instances of "-" or "-s" if (!isNotFlag) { // and if there exist previous instances of "-" (i.e: -p EA) - throw new IllegalStudyAreaException(Ui.WRONG_FLAG_ARGUMENT_POSITION); // throw exception + throw new IllegalStudyAreaException(WRONG_FLAG_ARGUMENT_POSITION); // throw exception } } } @@ -109,31 +137,31 @@ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException StringBuilder name = new StringBuilder(); boolean isNotFlag = true; // to keep track of instance "-" is input. for (int i = 0; i < commands.length; i++) { - if (commands[i].equals(Ui.SIZE_FLAG)) { + if (commands[i].equals(SIZE_FLAG)) { isNotFlag = false; // update isNotFlag as false because command is a flag checkFlag(flags, commands, i, false); // pass false instead of isNotFlag as only boolean logic - flags[0] = Ui.SIZE_FLAG; + flags[0] = SIZE_FLAG; flags[1] = Integer.toString(Integer.parseInt(commands[i + 1])); i++; - } else if (commands[i].contains(Ui.FLAG)) { + } else if (commands[i].contains(FLAG)) { isNotFlag = false; checkFlag(flags, commands, i,false); switch (commands[i].charAt(1)) { case 'p': - flags[2] = Ui.PORTS_FLAG; + flags[2] = PORTS_FLAG; break; case 'i': - flags[3] = Ui.INDOOR_FLAG; + flags[3] = INDOOR_FLAG; break; case 'o': - flags[3] = Ui.OUTDOOR_FLAG; + flags[3] = OUTDOOR_FLAG; break; default: - throw new IllegalStudyAreaException(Ui.WRONG_FLAG_USAGE); + throw new IllegalStudyAreaException(WRONG_FLAG_USAGE); } } else { // if no previous instances of "-" if (isNotFlag) { // and if input is not a flag - name.append(commands[i]).append(Ui.SPACE); // concatenate subsequent input that pass the control + name.append(commands[i]).append(SPACE); // concatenate subsequent input that pass the control flags[4] = name.toString().trim(); // flag } else { checkFlag(flags, commands, i, false); // if has previous instances of "-" and input is not @@ -170,34 +198,33 @@ public static boolean containsKey(String name, String address, String faculty, S * @throws IllegalStudyAreaException if User enters invalid commands. */ public ArrayList searchList(String userIn) throws IllegalStudyAreaException { - String[] temp = userIn.split(Ui.MULTIPLE_WHITE_SPACES); + String[] temp = userIn.split(MULTIPLE_WHITE_SPACES); String[] flags = getFlagsInfo(temp); ArrayList availStudyAreas = new ArrayList<>(); for (StudyArea studyArea : this.studyAreaList) { boolean isAvail = true; + int index = 0; for (String flag : flags) { - if (flag != null && isAvail) { + if (flag != null && isAvail && index != 1) { switch (flag) { - case Ui.PORTS_FLAG: + case PORTS_FLAG: isAvail = studyArea.hasPort(); break; - case Ui.INDOOR_FLAG: + case INDOOR_FLAG: isAvail = studyArea.isIndoor(); break; - case Ui.OUTDOOR_FLAG: + case OUTDOOR_FLAG: isAvail = !studyArea.isIndoor(); break; - case Ui.SIZE_FLAG: // allows user to find by capacity <= MaxPax - if (flags[1] != null) { - isAvail = Integer.parseInt(flags[1]) >= studyArea.getMaxPax(); - } - flags[1] = null; //so as to skip iteration on flags[1]. + case SIZE_FLAG: // allows user to find by capacity <= MaxPax + isAvail = Integer.parseInt(flags[1]) <= studyArea.getMaxPax(); break; default: // toLowerCase() so casing does not affect matching isAvail = containsKey(studyArea.getName().toLowerCase(), studyArea.getAddress().toLowerCase(), studyArea.getFaculty().toLowerCase(), flags[4].toLowerCase()); break; } + index++; } } if (isAvail) { diff --git a/src/main/java/task/TaskList.java b/src/main/java/task/TaskList.java index a26c2290f..e64568898 100644 --- a/src/main/java/task/TaskList.java +++ b/src/main/java/task/TaskList.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; - import ui.Ui; /** diff --git a/src/main/java/ui/Constants.java b/src/main/java/ui/Constants.java new file mode 100644 index 000000000..1887b2c51 --- /dev/null +++ b/src/main/java/ui/Constants.java @@ -0,0 +1,121 @@ +package ui; + +import java.io.File; + +/** + * This class contains all the constants required for Ui. + */ +public class Constants { + public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; + public static final String FILE_PATH_DICTIONARY = "library" + File.separator + "dictionary.txt"; + public static final String MISSING_STUDY_AREA_DATA = "locations.txt is missing"; + public static final String BYE_COMMAND = "bye"; + public static final String BYE_MESSAGE = "Bye!!!!!!"; + public static final String LINE = "_______________________________________________________________________________" + + "_________________"; + public static final int MAX_LINE_LENGTH = 58; + public static final String FLAG = "-"; + public static final String MULTIPLE_WHITE_SPACES = "\\s+"; + public static final String DUPLICATE_FLAGS = "Duplicate flags entered!"; + public static final String SIZE_FLAG = "-s"; + public static final String PORTS_FLAG = "-p"; + public static final String INDOOR_FLAG = "-i"; + public static final String OUTDOOR_FLAG = "-o"; + public static final String NOT_INTEGER = "Argument used after size flag \"-s\" is not an integer"; + public static final String WRONG_FLAG_USAGE = "Flags indicated are wrongly used. Please enter \"help\" for the" + + " supported flags!"; + public static final String SPACE = " "; + public static final String WRONG_FLAG_ARGUMENT_POSITION = "Flags are to be used only after location"; + public static final String START_STUDY_AREA_SEARCH = "Please enter the location for your desired study area. " + + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" + + " location is entered. When you are done with the search, enter \"bye\"."; + public static final String PROMPT_USER = "Please enter the location for your desired study area."; + public static final String FLAGS = "Here is a list of supported flags!\n\t -p for study areas with ports\n\t" + + " -i for study areas that are indoors\n\t -i for study areas that are outdoors\n\t " + + "-s {size} for maximum number of pax"; + public static final String AVAILABLE_STUDY_AREAS = "Here are the available study areas!"; + public static final String EMPTY_LIST = "Oops! Based on your criteria we were not able to find a compatible study" + + " area!"; + public static final String ONLY_FLAG = "Please enter the flag along with \"-\""; + public static final String INCONSISTENT_DATA_STORAGE = "Data is wrongly stored in locations.txt"; + public static final String HELP_COMMAND = "help"; + public static final String TAB = "\t "; + public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; + public static final String END_MESSAGE = "Thank you for using our study area search service!"; + public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"task\" to start" + + " your event list! If you are in the mood to mug and you" + + " want to start your study area list, enter \"study\" !If" + + " you want to exit, enter \"bye\" !"; + public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; + public static final String TASK_COMMAND = "task"; + public static final String STUDY_COMMAND = "study"; + public static final String GOODBYE_MESSAGE = " Goodbye! Hope to see you again!"; + public static final String INTERMEDIATE_MESSAGE = "Please enter \"task\" to continue with your event list or" + + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; + public static final String EMPTY_LOCATION = "Location entered is empty! Please type a location to search for " + + "StudyAreas!"; + public static final String NON_POSITIVE_INTEGER = "Integer entered cannot be zero or negative!"; + public static final String HELP_DESCRIPTION_20 = TAB + "*There are 4 levels of priority, with 1 being the most " + + "urgent, and 4 being the least urgent"; + public static final String HELP_DESCRIPTION_19 = TAB + "*All timing should follow 24 hour clock"; + public static final String HELP_DESCRIPTION_18 = TAB + "*All dates should follow YYYY-MM-DD format"; + public static final String HELP_DESCRIPTION_17 = TAB + "Notes:"; + public static final String HELP_DESCRIPTION_16 = TAB + "bye --------------------------------------- Terminate task" + + " interface"; + public static final String HELP_DESCRIPTION_15 = TAB + "help -------------------------------------- View List Of " + + "Commands Supported"; + public static final String HELP_DESCRIPTION_14 = TAB + "edit --------------- Edit the task"; + public static final String HELP_DESCRIPTION_13 = TAB + "delete ------------- Delete the " + + "task"; + public static final String HELP_DESCRIPTION_12 = TAB + "search ------------ View existing " + + "task that contains the keyword"; + public static final String HELP_DESCRIPTION_11 = TAB + "clear ------------------------------------- Delete" + + " all tasks"; + public static final String HELP_DESCRIPTION_10 = TAB + "countdown --------------------------------- View existing" + + " tasks based on days left"; + public static final String HELP_DESCRIPTION_9 = TAB + "priority_view ----------------------------- View existing " + + "tasks based on priority"; + public static final String HELP_DESCRIPTION_8 = TAB + "view -------------------------------------- View existing" + + " events"; + public static final String HELP_DESCRIPTION_7 = TAB + "------------------------------------------- Create a new " + + "deadline"; + public static final String HELP_DESCRIPTION_5 = TAB + "deadline /d /t /p " + + ""; + public static final String HELP_DESCRIPTION_4 = TAB + "------------------------------------------- Create a new " + + "event"; + public static final String HELP_DESCRIPTION_3 = TAB + "event /d /s " + + "/e /p "; + public static final String HELP_DESCRIPTION_2 = TAB + "Please enter the keywords followed by the information" + + " shown in the brackets"; + public static final String HELP_DESCRIPTION_1 = TAB + "OrgaNice! Supports the following commands"; + //@@author NizarMohd-reused + //Reused from https://www.netclipart.com/isee/iRwmhJb_bt21-rj-transparent-background/ and https://asciiart.club/ + //Image for public static final String DAB is obtained from the first link and then generated in second link. + public static final String DAB = "\t ``````````````````````````````````````````````````````````\n" + + "\t ````````````````````````````````:v(v'`````````````````````\n" + + "\t ```````````````````````````,)4|ex` `L}````````````````````\n" + + "\t `````````````````````````!s\"'h `M: ^z_;)T```````````````\n" + + "\t `````````````````````````Z u|}Z: \"}``````````````\n" + + "\t ``````````````````````:=?) 'B?L'```````````\n" + + "\t `````````````````````'Z ;Yp\"```````````\n" + + "\t `````````````````````.e ?_```````````\n" + + "\t ```````````````````'QDGH .5````````````\n" + + "\t ````````````````````I#g' '_` ||````````````\n" + + "\t ```````````:mX_``````YhL` `'q!` ? h````````````\n" + + "\t ```````````'Qbs)|L=_V\" 'Y} ^'q@&b=c=_` ,Z````````````\n" + + "\t ````````````q> 'T, ,o\" ;\"@c. .sVx~`````````````\n" + + "\t ````````````c! \"bh` `,p z:``````````````\n" + + "\t `````````````q. ngDQmh8s X'``````````````\n" + + "\t ``````````````LY\" :n}>``b; _V```````````````\n" + + "\t ````````````````q?, ?; \"V````````````````\n" + + "\t ``````````````KvR ' )x_`````````````````\n" + + "\t ``````````````zjL GLY\"```````````````````\n" + + "\t ```````````````M .I)``````````````````````\n" + + "\t ```````````````Lz `D:``````````````````````\n" + + "\t ``````````````vu` (I)_;\"\". P.`````````````````````\n" + + "\t ``````````````p :X.':^,\"=n \"q``````````````````````\n" + + "\t `````````````)0X?^:)I````````m' :j``````````````````````\n" + + "\t `````````````.IGD8k'`````````<&G55M```````````````````````\n" + + "\t ``````````````````````````````````````````````````````````"; + //@@author +} diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index d36ef34a5..129ad1c79 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -2,12 +2,40 @@ import studyarea.StudyArea; -import java.io.File; import java.io.InputStream; import java.io.PrintStream; import java.util.Scanner; import java.util.StringTokenizer; import static java.lang.System.lineSeparator; +import static ui.Constants.BYE_COMMAND; +import static ui.Constants.DAB; +import static ui.Constants.GOODBYE_MESSAGE; +import static ui.Constants.HELP_DESCRIPTION_1; +import static ui.Constants.HELP_DESCRIPTION_10; +import static ui.Constants.HELP_DESCRIPTION_11; +import static ui.Constants.HELP_DESCRIPTION_12; +import static ui.Constants.HELP_DESCRIPTION_13; +import static ui.Constants.HELP_DESCRIPTION_14; +import static ui.Constants.HELP_DESCRIPTION_15; +import static ui.Constants.HELP_DESCRIPTION_16; +import static ui.Constants.HELP_DESCRIPTION_17; +import static ui.Constants.HELP_DESCRIPTION_18; +import static ui.Constants.HELP_DESCRIPTION_19; +import static ui.Constants.HELP_DESCRIPTION_2; +import static ui.Constants.HELP_DESCRIPTION_20; +import static ui.Constants.HELP_DESCRIPTION_3; +import static ui.Constants.HELP_DESCRIPTION_4; +import static ui.Constants.HELP_DESCRIPTION_5; +import static ui.Constants.HELP_DESCRIPTION_7; +import static ui.Constants.HELP_DESCRIPTION_8; +import static ui.Constants.HELP_DESCRIPTION_9; +import static ui.Constants.LINE; +import static ui.Constants.MAX_LINE_LENGTH; +import static ui.Constants.SPACE; +import static ui.Constants.START_MESSAGE; +import static ui.Constants.STUDY_COMMAND; +import static ui.Constants.TAB; +import static ui.Constants.TASK_COMMAND; /** * Contains functions used to interact with the user. @@ -17,88 +45,6 @@ public class Ui { private final Scanner in; private final PrintStream out; - public static final String FILE_PATH_EVENTS = "library" + File.separator + "eventList.txt"; - public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; - public static final String FILE_PATH_DICTIONARY = "library" + File.separator + "dictionary.txt"; - public static final String MISSING_STUDY_AREA_DATA = "locations.txt is missing"; - public static final String BYE_COMMAND = "bye"; - public static final String BYE_MESSAGE = "Bye!!!!!!"; - public static final String LINE = "_______________________________________________________________________________" - + "_____"; - public static final int MAX_LINE_LENGTH = 58; - public static final String FLAG = "-"; - public static final String MULTIPLE_WHITE_SPACES = "\\s+"; - public static final String DUPLICATE_FLAGS = "Duplicate flags entered!"; - public static final String SIZE_FLAG = "-s"; - public static final String PORTS_FLAG = "-p"; - public static final String INDOOR_FLAG = "-i"; - public static final String OUTDOOR_FLAG = "-o"; - public static final String NOT_INTEGER = "Argument used after size flag \"-s\" is not an integer"; - public static final String WRONG_FLAG_USAGE = "Flags indicated are wrongly used. Please enter \"help\" for the" - + " supported flags!"; - public static final String SPACE = " "; - public static final String WRONG_FLAG_ARGUMENT_POSITION = "Flags are to be used only after location"; - public static final String START_STUDY_AREA_SEARCH = "Please enter the location for your desired study area. " - + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" - + " location is entered. When you are done with the search, enter \"bye\"."; - public static final String PROMPT_USER = "Please enter the location for your desired study area."; - public static final String FLAGS = "Here is a list of supported flags!\n\t -p for study areas with ports\n\t" - + " -i for study areas that are indoors\n\t -i for study areas that are outdoors\n\t " - + "-s {size} for maximum number of pax"; - public static final String AVAILABLE_STUDY_AREAS = "Here are the available study areas!"; - public static final String EMPTY_LIST = "Oops! Based on your criteria we were not able to find a compatible study" - + "area!"; - public static final String ONLY_FLAG = "Please enter the flag along with \"-\""; - public static final String INCONSISTENT_DATA_STORAGE = "Data is wrongly stored in locations.txt"; - public static final String HELP_COMMAND = "help"; - public static final String TAB = "\t "; - public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; - public static final String END_MESSAGE = "Thank you for using our study area search service!"; - public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"event\" to start\n" - + " your event list! If you are in the mood to mug and you" - + " want to start your study area list, enter \"study\" !If" - + " you want to exit, enter \"bye\" !"; - public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; - public static final String EVENT_COMMAND = "event"; - public static final String STUDY_COMMAND = "study"; - public static final String GOODBYE_MESSAGE = " Goodbye! Hope to see you again!"; - public static final String INTERMEDIATE_MESSAGE = "Please enter \"event\" to continue with your event list or" - + " \"study\" to continue with your study area list. To leave, enter \"bye\"."; - public static final String EMPTY_LOCATION = "Location entered is empty! Please type a location to search for " - + "StudyAreas!"; - - //@@author NizarMohd-reused - //Reused from https://www.netclipart.com/isee/iRwmhJb_bt21-rj-transparent-background/ and https://asciiart.club/ - //Image for public static final String DAB is obtained from the first link and then generated in second link. - public static final String DAB = "\t ``````````````````````````````````````````````````````````\n" - + "\t ````````````````````````````````:v(v'`````````````````````\n" - + "\t ```````````````````````````,)4|ex` `L}````````````````````\n" - + "\t `````````````````````````!s\"'h `M: ^z_;)T```````````````\n" - + "\t `````````````````````````Z u|}Z: \"}``````````````\n" - + "\t ``````````````````````:=?) 'B?L'```````````\n" - + "\t `````````````````````'Z ;Yp\"```````````\n" - + "\t `````````````````````.e ?_```````````\n" - + "\t ```````````````````'QDGH .5````````````\n" - + "\t ````````````````````I#g' '_` ||````````````\n" - + "\t ```````````:mX_``````YhL` `'q!` ? h````````````\n" - + "\t ```````````'Qbs)|L=_V\" 'Y} ^'q@&b=c=_` ,Z````````````\n" - + "\t ````````````q> 'T, ,o\" ;\"@c. .sVx~`````````````\n" - + "\t ````````````c! \"bh` `,p z:``````````````\n" - + "\t `````````````q. ngDQmh8s X'``````````````\n" - + "\t ``````````````LY\" :n}>``b; _V```````````````\n" - + "\t ````````````````q?, ?; \"V````````````````\n" - + "\t ``````````````KvR ' )x_`````````````````\n" - + "\t ``````````````zjL GLY\"```````````````````\n" - + "\t ```````````````M .I)``````````````````````\n" - + "\t ```````````````Lz `D:``````````````````````\n" - + "\t ``````````````vu` (I)_;\"\". P.`````````````````````\n" - + "\t ``````````````p :X.':^,\"=n \"q``````````````````````\n" - + "\t `````````````)0X?^:)I````````m' :j``````````````````````\n" - + "\t `````````````.IGD8k'`````````<&G55M```````````````````````\n" - + "\t ``````````````````````````````````````````````````````````"; - //@@author - - /** * This is the constructor used to create the Ui class in Duke.run(). */ @@ -125,7 +71,7 @@ public Ui(InputStream in, PrintStream out) { public int getMode() { String userIn = this.in.nextLine().toLowerCase(); switch (userIn) { - case EVENT_COMMAND : + case TASK_COMMAND : return 1; case STUDY_COMMAND : return 2; @@ -239,27 +185,25 @@ public void printEmptyLine() { */ public void printHelp() { printLine(); - this.out.println(TAB + "OrgaNice! Supports the following commands"); - this.out.println(TAB + "Please enter the keywords followed by the information shown in the brackets"); - this.out.println(TAB + "add /d /s /e /p "); - this.out.println(TAB + "------------------------------------------- Create a new event"); - this.out.println(TAB + "view -------------------------------------- View existing events"); - this.out.println(TAB + "priority_view ----------------------------- View existing events based " - + "on priority"); - this.out.println(TAB + "countdown --------------------------------- View existing events based on" - + " days left"); - this.out.println(TAB + "clear ------------------------------------- Delete all events"); - this.out.println(TAB + "search ----------- View existing events that contains " - + "the keyword"); - this.out.println(TAB + "delete ------------ Delete the event"); - this.out.println(TAB + "help -------------------------------------- View List Of Commands Supported"); - this.out.println(TAB + "bye --------------------------------------- Terminate program"); - this.out.println(TAB + "Notes:"); - this.out.println(TAB + "*All dates should follow YYYY-MM-DD format"); - this.out.println(TAB + "*All timing should follow 24 hour clock"); - this.out.println(TAB + "*There are 4 levels of priority, with 1 being the most urgent, and 4 being the " - + "least urgent"); + this.out.println(HELP_DESCRIPTION_1); + this.out.println(HELP_DESCRIPTION_2); + this.out.println(HELP_DESCRIPTION_3); + this.out.println(HELP_DESCRIPTION_4); + this.out.println(HELP_DESCRIPTION_5); + this.out.println(HELP_DESCRIPTION_7); + this.out.println(HELP_DESCRIPTION_8); + this.out.println(HELP_DESCRIPTION_9); + this.out.println(HELP_DESCRIPTION_10); + this.out.println(HELP_DESCRIPTION_11); + this.out.println(HELP_DESCRIPTION_12); + this.out.println(HELP_DESCRIPTION_13); + this.out.println(HELP_DESCRIPTION_14); + this.out.println(HELP_DESCRIPTION_15); + this.out.println(HELP_DESCRIPTION_16); + this.out.println(HELP_DESCRIPTION_17); + this.out.println(HELP_DESCRIPTION_18); + this.out.println(HELP_DESCRIPTION_19); + this.out.println(HELP_DESCRIPTION_20); printLine(); } @@ -285,7 +229,7 @@ public static String formatMessage(String message, int maxLength) { if (lineLength + word.length() > maxLength) { String temp = standardLengthMessage.toString().trim(); standardLengthMessage = new StringBuilder(temp); - standardLengthMessage.append(lineSeparator() + "\t "); + standardLengthMessage.append(lineSeparator()).append("\t "); lineLength = 0; } standardLengthMessage.append(word).append(SPACE); diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 61ad4cd64..3a9bbe90e 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -33,4 +33,21 @@ task countdown view countdown bye +study + +help +erc +src +sbux +-i -i +-i -o +-i +-p +-s +-s wegf +-s 8 +-s 1 +- +-qef +bye bye \ No newline at end of file From a2659010fb9e9071322c8762f04f2b665bc02f58 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 22:59:55 +0800 Subject: [PATCH 093/435] Enable assertions --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a6db99138..144f8e341 100644 --- a/build.gradle +++ b/build.gradle @@ -36,5 +36,6 @@ checkstyle { } run{ + enableAssertions = true standardInput = System.in -} \ No newline at end of file +} From 64e3337ecb5b17ccfb31f6fa03c9d1dfa4477525 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 23:02:19 +0800 Subject: [PATCH 094/435] Abstract out exceptions thrown as seperate exception classes --- src/main/java/command/AddDeadlineCommand.java | 4 + ...ineCreationFormatNotFollowedException.java | 11 + ...entCreationFormatNotFollowedException.java | 11 + .../EventStartTimeAfterEndTimeException.java | 11 + .../command/InvalidDateException.java | 9 + .../command/InvalidEndTimeException.java | 11 + .../command/InvalidStartTimeException.java | 9 + .../command/SearchKeywordEmptyException.java | 9 + .../TaskDateBeforeCurrentDateException.java | 9 + .../TaskPriorityNotIntegerException.java | 11 + src/main/java/task/Event.java | 190 ++++++++++++++---- 11 files changed, 251 insertions(+), 34 deletions(-) create mode 100644 src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java create mode 100644 src/main/java/exception/command/EventCreationFormatNotFollowedException.java create mode 100644 src/main/java/exception/command/EventStartTimeAfterEndTimeException.java create mode 100644 src/main/java/exception/command/InvalidDateException.java create mode 100644 src/main/java/exception/command/InvalidEndTimeException.java create mode 100644 src/main/java/exception/command/InvalidStartTimeException.java create mode 100644 src/main/java/exception/command/SearchKeywordEmptyException.java create mode 100644 src/main/java/exception/command/TaskDateBeforeCurrentDateException.java create mode 100644 src/main/java/exception/command/TaskPriorityNotIntegerException.java diff --git a/src/main/java/command/AddDeadlineCommand.java b/src/main/java/command/AddDeadlineCommand.java index 7600204e3..0a303e924 100644 --- a/src/main/java/command/AddDeadlineCommand.java +++ b/src/main/java/command/AddDeadlineCommand.java @@ -1,5 +1,6 @@ package command; +import exception.command.DeadlineCreationFormatNotFollowedException; import exception.command.EventDetailsNotProvidedException; import task.Deadline; import task.TaskList; @@ -26,6 +27,9 @@ public AddDeadlineCommand(String[] deadlineDetails, boolean isOneWordCommand) th throw new EventDetailsNotProvidedException(); } String[] details = deadlineDetails[1].split("/"); + if (details.length != 4) { + throw new DeadlineCreationFormatNotFollowedException(); + } String description = details[0]; String date = details[1].substring(2); String dueTime = details[2].substring(2); diff --git a/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java b/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java new file mode 100644 index 000000000..db21c9aa6 --- /dev/null +++ b/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java @@ -0,0 +1,11 @@ +package exception.command; + +import exception.CustomException; + +import static ui.Ui.HELP_DESCRIPTION_5; + +public class DeadlineCreationFormatNotFollowedException extends CustomException { + public DeadlineCreationFormatNotFollowedException() { + super("Please follow the correct format to add a new deadline\n" + HELP_DESCRIPTION_5); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/EventCreationFormatNotFollowedException.java b/src/main/java/exception/command/EventCreationFormatNotFollowedException.java new file mode 100644 index 000000000..ce475d574 --- /dev/null +++ b/src/main/java/exception/command/EventCreationFormatNotFollowedException.java @@ -0,0 +1,11 @@ +package exception.command; + +import exception.CustomException; + +import static ui.Ui.HELP_DESCRIPTION_3; + +public class EventCreationFormatNotFollowedException extends CustomException { + public EventCreationFormatNotFollowedException() { + super("Please follow the correct format to add a new event\n" + HELP_DESCRIPTION_3); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/EventStartTimeAfterEndTimeException.java b/src/main/java/exception/command/EventStartTimeAfterEndTimeException.java new file mode 100644 index 000000000..293969564 --- /dev/null +++ b/src/main/java/exception/command/EventStartTimeAfterEndTimeException.java @@ -0,0 +1,11 @@ +package exception.command; + +import exception.CustomException; + +import static ui.Ui.HELP_DESCRIPTION_5; + +public class EventStartTimeAfterEndTimeException extends CustomException { + public EventStartTimeAfterEndTimeException() { + super("Start time should be before End time"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/InvalidDateException.java b/src/main/java/exception/command/InvalidDateException.java new file mode 100644 index 000000000..aa0a13d22 --- /dev/null +++ b/src/main/java/exception/command/InvalidDateException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class InvalidDateException extends CustomException { + public InvalidDateException() { + super("Date provided is invalid or is in wrong format (Should be YYYY-MM-DD)"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/InvalidEndTimeException.java b/src/main/java/exception/command/InvalidEndTimeException.java new file mode 100644 index 000000000..f46b285a8 --- /dev/null +++ b/src/main/java/exception/command/InvalidEndTimeException.java @@ -0,0 +1,11 @@ +package exception.command; + +import exception.CustomException; + +import static ui.Ui.HELP_DESCRIPTION_5; + +public class InvalidEndTimeException extends CustomException { + public InvalidEndTimeException() { + super("End time provided is invalid or in wrong format (Should be HH:MM)"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/InvalidStartTimeException.java b/src/main/java/exception/command/InvalidStartTimeException.java new file mode 100644 index 000000000..2326cd322 --- /dev/null +++ b/src/main/java/exception/command/InvalidStartTimeException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class InvalidStartTimeException extends CustomException { + public InvalidStartTimeException() { + super("Start time provided is invalid or in wrong format (Should be HH:MM)"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/SearchKeywordEmptyException.java b/src/main/java/exception/command/SearchKeywordEmptyException.java new file mode 100644 index 000000000..dd8d675a2 --- /dev/null +++ b/src/main/java/exception/command/SearchKeywordEmptyException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class SearchKeywordEmptyException extends CustomException { + public SearchKeywordEmptyException() { + super("Keyword to be used for search is empty"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/TaskDateBeforeCurrentDateException.java b/src/main/java/exception/command/TaskDateBeforeCurrentDateException.java new file mode 100644 index 000000000..8a0f8471a --- /dev/null +++ b/src/main/java/exception/command/TaskDateBeforeCurrentDateException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class TaskDateBeforeCurrentDateException extends CustomException { + public TaskDateBeforeCurrentDateException() { + super("Date specified must be a current or a future date"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/TaskPriorityNotIntegerException.java b/src/main/java/exception/command/TaskPriorityNotIntegerException.java new file mode 100644 index 000000000..2c00ffb57 --- /dev/null +++ b/src/main/java/exception/command/TaskPriorityNotIntegerException.java @@ -0,0 +1,11 @@ +package exception.command; + +import exception.CustomException; + +import static ui.Ui.HELP_DESCRIPTION_5; + +public class TaskPriorityNotIntegerException extends CustomException { + public TaskPriorityNotIntegerException() { + super("Priority should be an integer"); + } +} \ No newline at end of file diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java index d2eeca81a..d55742839 100644 --- a/src/main/java/task/Event.java +++ b/src/main/java/task/Event.java @@ -1,5 +1,12 @@ package task; +import exception.command.EventStartTimeAfterEndTimeException; +import exception.command.InvalidDateException; +import exception.command.InvalidEndTimeException; +import exception.command.InvalidStartTimeException; +import exception.command.SearchKeywordEmptyException; +import exception.command.TaskDateBeforeCurrentDateException; +import exception.command.TaskPriorityNotIntegerException; import ui.Ui; import java.time.LocalDate; @@ -19,6 +26,31 @@ public class Event extends Task { public static final int EDIT_END_TIME = 4; public static final int EDIT_PRIORITY = 5; public static final String ERROR_MESSAGE = "Error encountered during execution"; + public static final String DATE_PATTERN = "MMM d yyyy"; + public static final String EVENT_SYMBOL = "[E] "; + public static final String AT = " at "; + public static final String FROM = " from "; + public static final String TO = " to "; + public static final String WITH_PRIORITY = " with priority "; + public static final String EMPTY_STRING = ""; + public static final String DELIMITER = "#"; + public static final String NEW_LINE_CHARACTER = "\n"; + public static final String EVENT_IDENTIFIER = "E"; + public static final String ENTER_NEW_PRIORITY_MESSAGE = "Enter new priority:"; + public static final String ENTER_NEW_END_TIME_MESSAGE = "Enter new End Time:"; + public static final String ENTER_NEW_START_TIME_MESSAGE = "Enter new Start Time:"; + public static final String ENTER_NEW_DATE_MESSAGE = "Enter new Date:"; + public static final String ENTER_NEW_DESCRIPTION_MESSAGE = "Enter new description:"; + public static final String ENTER_VALID_NUMBER_FROM_LIST_MESSAGE = "Please enter a valid number from the list"; + public static final String UPDATED_DETAILS = "Updated Details:"; + public static final String EVENT_DETAILS_AS_FOLLOWS_MESSAGE = "The event details are as follows:"; + public static final String ENTER_OPTION_MESSAGE = "Which field of the event to edit? (Enter Corresponding Number)"; + public static final String OPTION_TO_EDIT_DESCRIPTION = "1. Description"; + public static final String OPTION_TO_EDIT_DATE = "2. Date"; + public static final String OPTION_TO_EDIT_START_TIME = "3. Start Time"; + public static final String OPTION_TO_EDIT_END_TIME = "4. End Time"; + public static final String OPTION_TO_EDIT_PRIORITY = "5. Priority"; + private String description; private LocalDate date; private LocalTime startTime; @@ -34,6 +66,25 @@ public void setPriority(int priority) { this.priority = priority; } + /** + * Getter function for Start Time of Event. + * + * @return Start time of event. + */ + public LocalTime getStartTime() { + return startTime; + } + + /** + * Getter function for End Time of Event. + * + * @return End time of event. + */ + public LocalTime getEndTime() { + return endTime; + } + + /** * Constructor for Event Class. * @@ -51,48 +102,76 @@ public Event(String description, String date, String startTime, String endTime, parseDate(date); parseStartTime(startTime); parseEndTime(endTime); - parsePriority(priority); if (this.startTime.isAfter(this.endTime)) { - throw new Exception("Start time should be before End time"); - } - if (this.date.isBefore(LocalDate.now())) { - throw new Exception("Date specified must be a current or a future date"); + throw new EventStartTimeAfterEndTimeException(); } + parsePriority(priority); } + /** + * Parses the priority from the string entered by user for the priority field. + * + * @param priority String entered by user for the priority field. + * @throws Exception If the provided priority isn't an integer. + */ private void parsePriority(String priority) throws Exception { try { this.priority = Integer.parseInt(priority.strip()); } catch (NumberFormatException e) { - throw new Exception("Priority should be an integer"); + throw new TaskPriorityNotIntegerException(); } } + /** + * Parses the End time from the string entered by user for the endTime field. + * + * @param endTime String entered by user for the endTime field. + * @throws Exception If the provided end time isn't valid. + */ private void parseEndTime(String endTime) throws Exception { try { this.endTime = LocalTime.parse(endTime.strip()); } catch (DateTimeParseException e) { - throw new Exception("End time provided is invalid or in wrong format (Should be HH:MM)"); + throw new InvalidEndTimeException(); } } + /** + * Parses the End time from the string entered by user for the startTime field. + * + * @param startTime String entered by user for the startTime field. + * @throws Exception If the provided start time isn't valid. + */ private void parseStartTime(String startTime) throws Exception { try { this.startTime = LocalTime.parse(startTime.strip()); } catch (DateTimeParseException e) { - throw new Exception("Start time provided is invalid or in wrong format (Should be HH:MM)"); + throw new InvalidStartTimeException(); } } + /** + * Parses the Date from the string entered by user for the date field. + * + * @param date String entered by user for the date field. + * @throws Exception If the provided date isn't valid or is a past date. + */ private void parseDate(String date) throws Exception { try { this.date = LocalDate.parse(date.strip()); } catch (DateTimeParseException e) { - throw new Exception("Date provided is invalid or is in wrong format (Should be YYYY-MM-DD)"); + throw new InvalidDateException(); + } + if (this.date.isBefore(LocalDate.now())) { + throw new TaskDateBeforeCurrentDateException(); } - } + /** + * Parses the description from the string entered by user for the description field. + * + * @param description String entered by user for the description field. + */ private void parseDescription(String description) { this.description = description; } @@ -103,8 +182,8 @@ private void parseDescription(String description) { * @return eventInfo Contains information related to the event. */ public String getTaskInformation() { - String eventInfo = "[E] " + description + " at " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) - + " from " + startTime.toString() + " to " + endTime.toString() + " with priority " + priority; + String eventInfo = EVENT_SYMBOL + description + AT + date.format(DateTimeFormatter.ofPattern(DATE_PATTERN)) + + FROM + startTime.toString() + TO + endTime.toString() + WITH_PRIORITY + priority; return eventInfo; } @@ -144,8 +223,8 @@ public LocalDate getDate() { * @throws Exception If keyword entered is empty. */ public boolean hasKeyword(String keyword) throws Exception { - if (keyword.equals("")) { - throw new Exception("Keyword is empty"); + if (keyword.equals(EMPTY_STRING)) { + throw new SearchKeywordEmptyException(); } boolean containsKeyword = description.contains(keyword); return containsKeyword; @@ -157,8 +236,8 @@ public boolean hasKeyword(String keyword) throws Exception { * @return formattedEventDetails Contains the event details in the required format. */ public String getFormattedDetails() { - String formattedEventDetails = "E#" + description + "#" + date + "#" + startTime + "#" + endTime + "#" - + priority + "\n"; + String formattedEventDetails = EVENT_IDENTIFIER + DELIMITER + description + DELIMITER + date + DELIMITER + + startTime + DELIMITER + endTime + DELIMITER + priority + NEW_LINE_CHARACTER; return formattedEventDetails; } @@ -171,7 +250,7 @@ public String getFormattedDetails() { public Event editEvent(Ui ui) { printOptionsToEdit(ui); int fieldToBeEdited = 0; - fieldToBeEdited = getFieldToBeEdited(ui, false, fieldToBeEdited); + fieldToBeEdited = getFieldToBeEdited(ui); switch (fieldToBeEdited) { case EDIT_DESCRIPTION: editDescription(ui); @@ -196,11 +275,16 @@ public Event editEvent(Ui ui) { return this; } + /** + * Used to edit the priority field of the event. + * + * @param ui Used to interact with the user. + */ private void editPriority(Ui ui) { boolean exceptionEncountered; do { exceptionEncountered = false; - ui.printMessage("Enter new priority:"); + ui.printMessage(ENTER_NEW_PRIORITY_MESSAGE); String newPriorityString = ui.getUserIn(); try { parsePriority(newPriorityString); @@ -211,16 +295,21 @@ private void editPriority(Ui ui) { } while (exceptionEncountered); } + /** + * Used to edit the endTime field of the event. + * + * @param ui Used to interact with the user. + */ private void editEndTime(Ui ui) { boolean exceptionEncountered; do { exceptionEncountered = false; - ui.printMessage("Enter new End Time:"); + ui.printMessage(ENTER_NEW_END_TIME_MESSAGE); String newEndTimeString = ui.getUserIn(); try { parseEndTime(newEndTimeString); if (this.endTime.isBefore(this.startTime)) { - throw new Exception("End time should be after start time"); + throw new EventStartTimeAfterEndTimeException(); } } catch (Exception e) { ui.printMessage(e.getMessage()); @@ -229,11 +318,16 @@ private void editEndTime(Ui ui) { } while (exceptionEncountered); } + /** + * Used to edit the startTime field of the event. + * + * @param ui Used to interact with the user. + */ private void editStartTime(Ui ui) { boolean exceptionEncountered; do { exceptionEncountered = false; - ui.printMessage("Enter new Start Time:"); + ui.printMessage(ENTER_NEW_START_TIME_MESSAGE); String newStartTimeString = ui.getUserIn(); try { parseStartTime(newStartTimeString); @@ -244,16 +338,21 @@ private void editStartTime(Ui ui) { } while (exceptionEncountered); } + /** + * Used to edit the date field of the event. + * + * @param ui Used to interact with the user. + */ private void editDate(Ui ui) { boolean exceptionEncountered; do { exceptionEncountered = false; - ui.printMessage("Enter new Date:"); + ui.printMessage(ENTER_NEW_DATE_MESSAGE); String newDateString = ui.getUserIn(); try { parseDate(newDateString); if (this.date.isBefore(LocalDate.now())) { - throw new Exception("Date specified must be a current or a future date"); + throw new TaskDateBeforeCurrentDateException(); } } catch (Exception e) { ui.printMessage(e.getMessage()); @@ -262,13 +361,26 @@ private void editDate(Ui ui) { } while (exceptionEncountered); } + /** + * Used to edit the description field of the event. + * + * @param ui Used to interact with the user. + */ private void editDescription(Ui ui) { - ui.printMessage("Enter new description:"); + ui.printMessage(ENTER_NEW_DESCRIPTION_MESSAGE); String newDescription = ui.getUserIn(); parseDescription(newDescription); } - private int getFieldToBeEdited(Ui ui, boolean exceptionEncountered, int fieldToBeEdited) { + /** + * Returns an integer denoting the field selected to be edited later. + * + * @param ui Used to interact with the user. + * @return fieldToBeEdited Corresponds to the field to be edited. + */ + private int getFieldToBeEdited(Ui ui) { + int fieldToBeEdited = 0; + boolean exceptionEncountered; do { exceptionEncountered = false; try { @@ -277,29 +389,39 @@ private int getFieldToBeEdited(Ui ui, boolean exceptionEncountered, int fieldToB throw new Exception(); } } catch (Exception exception) { - ui.printMessage("Please enter a valid number"); + ui.printMessage(ENTER_VALID_NUMBER_FROM_LIST_MESSAGE); exceptionEncountered = true; } } while (exceptionEncountered); return fieldToBeEdited; } + /** + * Prints the updated details of the event after an edit command. + * + * @param ui Used to interact with user. + */ private void printUpdatedDetails(Ui ui) { - ui.printMessage("Updated Details:"); + ui.printMessage(UPDATED_DETAILS); ui.printMessage(this.getTaskInformation()); ui.printLine(); } + /** + * Prints the list of fields that could be edited as a list. + * + * @param ui Used to interact with user. + */ private void printOptionsToEdit(Ui ui) { ui.printLine(); - ui.printMessage("The event details are as follows:"); + ui.printMessage(EVENT_DETAILS_AS_FOLLOWS_MESSAGE); ui.printMessage(this.getTaskInformation()); - ui.printMessage("Which field of the event to edit? (Enter Corresponding Number)"); - ui.printMessage("1. Description"); - ui.printMessage("2. Date"); - ui.printMessage("3. Start Time"); - ui.printMessage("4. End Time"); - ui.printMessage("5. Priority"); + ui.printMessage(ENTER_OPTION_MESSAGE); + ui.printMessage(OPTION_TO_EDIT_DESCRIPTION); + ui.printMessage(OPTION_TO_EDIT_DATE); + ui.printMessage(OPTION_TO_EDIT_START_TIME); + ui.printMessage(OPTION_TO_EDIT_END_TIME); + ui.printMessage(OPTION_TO_EDIT_PRIORITY); ui.printEmptyLine(); } } From 7b6f7aea07db652fe2d21adb82a0c071647607ef Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 23:03:19 +0800 Subject: [PATCH 095/435] Refactor code --- src/main/java/command/AddEventCommand.java | 13 ++++++++++++- src/main/java/resourceloader/TaskLoader.java | 10 +++++++--- src/main/java/seedu/duke/Duke.java | 4 ++-- src/test/java/task/event/TaskListTest.java | 2 +- src/test/java/task/event/TaskTest.java | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/command/AddEventCommand.java b/src/main/java/command/AddEventCommand.java index 9e45950cd..555aa7390 100644 --- a/src/main/java/command/AddEventCommand.java +++ b/src/main/java/command/AddEventCommand.java @@ -1,15 +1,22 @@ package command; +import exception.command.EventCreationFormatNotFollowedException; import exception.command.EventDetailsNotProvidedException; import task.Event; import task.TaskList; import ui.Ui; +import java.time.LocalDate; + /** * This command is used to add new events to the Tasklist. */ public class AddEventCommand extends Command { + public static final String START_TIME_AFTER_END_TIME_ERROR_MESSAGE = "Start time after end time exception " + + "not thrown"; + public static final String DATE_BEFORE_CURRENT_DATE_ERROR_MESSAGE = "Past event exception not thrown"; + /** The new event to be added. */ Event newEvent; @@ -25,14 +32,18 @@ public AddEventCommand(String[] eventDetails, boolean isOneWordCommand) throws E if (isOneWordCommand) { throw new EventDetailsNotProvidedException(); } - String[] details = eventDetails[1].split("/"); + if (details.length != 5) { + throw new EventCreationFormatNotFollowedException(); + } String description = details[0]; String date = details[1].substring(2); String startTime = details[2].substring(2); String endTime = details[3].substring(2); String priority = details[4].substring(2); newEvent = new Event(description,date,startTime,endTime,priority); + assert !newEvent.getStartTime().isAfter(newEvent.getEndTime()) : START_TIME_AFTER_END_TIME_ERROR_MESSAGE; + assert !newEvent.getDate().isBefore(LocalDate.now()) : DATE_BEFORE_CURRENT_DATE_ERROR_MESSAGE; } @Override diff --git a/src/main/java/resourceloader/TaskLoader.java b/src/main/java/resourceloader/TaskLoader.java index 50366f718..178d64c3f 100644 --- a/src/main/java/resourceloader/TaskLoader.java +++ b/src/main/java/resourceloader/TaskLoader.java @@ -14,7 +14,7 @@ import java.util.ArrayList; import java.util.Scanner; -import static seedu.duke.Duke.FILE_PATH_STUDYAREAS; +import static seedu.duke.Duke.FILE_PATH_STUDY_AREAS; /** @@ -22,6 +22,9 @@ */ public class TaskLoader { + public static final String INVALID_TASK_TYPE_MESSAGE = "Invalid task type identified when parsing tasks from " + + "taskList.txt"; + /** Location of data file. */ private String filePath; /** Directory of data file. */ @@ -85,7 +88,8 @@ private Task parseTaskDetails(String details) throws Exception { newTask = parseEventDetails(taskDetails); break; default: - // Error handling + assert false : INVALID_TASK_TYPE_MESSAGE; + break; } return newTask; } @@ -134,7 +138,7 @@ private void createNewDataFile() { try { Files.createDirectories(fileDirectory); Files.createFile(Paths.get(filePath)); - Files.createFile(Paths.get(FILE_PATH_STUDYAREAS)); + Files.createFile(Paths.get(FILE_PATH_STUDY_AREAS)); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 53d609344..e980e6b08 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -20,7 +20,7 @@ public class Duke { public static final String FILE_PATH_EVENTS = "library" + File.separator + "taskList.txt"; - public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; + public static final String FILE_PATH_STUDY_AREAS = "library" + File.separator + "locations.txt"; private static TaskLoader taskLoader; protected static StudyAreaLoader studyAreaLoader; private static TaskList taskList = new TaskList(); @@ -36,7 +36,7 @@ public Duke() { parser = new Parser(); taskLoader = new TaskLoader(FILE_PATH_EVENTS); taskList = new TaskList(taskLoader.loadFile()); - studyAreaLoader = new StudyAreaLoader(FILE_PATH_STUDYAREAS); + studyAreaLoader = new StudyAreaLoader(FILE_PATH_STUDY_AREAS); studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); } catch (FileNotFoundException | IllegalStudyAreaException e) { ui.printLine(); diff --git a/src/test/java/task/event/TaskListTest.java b/src/test/java/task/event/TaskListTest.java index 91a7b29c5..87ab16f9c 100644 --- a/src/test/java/task/event/TaskListTest.java +++ b/src/test/java/task/event/TaskListTest.java @@ -37,7 +37,7 @@ void searchEvents_emptySearchKeyword_throwException() { taskList.searchTasks("",ui); fail("Empty string search not identified"); } catch (Exception exception) { - assertEquals("Keyword is empty", exception.getMessage()); + assertEquals("Keyword to be used for search is empty", exception.getMessage()); } } diff --git a/src/test/java/task/event/TaskTest.java b/src/test/java/task/event/TaskTest.java index 5763c8870..dcbe9df58 100644 --- a/src/test/java/task/event/TaskTest.java +++ b/src/test/java/task/event/TaskTest.java @@ -100,7 +100,7 @@ void searchKeyword_emptyKeyword_throwException() throws Exception { "17:00", "1").hasKeyword(""); fail("Empty keyword not detected"); } catch (Exception e) { - assertEquals("Keyword is empty", e.getMessage()); + assertEquals("Keyword to be used for search is empty", e.getMessage()); } } From d75f262ab7624395965c80bef337f4a95f66c634 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 23:28:07 +0800 Subject: [PATCH 096/435] Refactor more code --- .../command/InvalidDueTimeException.java | 9 ++ .../command/InvalidEndTimeException.java | 2 +- .../command/InvalidStartTimeException.java | 2 +- src/main/java/task/Deadline.java | 146 ++++++++++++++---- src/main/java/task/Event.java | 8 +- src/test/java/task/event/TaskTest.java | 6 +- 6 files changed, 138 insertions(+), 35 deletions(-) create mode 100644 src/main/java/exception/command/InvalidDueTimeException.java diff --git a/src/main/java/exception/command/InvalidDueTimeException.java b/src/main/java/exception/command/InvalidDueTimeException.java new file mode 100644 index 000000000..45de58be9 --- /dev/null +++ b/src/main/java/exception/command/InvalidDueTimeException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class InvalidDueTimeException extends CustomException { + public InvalidDueTimeException() { + super("Due time provided is invalid or in wrong format (Should be HH:MM) 24 Hr format"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/InvalidEndTimeException.java b/src/main/java/exception/command/InvalidEndTimeException.java index f46b285a8..234c2f933 100644 --- a/src/main/java/exception/command/InvalidEndTimeException.java +++ b/src/main/java/exception/command/InvalidEndTimeException.java @@ -6,6 +6,6 @@ public class InvalidEndTimeException extends CustomException { public InvalidEndTimeException() { - super("End time provided is invalid or in wrong format (Should be HH:MM)"); + super("End time provided is invalid or in wrong format (Should be HH:MM) 24 Hr format"); } } \ No newline at end of file diff --git a/src/main/java/exception/command/InvalidStartTimeException.java b/src/main/java/exception/command/InvalidStartTimeException.java index 2326cd322..3fffdee3b 100644 --- a/src/main/java/exception/command/InvalidStartTimeException.java +++ b/src/main/java/exception/command/InvalidStartTimeException.java @@ -4,6 +4,6 @@ public class InvalidStartTimeException extends CustomException { public InvalidStartTimeException() { - super("Start time provided is invalid or in wrong format (Should be HH:MM)"); + super("Start time provided is invalid or in wrong format (Should be HH:MM) 24 Hr format"); } } \ No newline at end of file diff --git a/src/main/java/task/Deadline.java b/src/main/java/task/Deadline.java index ab1ae8f53..22ad1e3db 100644 --- a/src/main/java/task/Deadline.java +++ b/src/main/java/task/Deadline.java @@ -1,5 +1,10 @@ package task; +import exception.command.InvalidDateException; +import exception.command.InvalidDueTimeException; +import exception.command.SearchKeywordEmptyException; +import exception.command.TaskDateBeforeCurrentDateException; +import exception.command.TaskPriorityNotIntegerException; import ui.Ui; import java.time.LocalDate; @@ -8,9 +13,22 @@ import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; +import static task.Event.AT; +import static task.Event.DATE_PATTERN; +import static task.Event.DELIMITER; import static task.Event.EDIT_DATE; import static task.Event.EDIT_DESCRIPTION; +import static task.Event.EMPTY_STRING; +import static task.Event.ENTER_NEW_DATE_MESSAGE; +import static task.Event.ENTER_NEW_DESCRIPTION_MESSAGE; +import static task.Event.ENTER_NEW_PRIORITY_MESSAGE; +import static task.Event.ENTER_VALID_NUMBER_FROM_LIST_MESSAGE; import static task.Event.ERROR_MESSAGE; +import static task.Event.NEW_LINE_CHARACTER; +import static task.Event.OPTION_TO_EDIT_DATE; +import static task.Event.OPTION_TO_EDIT_DESCRIPTION; +import static task.Event.UPDATED_DETAILS; +import static task.Event.WITH_PRIORITY; /** * Represents an deadline and contains the related functions. @@ -19,6 +37,15 @@ public class Deadline extends Task { private static final int EDIT_DUE_TIME = 3; public static final int EDIT_PRIORITY = 4; + public static final String DEADLINE_IDENTIFIER = "D"; + public static final String DEADLINE_SYMBOL = "[D] "; + public static final String ON = " on "; + public static final String ENTER_NEW_DUE_TIME_MESSAGE = "Enter new due Time:"; + public static final String DEADLINE_DETAILS_AS_FOLLOWS_MESSAGE = "The deadline details are as follows:"; + public static final String ASK_FOR_OPTION_MESSAGE = "Which field of the deadline to edit? (Enter Corresponding " + + "Number)"; + public static final String OPTION_TO_EDIT_DUE_TIME = "3. Due Time"; + public static final String OPTION_TO_EDIT_PRIORITY = "4. Priority"; private String description; private LocalDate date; private LocalTime dueTime; @@ -48,9 +75,6 @@ public Deadline(String description, String date, String dueTime, String priority parseDate(date); parseDueTime(dueTime); parsePriority(priority); - if (this.date.isBefore(LocalDate.now())) { - throw new Exception("Date specified must be a current or a future date"); - } } @@ -64,31 +88,56 @@ public long numberOfDaysLeft() { return ChronoUnit.DAYS.between(LocalDate.now(),this.date); } + /** + * Parses the priority from the string entered by user for the priority field. + * + * @param priority String entered by user for the priority field. + * @throws Exception If the provided priority isn't an integer. + */ private void parsePriority(String priority) throws Exception { try { this.priority = Integer.parseInt(priority.strip()); } catch (NumberFormatException e) { - throw new Exception("Priority should be an integer"); + throw new TaskPriorityNotIntegerException(); } } + /** + * Parses the Due time from the string entered by user for the dueTime field. + * + * @param dueTime String entered by user for the dueTime field. + * @throws Exception If the provided end time isn't valid. + */ private void parseDueTime(String dueTime) throws Exception { try { this.dueTime = LocalTime.parse(dueTime.strip()); } catch (DateTimeParseException e) { - throw new Exception("Due time provided is invalid or in wrong format (Should be HH:MM)"); + throw new InvalidDueTimeException(); } } + /** + * Parses the Date from the string entered by user for the date field. + * + * @param date String entered by user for the date field. + * @throws Exception If the provided date isn't valid or is a past date. + */ private void parseDate(String date) throws Exception { try { this.date = LocalDate.parse(date.strip()); } catch (DateTimeParseException e) { - throw new Exception("Date provided is invalid or is in wrong format (Should be YYYY-MM-DD)"); + throw new InvalidDateException(); + } + if (this.date.isBefore(LocalDate.now())) { + throw new TaskDateBeforeCurrentDateException(); } - } + /** + * Parses the description from the string entered by user for the description field. + * + * @param description String entered by user for the description field. + */ private void parseDescription(String description) { this.description = description; } @@ -99,8 +148,9 @@ private void parseDescription(String description) { * @return deadlineInfo Contains information related to the deadline. */ public String getTaskInformation() { - String deadlineInfo = "[D] " + description + " on " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) - + " at " + dueTime.toString() + " with priority " + priority; + String deadlineInfo = DEADLINE_SYMBOL + description + ON + + date.format(DateTimeFormatter.ofPattern(DATE_PATTERN)) + AT + dueTime.toString() + + WITH_PRIORITY + priority; return deadlineInfo; } @@ -131,8 +181,8 @@ public LocalDate getDate() { * @throws Exception If no keyword is entered. */ public boolean hasKeyword(String keyword) throws Exception { - if (keyword.equals("")) { - throw new Exception("Keyword is empty"); + if (keyword.equals(EMPTY_STRING)) { + throw new SearchKeywordEmptyException(); } boolean containsKeyword = description.contains(keyword); return containsKeyword; @@ -144,7 +194,8 @@ public boolean hasKeyword(String keyword) throws Exception { * @return formattedDeadlineDetails Contains the deadline details in the required format. */ public String getFormattedDetails() { - String formattedDeadlineDetails = "D#" + description + "#" + date + "#" + dueTime + "#" + priority + "\n"; + String formattedDeadlineDetails = DEADLINE_IDENTIFIER + DELIMITER + description + DELIMITER + date + DELIMITER + + dueTime + DELIMITER + priority + NEW_LINE_CHARACTER; return formattedDeadlineDetails; } @@ -157,7 +208,7 @@ public String getFormattedDetails() { public Deadline editDeadline(Ui ui) { printOptionsToEdit(ui); int fieldToBeEdited = 0; - fieldToBeEdited = getFieldToBeEdited(ui, false, fieldToBeEdited); + fieldToBeEdited = getFieldToBeEdited(ui); switch (fieldToBeEdited) { case EDIT_DESCRIPTION: editDescription(ui); @@ -179,11 +230,16 @@ public Deadline editDeadline(Ui ui) { return this; } + /** + * Used to edit the priority field of the deadline. + * + * @param ui Used to interact with the user. + */ private void editPriority(Ui ui) { boolean exceptionEncountered; do { exceptionEncountered = false; - ui.printMessage("Enter new priority:"); + ui.printMessage(ENTER_NEW_PRIORITY_MESSAGE); String newPriorityString = ui.getUserIn(); try { parsePriority(newPriorityString); @@ -194,11 +250,16 @@ private void editPriority(Ui ui) { } while (exceptionEncountered); } + /** + * Used to edit the dueTime field of the deadline. + * + * @param ui Used to interact with the user. + */ private void editDueTime(Ui ui) { boolean exceptionEncountered; do { exceptionEncountered = false; - ui.printMessage("Enter new due Time:"); + ui.printMessage(ENTER_NEW_DUE_TIME_MESSAGE); String newStartTimeString = ui.getUserIn(); try { parseDueTime(newStartTimeString); @@ -209,16 +270,21 @@ private void editDueTime(Ui ui) { } while (exceptionEncountered); } + /** + * Used to edit the date field of the deadline. + * + * @param ui Used to interact with the user. + */ private void editDate(Ui ui) { boolean exceptionEncountered; do { exceptionEncountered = false; - ui.printMessage("Enter new Date:"); + ui.printMessage(ENTER_NEW_DATE_MESSAGE); String newDateString = ui.getUserIn(); try { parseDate(newDateString); if (this.date.isBefore(LocalDate.now())) { - throw new Exception("Date specified must be a current or a future date"); + throw new TaskDateBeforeCurrentDateException(); } } catch (Exception e) { ui.printMessage(e.getMessage()); @@ -227,43 +293,67 @@ private void editDate(Ui ui) { } while (exceptionEncountered); } + /** + * Used to edit the description field of the deadline. + * + * @param ui Used to interact with the user. + */ private void editDescription(Ui ui) { - ui.printMessage("Enter new description:"); + ui.printMessage(ENTER_NEW_DESCRIPTION_MESSAGE); String newDescription = ui.getUserIn(); parseDescription(newDescription); } - private int getFieldToBeEdited(Ui ui, boolean exceptionEncountered, int fieldToBeEdited) { + /** + * Returns an integer denoting the field selected to be edited later. + * + * @param ui Used to interact with the user. + * @return fieldToBeEdited Corresponds to the field to be edited. + */ + private int getFieldToBeEdited(Ui ui) { + boolean exceptionEncountered; + int fieldToBeEdited = 0; do { exceptionEncountered = false; try { fieldToBeEdited = Integer.parseInt(ui.getUserIn()); - if (fieldToBeEdited > 4 || fieldToBeEdited < 0) { + boolean isInvalidOption = fieldToBeEdited > 4 || fieldToBeEdited < 0; + if (isInvalidOption) { throw new Exception(); } } catch (Exception exception) { - ui.printMessage("Please enter a valid number"); + ui.printMessage(ENTER_VALID_NUMBER_FROM_LIST_MESSAGE); exceptionEncountered = true; } } while (exceptionEncountered); return fieldToBeEdited; } + /** + * Prints the updated details of the deadline after an edit command. + * + * @param ui Used to interact with user. + */ private void printUpdatedDetails(Ui ui) { - ui.printMessage("Updated Details:"); + ui.printMessage(UPDATED_DETAILS); ui.printMessage(this.getTaskInformation()); ui.printLine(); } + /** + * Prints the list of fields that could be edited as a list. + * + * @param ui Used to interact with user. + */ private void printOptionsToEdit(Ui ui) { ui.printLine(); - ui.printMessage("The deadline details are as follows:"); + ui.printMessage(DEADLINE_DETAILS_AS_FOLLOWS_MESSAGE); ui.printMessage(this.getTaskInformation()); - ui.printMessage("Which field of the event to edit? (Enter Corresponding Number)"); - ui.printMessage("1. Description"); - ui.printMessage("2. Date"); - ui.printMessage("3. Due Time"); - ui.printMessage("4. Priority"); + ui.printMessage(ASK_FOR_OPTION_MESSAGE); + ui.printMessage(OPTION_TO_EDIT_DESCRIPTION); + ui.printMessage(OPTION_TO_EDIT_DATE); + ui.printMessage(OPTION_TO_EDIT_DUE_TIME); + ui.printMessage(OPTION_TO_EDIT_PRIORITY); ui.printEmptyLine(); } } \ No newline at end of file diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java index d55742839..d374c189d 100644 --- a/src/main/java/task/Event.java +++ b/src/main/java/task/Event.java @@ -44,7 +44,8 @@ public class Event extends Task { public static final String ENTER_VALID_NUMBER_FROM_LIST_MESSAGE = "Please enter a valid number from the list"; public static final String UPDATED_DETAILS = "Updated Details:"; public static final String EVENT_DETAILS_AS_FOLLOWS_MESSAGE = "The event details are as follows:"; - public static final String ENTER_OPTION_MESSAGE = "Which field of the event to edit? (Enter Corresponding Number)"; + public static final String ASK_FOR_OPTION_MESSAGE = "Which field of the event to edit?" + + " (Enter Corresponding Number)"; public static final String OPTION_TO_EDIT_DESCRIPTION = "1. Description"; public static final String OPTION_TO_EDIT_DATE = "2. Date"; public static final String OPTION_TO_EDIT_START_TIME = "3. Start Time"; @@ -385,7 +386,8 @@ private int getFieldToBeEdited(Ui ui) { exceptionEncountered = false; try { fieldToBeEdited = Integer.parseInt(ui.getUserIn()); - if (fieldToBeEdited > 5 || fieldToBeEdited < 0) { + boolean isInvalidOption = fieldToBeEdited > 5 || fieldToBeEdited < 0; + if (isInvalidOption) { throw new Exception(); } } catch (Exception exception) { @@ -416,7 +418,7 @@ private void printOptionsToEdit(Ui ui) { ui.printLine(); ui.printMessage(EVENT_DETAILS_AS_FOLLOWS_MESSAGE); ui.printMessage(this.getTaskInformation()); - ui.printMessage(ENTER_OPTION_MESSAGE); + ui.printMessage(ASK_FOR_OPTION_MESSAGE); ui.printMessage(OPTION_TO_EDIT_DESCRIPTION); ui.printMessage(OPTION_TO_EDIT_DATE); ui.printMessage(OPTION_TO_EDIT_START_TIME); diff --git a/src/test/java/task/event/TaskTest.java b/src/test/java/task/event/TaskTest.java index dcbe9df58..3924e3c17 100644 --- a/src/test/java/task/event/TaskTest.java +++ b/src/test/java/task/event/TaskTest.java @@ -45,7 +45,8 @@ void createEvent_invalidStartTime_throwException() { "17:00", "1"); fail("Invalid start time not rejected"); } catch (Exception e) { - assertEquals("Start time provided is invalid or in wrong format (Should be HH:MM)",e.getMessage()); + assertEquals("Start time provided is invalid or in wrong format (Should be HH:MM) 24 Hr format", + e.getMessage()); } } @@ -56,7 +57,8 @@ void createEvent_invalidEndTime_throwException() { "10:70", "1"); fail("Invalid end time not rejected"); } catch (Exception e) { - assertEquals("End time provided is invalid or in wrong format (Should be HH:MM)",e.getMessage()); + assertEquals("End time provided is invalid or in wrong format (Should be HH:MM) 24 Hr format", + e.getMessage()); } } From 95ed33398771c5812abeea142ab6ceff2f569911 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 23:39:44 +0800 Subject: [PATCH 097/435] Add new exception class for help command --- src/main/java/command/HelpCommand.java | 3 ++- .../exception/command/InvalidHelpCommandException.java | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/main/java/exception/command/InvalidHelpCommandException.java diff --git a/src/main/java/command/HelpCommand.java b/src/main/java/command/HelpCommand.java index 88396124c..18624ff10 100644 --- a/src/main/java/command/HelpCommand.java +++ b/src/main/java/command/HelpCommand.java @@ -1,5 +1,6 @@ package command; +import exception.command.InvalidHelpCommandException; import task.TaskList; import ui.Ui; @@ -17,7 +18,7 @@ public class HelpCommand extends Command { */ public HelpCommand(boolean isOneWordCommand) throws Exception { if (!isOneWordCommand) { - throw new Exception("Wrong command used to view command list (Should be :help )"); + throw new InvalidHelpCommandException(); } } diff --git a/src/main/java/exception/command/InvalidHelpCommandException.java b/src/main/java/exception/command/InvalidHelpCommandException.java new file mode 100644 index 000000000..6b3f3a7ed --- /dev/null +++ b/src/main/java/exception/command/InvalidHelpCommandException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class InvalidHelpCommandException extends CustomException { + public InvalidHelpCommandException() { + super("Wrong command used to view command list (Should be :help )"); + } +} \ No newline at end of file From 9e9e59f177bf36f461e2467b0fa45e21daa6cc36 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 23:40:03 +0800 Subject: [PATCH 098/435] Refactor code --- src/main/java/command/AddDeadlineCommand.java | 9 ++++++++- src/main/java/command/AddEventCommand.java | 5 +++-- src/main/java/task/Event.java | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/command/AddDeadlineCommand.java b/src/main/java/command/AddDeadlineCommand.java index 0a303e924..6f4ecf072 100644 --- a/src/main/java/command/AddDeadlineCommand.java +++ b/src/main/java/command/AddDeadlineCommand.java @@ -6,11 +6,17 @@ import task.TaskList; import ui.Ui; +import java.time.LocalDate; + +import static command.AddEventCommand.DATE_BEFORE_CURRENT_DATE_ERROR_MESSAGE; + /** * This command is used to add new deadlines to the Tasklist. */ public class AddDeadlineCommand extends Command { + public static final String SLASH_SYMBOL = "/"; + /** The new event to be added. */ Deadline newDeadline; @@ -26,7 +32,7 @@ public AddDeadlineCommand(String[] deadlineDetails, boolean isOneWordCommand) th if (isOneWordCommand) { throw new EventDetailsNotProvidedException(); } - String[] details = deadlineDetails[1].split("/"); + String[] details = deadlineDetails[1].split(SLASH_SYMBOL); if (details.length != 4) { throw new DeadlineCreationFormatNotFollowedException(); } @@ -35,6 +41,7 @@ public AddDeadlineCommand(String[] deadlineDetails, boolean isOneWordCommand) th String dueTime = details[2].substring(2); String priority = details[3].substring(2); newDeadline = new Deadline(description, date, dueTime, priority); + assert !newDeadline.getDate().isBefore(LocalDate.now()) : DATE_BEFORE_CURRENT_DATE_ERROR_MESSAGE; } @Override diff --git a/src/main/java/command/AddEventCommand.java b/src/main/java/command/AddEventCommand.java index 555aa7390..3901c6e47 100644 --- a/src/main/java/command/AddEventCommand.java +++ b/src/main/java/command/AddEventCommand.java @@ -15,7 +15,8 @@ public class AddEventCommand extends Command { public static final String START_TIME_AFTER_END_TIME_ERROR_MESSAGE = "Start time after end time exception " + "not thrown"; - public static final String DATE_BEFORE_CURRENT_DATE_ERROR_MESSAGE = "Past event exception not thrown"; + public static final String DATE_BEFORE_CURRENT_DATE_ERROR_MESSAGE = "Date past current day exception not thrown"; + public static final String SLASH_SYMBOL = "/"; /** The new event to be added. */ Event newEvent; @@ -32,7 +33,7 @@ public AddEventCommand(String[] eventDetails, boolean isOneWordCommand) throws E if (isOneWordCommand) { throw new EventDetailsNotProvidedException(); } - String[] details = eventDetails[1].split("/"); + String[] details = eventDetails[1].split(SLASH_SYMBOL); if (details.length != 5) { throw new EventCreationFormatNotFollowedException(); } diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java index d374c189d..8fdd3ef9f 100644 --- a/src/main/java/task/Event.java +++ b/src/main/java/task/Event.java @@ -332,6 +332,9 @@ private void editStartTime(Ui ui) { String newStartTimeString = ui.getUserIn(); try { parseStartTime(newStartTimeString); + if (this.endTime.isBefore(this.startTime)) { + throw new EventStartTimeAfterEndTimeException(); + } } catch (Exception e) { ui.printMessage(e.getMessage()); exceptionEncountered = true; From 6fe654ff8ada900975928e996705e07d408a2992 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 14 Mar 2020 23:50:05 +0800 Subject: [PATCH 099/435] Update EXPECTED.TXT --- text-ui-test/EXPECTED.TXT | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 7147ee072..e0e323794 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -88,7 +88,9 @@ ________________________________________________________________________________ deleted ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ - Index 1 out of bounds for length 1 + Please follow the correct format to add a new event + event /d /s /e /p ________________________________________________________________________________________________________ ________________________________________________________________________________________________________ Enter a valid integer index (1-based) to delete/edit @@ -114,8 +116,8 @@ ________________________________________________________________________________ 4. End Time 5. Priority - Please enter a valid number - Please enter a valid number + Please enter a valid number from the list + Please enter a valid number from the list Enter new description: Updated Details: [E] team meeting at May 5 2020 from 12:00 to 13:00 with From 456a5cd8a1afaae5172a0fa05e022916a0db66c6 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 00:03:21 +0800 Subject: [PATCH 100/435] Add JavaDoc Comments --- src/main/java/task/TaskList.java | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/task/TaskList.java b/src/main/java/task/TaskList.java index a26c2290f..53f4f15a4 100644 --- a/src/main/java/task/TaskList.java +++ b/src/main/java/task/TaskList.java @@ -162,7 +162,7 @@ public void clearTasks(Ui ui) { } /** - * Lists all the tasks sorted by their priority. + * Lists all the tasks sorted by their priority by calling a helper function. * * @param ui This allows TaskList class to interact with User. */ @@ -179,6 +179,12 @@ public void priorityView(Ui ui) { ui.printLine(); } + /** + * Prints the tasks sorted by their priority. + * + * @param ui This allows TaskList class to interact with User. + * @param tasksSortedByPriority The sorted list of tasks. + */ private void printTasksSortedByPriority(Ui ui, ArrayList tasksSortedByPriority) { int taskNumber = 1; ui.printMessage("Here is the list of tasks added so far displayed in decreasing order of priority:"); @@ -189,7 +195,7 @@ private void printTasksSortedByPriority(Ui ui, ArrayList tasksSortedByPrio } /** - * Lists all the tasks sorted by date along with the days remaining. + * Lists all the tasks sorted by date along with the days remaining by calling a helper function. * * @param ui This allows TaskList class to interact with User. */ @@ -205,6 +211,12 @@ public void countdownView(Ui ui) { ui.printLine(); } + /** + * Prints the tasks sorted by date along with the days remaining. + * + * @param ui This allows TaskList class to interact with User. + * @param tasksSortedByDate The sorted list of tasks. + */ private void printTasksSortedByDate(Ui ui, ArrayList tasksSortedByDate) { int taskNumber = 1; ui.printMessage("Here is the list of tasks with sorted based on the number of days left:"); @@ -234,6 +246,13 @@ public void searchTasks(String keyword, Ui ui) throws Exception { ui.printLine(); } + /** + * Used to check if there is at least one task containing the keyword in it's description. + * + * @param keyword The word used for search. + * @return true if at least one task has a description containing the keyword and false otherwise + * @throws Exception If keyword used is empty. + */ private boolean checkForMatchedTasks(String keyword) throws Exception { boolean hasMatchedTask = false; for (Task task : tasks) { @@ -245,6 +264,13 @@ private boolean checkForMatchedTasks(String keyword) throws Exception { return hasMatchedTask; } + /** + * Displays the list of tasks containing the keyword in their descriptions. + * + * @param keyword The word used for search. + * @param ui Used to interact with the user. + * @throws Exception If the keyword is empty. + */ private void printMatchedTasks(String keyword, Ui ui) throws Exception { int taskNumber = 1; for (Task task : tasks) { From 6ef86db34c00b10857955947f874dc509bcc00a3 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 00:58:24 +0800 Subject: [PATCH 101/435] Change text-ui-test files --- text-ui-test/EXPECTED.TXT | 16 ---------------- text-ui-test/input.txt | 2 -- 2 files changed, 18 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index e0e323794..8b3ddfdef 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -167,14 +167,6 @@ ________________________________________________________________________________ ________________________________________________________________________________________________________ Invalid command entered, Please enter a valid command ________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Here is the list of tasks with sorted based on the - number of days left: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 ---> 49 day(s) left - 2) [E] team meeting at Jun 6 2020 from 12:00 to 13:00 - with priority 1 ---> 84 day(s) left -________________________________________________________________________________________________________ ________________________________________________________________________________________________________ Exiting task interface ________________________________________________________________________________________________________ @@ -207,14 +199,6 @@ ________________________________________________________________________________ Wrong command used to view countdown of events (Should be :countdown ) ________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Here is the list of tasks with sorted based on the - number of days left: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 ---> 49 day(s) left - 2) [E] team meeting at Jun 6 2020 from 12:00 to 13:00 - with priority 1 ---> 84 day(s) left -________________________________________________________________________________________________________ ________________________________________________________________________________________________________ Exiting task interface ________________________________________________________________________________________________________ diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 61ad4cd64..60ded882a 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -27,10 +27,8 @@ edit 2 event view list task -countdown bye task countdown view -countdown bye bye \ No newline at end of file From 614300b755f88b71a4f434d92909323acef397f2 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 00:59:12 +0800 Subject: [PATCH 102/435] Add logging for Duke class --- dukeLogger.log | 10 +++++++ src/main/java/seedu/duke/Duke.java | 43 ++++++++++++++++++++++++++++++ text-ui-test/dukeLogger.log | 10 +++++++ 3 files changed, 63 insertions(+) create mode 100644 dukeLogger.log create mode 100644 text-ui-test/dukeLogger.log diff --git a/dukeLogger.log b/dukeLogger.log new file mode 100644 index 000000000..6039571c0 --- /dev/null +++ b/dukeLogger.log @@ -0,0 +1,10 @@ +Mar 15, 2020 12:50:44 AM seedu.duke.Duke run +INFO: Application started Execution +Mar 15, 2020 12:50:56 AM seedu.duke.Duke run +INFO: Application transitioning to task mode +Mar 15, 2020 12:51:01 AM seedu.duke.Duke run +INFO: Application transitioning to study area mode +Mar 15, 2020 12:51:05 AM seedu.duke.Duke run +INFO: Application is going to exit +Mar 15, 2020 12:51:05 AM seedu.duke.Duke run +INFO: Application closed successfully diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index e980e6b08..e5d63b3aa 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -12,6 +12,13 @@ import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.logging.ConsoleHandler; +import java.util.logging.FileHandler; +import java.util.logging.Level; +import java.util.logging.LogManager; +import java.util.logging.Logger; +import java.util.logging.SimpleFormatter; /** @@ -21,51 +28,86 @@ public class Duke { public static final String FILE_PATH_EVENTS = "library" + File.separator + "taskList.txt"; public static final String FILE_PATH_STUDY_AREAS = "library" + File.separator + "locations.txt"; + public static final String EXCEPTION_ENCOUNTERED_MESSAGE = "Exception encountered when Duke was constructed"; + public static final String DUKE_LOGGER_LOG = "dukeLogger.log"; + public static final String FILE_LOGGER_NOT_WORKING_MESSAGE = "File Logger not working"; + public static final String APPLICATION_STARTED_EXECUTION = "Application started Execution"; + public static final String APPLICATION_GOING_TO_EXIT = "Application is going to exit"; + public static final String TASK_MODE = "Application transitioning to task mode"; + public static final String STUDY_AREA_MODE = "Application transitioning to study area mode"; + public static final String WRONG_COMMAND = "Wrong command entered by user"; + public static final String APPLICATION_CLOSED_SUCCESSFULLY = "Application closed successfully"; + private static TaskLoader taskLoader; protected static StudyAreaLoader studyAreaLoader; private static TaskList taskList = new TaskList(); private static StudyAreaList studyAreaList; private static Ui ui = new Ui(); private static Parser parser; + private final static Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); /** * This is the constructor to create a new Duke program every time user runs the main loop. */ public Duke() { try { + setupLogger(); parser = new Parser(); taskLoader = new TaskLoader(FILE_PATH_EVENTS); taskList = new TaskList(taskLoader.loadFile()); studyAreaLoader = new StudyAreaLoader(FILE_PATH_STUDY_AREAS); studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); } catch (FileNotFoundException | IllegalStudyAreaException e) { + LOGGER.log(Level.SEVERE, EXCEPTION_ENCOUNTERED_MESSAGE, e); ui.printLine(); ui.printMessage(e.getMessage()); ui.printLine(); } } + private void setupLogger() { + LogManager.getLogManager().reset(); + LOGGER.setLevel(Level.INFO); + ConsoleHandler ch = new ConsoleHandler(); + ch.setLevel(Level.SEVERE); + ch.setFormatter(new SimpleFormatter()); + LOGGER.addHandler(ch); + try { + FileHandler fh = new FileHandler(DUKE_LOGGER_LOG); + fh.setLevel(Level.INFO); + fh.setFormatter(new SimpleFormatter()); + LOGGER.addHandler(fh); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, FILE_LOGGER_NOT_WORKING_MESSAGE, e); + } + } + /** * This method runs the program. */ public void run() { + LOGGER.log(Level.INFO, APPLICATION_STARTED_EXECUTION); ui.printWelcomeMessage(); boolean status = true; while (status) { int mode = ui.getMode(); switch (mode) { case -1: + LOGGER.log(Level.INFO, APPLICATION_GOING_TO_EXIT); status = false; break; case 1: + LOGGER.log(Level.INFO, TASK_MODE); TaskCommand.runCommands(taskList, ui, parser); ui.printMessage(Ui.INTERMEDIATE_MESSAGE); break; case 2: + LOGGER.log(Level.INFO, STUDY_AREA_MODE); StudyAreaCommand.runCommands(studyAreaList, ui); ui.printMessage(Ui.INTERMEDIATE_MESSAGE); break; default: + LOGGER.log(Level.INFO, WRONG_COMMAND); ui.printLine(); ui.printMessage(Ui.WRONG_INPUT); break; @@ -75,6 +117,7 @@ public void run() { taskLoader.saveTasks(taskList.tasks); ui.printMessage(Ui.GOODBYE_MESSAGE + Ui.DAB); ui.close(); + LOGGER.log(Level.INFO, APPLICATION_CLOSED_SUCCESSFULLY); } /** diff --git a/text-ui-test/dukeLogger.log b/text-ui-test/dukeLogger.log new file mode 100644 index 000000000..e51e107f7 --- /dev/null +++ b/text-ui-test/dukeLogger.log @@ -0,0 +1,10 @@ +Mar 15, 2020 12:57:31 AM seedu.duke.Duke run +INFO: Application started Execution +Mar 15, 2020 12:57:31 AM seedu.duke.Duke run +INFO: Application transitioning to task mode +Mar 15, 2020 12:57:32 AM seedu.duke.Duke run +INFO: Application transitioning to task mode +Mar 15, 2020 12:57:32 AM seedu.duke.Duke run +INFO: Application is going to exit +Mar 15, 2020 12:57:32 AM seedu.duke.Duke run +INFO: Application closed successfully From a615f45261be3973acce90af245e21ff844202ca Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 01:00:57 +0800 Subject: [PATCH 103/435] Rectify issue --- src/main/java/seedu/duke/Duke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index e5d63b3aa..f1fc827b3 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -44,7 +44,7 @@ public class Duke { private static StudyAreaList studyAreaList; private static Ui ui = new Ui(); private static Parser parser; - private final static Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); /** * This is the constructor to create a new Duke program every time user runs the main loop. From 8715abe9a056c7459b2665366428ef16a0277b85 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 01:21:08 +0800 Subject: [PATCH 104/435] Add Logging for Event Class --- src/main/java/task/Event.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java index 8fdd3ef9f..dbd39c1c5 100644 --- a/src/main/java/task/Event.java +++ b/src/main/java/task/Event.java @@ -14,6 +14,8 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Represents an event and contains the related functions. @@ -51,12 +53,26 @@ public class Event extends Task { public static final String OPTION_TO_EDIT_START_TIME = "3. Start Time"; public static final String OPTION_TO_EDIT_END_TIME = "4. End Time"; public static final String OPTION_TO_EDIT_PRIORITY = "5. Priority"; + public static final String START_TIME_AFTER_END_TIME = "Event start time after end time exception thrown"; + public static final String PRIORITY_NOT_INTEGER = "Task priority not integer exception thrown"; + public static final String INVALID_END_TIME = "Invalid end time exception thrown"; + public static final String INVALID_START_TIME = "Invalid start time exception thrown"; + public static final String INVALID_DATE = "Invalid date exception thrown"; + public static final String DATE_AFTER_CURRENT_DATE = "Date after current date exception thrown"; + public static final String SEARCH_KEYWORD_EMPTY = "Search keyword empty exception thrown"; + public static final String WRONG_OPTION = "Wrong option entered not handled by getFieldToBeEdited"; + public static final String INVALID_PRIORITY_VALUE = "Invalid priority value entered by user"; + public static final String INVALID_END_TIME_ENTERED = "Invalid end time entered by the user"; + public static final String INVALID_START_TIME_ENTERED = "Invalid start time entered by user"; + public static final String INVALID_DATE_ENTERED = "Invalid date entered by user"; + public static final String INVALID_OPTION_ENTERED = "Invalid option entered by user"; private String description; private LocalDate date; private LocalTime startTime; private LocalTime endTime; private int priority; + private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); /** * Setter for priority of the deadline. @@ -104,6 +120,7 @@ public Event(String description, String date, String startTime, String endTime, parseStartTime(startTime); parseEndTime(endTime); if (this.startTime.isAfter(this.endTime)) { + LOGGER.log(Level.INFO, START_TIME_AFTER_END_TIME); throw new EventStartTimeAfterEndTimeException(); } parsePriority(priority); @@ -119,6 +136,7 @@ private void parsePriority(String priority) throws Exception { try { this.priority = Integer.parseInt(priority.strip()); } catch (NumberFormatException e) { + LOGGER.log(Level.INFO, PRIORITY_NOT_INTEGER); throw new TaskPriorityNotIntegerException(); } } @@ -133,6 +151,7 @@ private void parseEndTime(String endTime) throws Exception { try { this.endTime = LocalTime.parse(endTime.strip()); } catch (DateTimeParseException e) { + LOGGER.log(Level.INFO, INVALID_END_TIME); throw new InvalidEndTimeException(); } } @@ -147,6 +166,7 @@ private void parseStartTime(String startTime) throws Exception { try { this.startTime = LocalTime.parse(startTime.strip()); } catch (DateTimeParseException e) { + LOGGER.log(Level.INFO, INVALID_START_TIME); throw new InvalidStartTimeException(); } } @@ -161,9 +181,11 @@ private void parseDate(String date) throws Exception { try { this.date = LocalDate.parse(date.strip()); } catch (DateTimeParseException e) { + LOGGER.log(Level.INFO, INVALID_DATE); throw new InvalidDateException(); } if (this.date.isBefore(LocalDate.now())) { + LOGGER.log(Level.INFO, DATE_AFTER_CURRENT_DATE); throw new TaskDateBeforeCurrentDateException(); } } @@ -225,6 +247,7 @@ public LocalDate getDate() { */ public boolean hasKeyword(String keyword) throws Exception { if (keyword.equals(EMPTY_STRING)) { + LOGGER.log(Level.INFO, SEARCH_KEYWORD_EMPTY); throw new SearchKeywordEmptyException(); } boolean containsKeyword = description.contains(keyword); @@ -269,6 +292,7 @@ public Event editEvent(Ui ui) { editPriority(ui); break; default: + LOGGER.log(Level.SEVERE, WRONG_OPTION); ui.printMessage(ERROR_MESSAGE); break; } @@ -290,6 +314,7 @@ private void editPriority(Ui ui) { try { parsePriority(newPriorityString); } catch (Exception e) { + LOGGER.log(Level.INFO, INVALID_PRIORITY_VALUE); ui.printMessage(e.getMessage()); exceptionEncountered = true; } @@ -310,9 +335,11 @@ private void editEndTime(Ui ui) { try { parseEndTime(newEndTimeString); if (this.endTime.isBefore(this.startTime)) { + LOGGER.log(Level.INFO, START_TIME_AFTER_END_TIME); throw new EventStartTimeAfterEndTimeException(); } } catch (Exception e) { + LOGGER.log(Level.INFO, INVALID_END_TIME_ENTERED); ui.printMessage(e.getMessage()); exceptionEncountered = true; } @@ -333,9 +360,11 @@ private void editStartTime(Ui ui) { try { parseStartTime(newStartTimeString); if (this.endTime.isBefore(this.startTime)) { + LOGGER.log(Level.INFO, START_TIME_AFTER_END_TIME); throw new EventStartTimeAfterEndTimeException(); } } catch (Exception e) { + LOGGER.log(Level.INFO, INVALID_START_TIME_ENTERED); ui.printMessage(e.getMessage()); exceptionEncountered = true; } @@ -356,9 +385,11 @@ private void editDate(Ui ui) { try { parseDate(newDateString); if (this.date.isBefore(LocalDate.now())) { + LOGGER.log(Level.INFO, DATE_AFTER_CURRENT_DATE); throw new TaskDateBeforeCurrentDateException(); } } catch (Exception e) { + LOGGER.log(Level.INFO, INVALID_DATE_ENTERED); ui.printMessage(e.getMessage()); exceptionEncountered = true; } @@ -394,6 +425,7 @@ private int getFieldToBeEdited(Ui ui) { throw new Exception(); } } catch (Exception exception) { + LOGGER.log(Level.INFO, INVALID_OPTION_ENTERED); ui.printMessage(ENTER_VALID_NUMBER_FROM_LIST_MESSAGE); exceptionEncountered = true; } From f92a429137b1748dca3f50cc0f46e3ec8b286e98 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 01:40:53 +0800 Subject: [PATCH 105/435] Add Logging for Deadline Class --- src/main/java/task/Deadline.java | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/task/Deadline.java b/src/main/java/task/Deadline.java index 22ad1e3db..ceb14df79 100644 --- a/src/main/java/task/Deadline.java +++ b/src/main/java/task/Deadline.java @@ -12,8 +12,11 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; +import java.util.logging.Level; +import java.util.logging.Logger; import static task.Event.AT; +import static task.Event.DATE_AFTER_CURRENT_DATE; import static task.Event.DATE_PATTERN; import static task.Event.DELIMITER; import static task.Event.EDIT_DATE; @@ -24,11 +27,19 @@ import static task.Event.ENTER_NEW_PRIORITY_MESSAGE; import static task.Event.ENTER_VALID_NUMBER_FROM_LIST_MESSAGE; import static task.Event.ERROR_MESSAGE; +import static task.Event.INVALID_DATE; +import static task.Event.INVALID_DATE_ENTERED; +import static task.Event.INVALID_OPTION_ENTERED; +import static task.Event.INVALID_PRIORITY_VALUE; import static task.Event.NEW_LINE_CHARACTER; import static task.Event.OPTION_TO_EDIT_DATE; import static task.Event.OPTION_TO_EDIT_DESCRIPTION; +import static task.Event.PRIORITY_NOT_INTEGER; +import static task.Event.SEARCH_KEYWORD_EMPTY; import static task.Event.UPDATED_DETAILS; import static task.Event.WITH_PRIORITY; +import static task.Event.WRONG_OPTION; + /** * Represents an deadline and contains the related functions. @@ -46,10 +57,13 @@ public class Deadline extends Task { + "Number)"; public static final String OPTION_TO_EDIT_DUE_TIME = "3. Due Time"; public static final String OPTION_TO_EDIT_PRIORITY = "4. Priority"; + private static final String INVALID_DUE_TIME = "Invalid due time entered by user"; + private static final String INVALID_DUE_TIME_ENTERED = "Invalid due time entered by the user"; private String description; private LocalDate date; private LocalTime dueTime; private int priority; + private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); /** * Setter for priority of the deadline. @@ -98,6 +112,7 @@ private void parsePriority(String priority) throws Exception { try { this.priority = Integer.parseInt(priority.strip()); } catch (NumberFormatException e) { + LOGGER.log(Level.INFO, PRIORITY_NOT_INTEGER); throw new TaskPriorityNotIntegerException(); } } @@ -112,6 +127,7 @@ private void parseDueTime(String dueTime) throws Exception { try { this.dueTime = LocalTime.parse(dueTime.strip()); } catch (DateTimeParseException e) { + LOGGER.log(Level.INFO, INVALID_DUE_TIME); throw new InvalidDueTimeException(); } } @@ -126,9 +142,11 @@ private void parseDate(String date) throws Exception { try { this.date = LocalDate.parse(date.strip()); } catch (DateTimeParseException e) { + LOGGER.log(Level.INFO, INVALID_DATE); throw new InvalidDateException(); } if (this.date.isBefore(LocalDate.now())) { + LOGGER.log(Level.INFO, DATE_AFTER_CURRENT_DATE); throw new TaskDateBeforeCurrentDateException(); } } @@ -182,6 +200,7 @@ public LocalDate getDate() { */ public boolean hasKeyword(String keyword) throws Exception { if (keyword.equals(EMPTY_STRING)) { + LOGGER.log(Level.INFO, SEARCH_KEYWORD_EMPTY); throw new SearchKeywordEmptyException(); } boolean containsKeyword = description.contains(keyword); @@ -207,7 +226,7 @@ public String getFormattedDetails() { */ public Deadline editDeadline(Ui ui) { printOptionsToEdit(ui); - int fieldToBeEdited = 0; + int fieldToBeEdited; fieldToBeEdited = getFieldToBeEdited(ui); switch (fieldToBeEdited) { case EDIT_DESCRIPTION: @@ -223,6 +242,7 @@ public Deadline editDeadline(Ui ui) { editPriority(ui); break; default: + LOGGER.log(Level.SEVERE, WRONG_OPTION); ui.printMessage(ERROR_MESSAGE); break; } @@ -244,6 +264,7 @@ private void editPriority(Ui ui) { try { parsePriority(newPriorityString); } catch (Exception e) { + LOGGER.log(Level.INFO, INVALID_PRIORITY_VALUE); ui.printMessage(e.getMessage()); exceptionEncountered = true; } @@ -264,6 +285,7 @@ private void editDueTime(Ui ui) { try { parseDueTime(newStartTimeString); } catch (Exception e) { + LOGGER.log(Level.INFO, INVALID_DUE_TIME_ENTERED); ui.printMessage(e.getMessage()); exceptionEncountered = true; } @@ -284,9 +306,11 @@ private void editDate(Ui ui) { try { parseDate(newDateString); if (this.date.isBefore(LocalDate.now())) { + LOGGER.log(Level.INFO, DATE_AFTER_CURRENT_DATE); throw new TaskDateBeforeCurrentDateException(); } } catch (Exception e) { + LOGGER.log(Level.INFO, INVALID_DATE_ENTERED); ui.printMessage(e.getMessage()); exceptionEncountered = true; } @@ -322,6 +346,7 @@ private int getFieldToBeEdited(Ui ui) { throw new Exception(); } } catch (Exception exception) { + LOGGER.log(Level.INFO, INVALID_OPTION_ENTERED); ui.printMessage(ENTER_VALID_NUMBER_FROM_LIST_MESSAGE); exceptionEncountered = true; } From af18a1a0ce9030d35e748a6b66adc8f6c87aa1f5 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 01:41:14 +0800 Subject: [PATCH 106/435] Refactor code --- src/main/java/task/Event.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java index dbd39c1c5..ab41b358a 100644 --- a/src/main/java/task/Event.java +++ b/src/main/java/task/Event.java @@ -273,7 +273,7 @@ public String getFormattedDetails() { */ public Event editEvent(Ui ui) { printOptionsToEdit(ui); - int fieldToBeEdited = 0; + int fieldToBeEdited; fieldToBeEdited = getFieldToBeEdited(ui); switch (fieldToBeEdited) { case EDIT_DESCRIPTION: From 31ddb97f5986daa423a585c66c2869939ab0d64e Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 01:41:44 +0800 Subject: [PATCH 107/435] Update text-ui-test files --- text-ui-test/EXPECTED.TXT | 20 ++++++++++++++++++++ text-ui-test/dukeLogger.log | 20 +++++++++++++++----- text-ui-test/input.txt | 4 ++++ text-ui-test/library/taskList.txt | 2 +- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 8b3ddfdef..c2a573af3 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -158,6 +158,26 @@ ________________________________________________________________________________ The task at the mentioned index has been edited successfully ________________________________________________________________________________________________________ +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + The deadline details are as follows: + [D] assignment on May 2 2020 at 14:00 with priority 2 + Which field of the deadline to edit? (Enter + Corresponding Number) + 1. Description + 2. Date + 3. Due Time + 4. Priority + + Please enter a valid number from the list + Enter new description: + Updated Details: + [D] assignment on May 2 2020 at 14:00 with priority 2 +________________________________________________________________________________________________________ +________________________________________________________________________________________________________ + The task at the mentioned index has been edited + successfully +________________________________________________________________________________________________________ ________________________________________________________________________________________________________ Event details are not provided ________________________________________________________________________________________________________ diff --git a/text-ui-test/dukeLogger.log b/text-ui-test/dukeLogger.log index e51e107f7..1c8c54b65 100644 --- a/text-ui-test/dukeLogger.log +++ b/text-ui-test/dukeLogger.log @@ -1,10 +1,20 @@ -Mar 15, 2020 12:57:31 AM seedu.duke.Duke run +Mar 15, 2020 1:39:19 AM seedu.duke.Duke run INFO: Application started Execution -Mar 15, 2020 12:57:31 AM seedu.duke.Duke run +Mar 15, 2020 1:39:19 AM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 12:57:32 AM seedu.duke.Duke run +Mar 15, 2020 1:39:19 AM task.Event getFieldToBeEdited +INFO: Invalid option entered by user +Mar 15, 2020 1:39:19 AM task.Event getFieldToBeEdited +INFO: Invalid option entered by user +Mar 15, 2020 1:39:19 AM task.Event parseDate +INFO: Date after current date exception thrown +Mar 15, 2020 1:39:19 AM task.Event editDate +INFO: Invalid date entered by user +Mar 15, 2020 1:39:19 AM task.Deadline getFieldToBeEdited +INFO: Invalid option entered by user +Mar 15, 2020 1:39:19 AM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 12:57:32 AM seedu.duke.Duke run +Mar 15, 2020 1:39:19 AM seedu.duke.Duke run INFO: Application is going to exit -Mar 15, 2020 12:57:32 AM seedu.duke.Duke run +Mar 15, 2020 1:39:19 AM seedu.duke.Duke run INFO: Application closed successfully diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 60ded882a..38bfdd9b2 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -24,6 +24,10 @@ edit 2 2 2020-01-01 2020-06-06 +edit 1 +5 +1 +assignment event view list task diff --git a/text-ui-test/library/taskList.txt b/text-ui-test/library/taskList.txt index fa0db46bf..a8754e4e2 100644 --- a/text-ui-test/library/taskList.txt +++ b/text-ui-test/library/taskList.txt @@ -1,2 +1,2 @@ -D#assignment #2020-05-02#14:00#2 +D#assignment#2020-05-02#14:00#2 E#team meeting#2020-06-06#12:00#13:00#1 From a5a723a8bd9b581abb7ac1206045b1a26ec1fcea Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 02:13:00 +0800 Subject: [PATCH 108/435] Replace '\n' with System.lineSeparator() --- ...ineCreationFormatNotFollowedException.java | 2 +- ...entCreationFormatNotFollowedException.java | 2 +- src/main/java/task/Event.java | 2 +- src/main/java/ui/Ui.java | 80 ++++++++++--------- src/test/java/task/event/TaskTest.java | 2 +- 5 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java b/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java index db21c9aa6..80f4bbdd9 100644 --- a/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java +++ b/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java @@ -6,6 +6,6 @@ public class DeadlineCreationFormatNotFollowedException extends CustomException { public DeadlineCreationFormatNotFollowedException() { - super("Please follow the correct format to add a new deadline\n" + HELP_DESCRIPTION_5); + super("Please follow the correct format to add a new deadline" + System.lineSeparator() + HELP_DESCRIPTION_5); } } \ No newline at end of file diff --git a/src/main/java/exception/command/EventCreationFormatNotFollowedException.java b/src/main/java/exception/command/EventCreationFormatNotFollowedException.java index ce475d574..a28275fa9 100644 --- a/src/main/java/exception/command/EventCreationFormatNotFollowedException.java +++ b/src/main/java/exception/command/EventCreationFormatNotFollowedException.java @@ -6,6 +6,6 @@ public class EventCreationFormatNotFollowedException extends CustomException { public EventCreationFormatNotFollowedException() { - super("Please follow the correct format to add a new event\n" + HELP_DESCRIPTION_3); + super("Please follow the correct format to add a new event" + System.lineSeparator() + HELP_DESCRIPTION_3); } } \ No newline at end of file diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java index ab41b358a..f04001a9a 100644 --- a/src/main/java/task/Event.java +++ b/src/main/java/task/Event.java @@ -36,7 +36,7 @@ public class Event extends Task { public static final String WITH_PRIORITY = " with priority "; public static final String EMPTY_STRING = ""; public static final String DELIMITER = "#"; - public static final String NEW_LINE_CHARACTER = "\n"; + public static final String NEW_LINE_CHARACTER = System.lineSeparator(); public static final String EVENT_IDENTIFIER = "E"; public static final String ENTER_NEW_PRIORITY_MESSAGE = "Enter new priority:"; public static final String ENTER_NEW_END_TIME_MESSAGE = "Enter new End Time:"; diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index f2ffbde25..f15d25dea 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -38,8 +38,9 @@ public class Ui { + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" + " location is entered. When you are done with the search, enter \"bye\"."; public static final String PROMPT_USER = "Please enter the location for your desired study area."; - public static final String FLAGS = "Here is a list of supported flags!\n\t -p for study areas with ports\n\t" - + " -i for study areas that are indoors\n\t -i for study areas that are outdoors\n\t " + public static final String FLAGS = "Here is a list of supported flags!" + System.lineSeparator() + "\t -p for study" + + " areas with ports" + System.lineSeparator() + "\t -i for study areas that are indoors" + + System.lineSeparator() + "\t -i for study areas that are outdoors" + System.lineSeparator() + "\t " + "-s {size} for maximum number of pax"; public static final String AVAILABLE_STUDY_AREAS = "Here are the available study areas!"; public static final String EMPTY_LIST = "Oops! Based on your criteria we were not able to find a compatible study" @@ -83,8 +84,8 @@ public class Ui { public static final String HELP_DESCRIPTION_1 = TAB + "OrgaNice! Supports the following commands"; public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; - public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"task\" to start\n" - + " your task list! If you are in the mood to mug and you" + public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"task\" to start" + + System.lineSeparator() + " your task list! If you are in the mood to mug and you" + " want to start your study area list, enter \"study\" !If" + " you want to exit, enter \"bye\" !"; public static final String WRONG_INPUT = "Wrong input! Please enter either \"task\" or \"study\" only!"; @@ -99,31 +100,32 @@ public class Ui { //@@author NizarMohd-reused //Reused from https://www.netclipart.com/isee/iRwmhJb_bt21-rj-transparent-background/ and https://asciiart.club/ //Image for public static final String DAB is obtained from the first link and then generated in second link. - public static final String DAB = "\t ``````````````````````````````````````````````````````````\n" - + "\t ````````````````````````````````:v(v'`````````````````````\n" - + "\t ```````````````````````````,)4|ex` `L}````````````````````\n" - + "\t `````````````````````````!s\"'h `M: ^z_;)T```````````````\n" - + "\t `````````````````````````Z u|}Z: \"}``````````````\n" - + "\t ``````````````````````:=?) 'B?L'```````````\n" - + "\t `````````````````````'Z ;Yp\"```````````\n" - + "\t `````````````````````.e ?_```````````\n" - + "\t ```````````````````'QDGH .5````````````\n" - + "\t ````````````````````I#g' '_` ||````````````\n" - + "\t ```````````:mX_``````YhL` `'q!` ? h````````````\n" - + "\t ```````````'Qbs)|L=_V\" 'Y} ^'q@&b=c=_` ,Z````````````\n" - + "\t ````````````q> 'T, ,o\" ;\"@c. .sVx~`````````````\n" - + "\t ````````````c! \"bh` `,p z:``````````````\n" - + "\t `````````````q. ngDQmh8s X'``````````````\n" - + "\t ``````````````LY\" :n}>``b; _V```````````````\n" - + "\t ````````````````q?, ?; \"V````````````````\n" - + "\t ``````````````KvR ' )x_`````````````````\n" - + "\t ``````````````zjL GLY\"```````````````````\n" - + "\t ```````````````M .I)``````````````````````\n" - + "\t ```````````````Lz `D:``````````````````````\n" - + "\t ``````````````vu` (I)_;\"\". P.`````````````````````\n" - + "\t ``````````````p :X.':^,\"=n \"q``````````````````````\n" - + "\t `````````````)0X?^:)I````````m' :j``````````````````````\n" - + "\t `````````````.IGD8k'`````````<&G55M```````````````````````\n" + public static final String DAB = "\t ``````````````````````````````````````````````````````````" + + System.lineSeparator() + + "\t ````````````````````````````````:v(v'`````````````````````" + System.lineSeparator() + + "\t ```````````````````````````,)4|ex` `L}````````````````````" + System.lineSeparator() + + "\t `````````````````````````!s\"'h `M: ^z_;)T```````````````" + System.lineSeparator() + + "\t `````````````````````````Z u|}Z: \"}``````````````" + System.lineSeparator() + + "\t ``````````````````````:=?) 'B?L'```````````" + System.lineSeparator() + + "\t `````````````````````'Z ;Yp\"```````````" + System.lineSeparator() + + "\t `````````````````````.e ?_```````````" + System.lineSeparator() + + "\t ```````````````````'QDGH .5````````````" + System.lineSeparator() + + "\t ````````````````````I#g' '_` ||````````````" + System.lineSeparator() + + "\t ```````````:mX_``````YhL` `'q!` ? h````````````" + System.lineSeparator() + + "\t ```````````'Qbs)|L=_V\" 'Y} ^'q@&b=c=_` ,Z````````````" + System.lineSeparator() + + "\t ````````````q> 'T, ,o\" ;\"@c. .sVx~`````````````" + System.lineSeparator() + + "\t ````````````c! \"bh` `,p z:``````````````" + System.lineSeparator() + + "\t `````````````q. ngDQmh8s X'``````````````" + System.lineSeparator() + + "\t ``````````````LY\" :n}>``b; _V```````````````" + System.lineSeparator() + + "\t ````````````````q?, ?; \"V````````````````" + System.lineSeparator() + + "\t ``````````````KvR ' )x_`````````````````" + System.lineSeparator() + + "\t ``````````````zjL GLY\"```````````````````" + System.lineSeparator() + + "\t ```````````````M .I)``````````````````````" + System.lineSeparator() + + "\t ```````````````Lz `D:``````````````````````" + System.lineSeparator() + + "\t ``````````````vu` (I)_;\"\". P.`````````````````````" + System.lineSeparator() + + "\t ``````````````p :X.':^,\"=n \"q``````````````````````" + System.lineSeparator() + + "\t `````````````)0X?^:)I````````m' :j``````````````````````" + System.lineSeparator() + + "\t `````````````.IGD8k'`````````<&G55M```````````````````````" + System.lineSeparator() + "\t ``````````````````````````````````````````````````````````"; //@@author @@ -233,30 +235,32 @@ public void printWelcomeMessage() { // modifications. The website above allows for generation of fonts in ascii format. Therefore, logo is // generated from the service provided by the website. String logo = "_______/\\\\\\\\\\_____________________________________________________/\\\\\\\\\\_____/\\\\\\__" - + "__________________________________________/\\\\\\____________\n" + + "__________________________________________/\\\\\\____________" + System.lineSeparator() + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" - + "_________________________________________/\\\\\\\\\\\\\\_________\n" + + "_________________________________________/\\\\\\\\\\\\\\_________" + System.lineSeparator() + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" - + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______\n" + + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______" + + System.lineSeparator() + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" - + "_\\//\\\\\\\\\\\\\\_______\n" + + "_\\//\\\\\\\\\\\\\\_______" + System.lineSeparator() + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" - + "___\n" + + "___" + System.lineSeparator() + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" - + "_____\n" + + "_____" + System.lineSeparator() + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" - + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______\n" + + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______" + + System.lineSeparator() + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" + "_\\//\\\\\\\\\\\\\\\\/\\\\" + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" - + "_/\\\\\\_____\n" + + "_/\\\\\\_____" + System.lineSeparator() + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" + "_\\///______\\////////_____\\//////////______\\///_____"; //@@author - this.out.println("Hello from\n" + logo); + this.out.println("Hello from" + System.lineSeparator() + logo); this.out.println("What is your name?"); printLine(); String name = this.in.nextLine(); diff --git a/src/test/java/task/event/TaskTest.java b/src/test/java/task/event/TaskTest.java index 3924e3c17..4fc99078c 100644 --- a/src/test/java/task/event/TaskTest.java +++ b/src/test/java/task/event/TaskTest.java @@ -20,7 +20,7 @@ void eventInformation() throws Exception { @Test void formattedDetails() throws Exception { - assertEquals("E#Team Meeting#2020-03-21#09:00#17:00#1\n", + assertEquals("E#Team Meeting#2020-03-21#09:00#17:00#1" + System.lineSeparator(), new Event("Team Meeting", "2020-03-21", "09:00", "17:00", "1").getFormattedDetails()); } From e1692e5eb418b2d6ce2be5e763b9ee4fb55d2c6a Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sun, 15 Mar 2020 13:23:08 +0800 Subject: [PATCH 109/435] transfer Logo to Constants file --- src/main/java/ui/Constants.java | 30 ++++++++++++++++ src/main/java/ui/Ui.java | 61 ++------------------------------- 2 files changed, 32 insertions(+), 59 deletions(-) diff --git a/src/main/java/ui/Constants.java b/src/main/java/ui/Constants.java index 1887b2c51..82c586756 100644 --- a/src/main/java/ui/Constants.java +++ b/src/main/java/ui/Constants.java @@ -118,4 +118,34 @@ public class Constants { + "\t `````````````.IGD8k'`````````<&G55M```````````````````````\n" + "\t ``````````````````````````````````````````````````````````"; //@@author + + //@@author NizarMohd-reused + //Reused logo from http://patorjk.com/software/taag/#p=display&f=Graffiti&t=TypeSomething with minor + // modifications. The website above allows for generation of fonts in ascii format. Therefore, logo is + // generated from the service provided by the website. + public static final String LOGO = "_______/\\\\\\\\\\___________________________________________________" + + "__/\\\\\\\\\\_____/\\\\\\__" + + "__________________________________________/\\\\\\____________\n" + + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" + + "_________________________________________/\\\\\\\\\\\\\\_________\n" + + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" + + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______\n" + + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" + + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\_______\n" + + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" + + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" + + "___\n" + + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" + + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" + + "_____\n" + + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" + + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______\n" + + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\\\/\\\\" + + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" + + "_/\\\\\\_____\n" + + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" + + "_\\///______\\////////_____\\//////////______\\///_____"; + //@@author } diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 129ad1c79..ce4dea398 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -7,35 +7,7 @@ import java.util.Scanner; import java.util.StringTokenizer; import static java.lang.System.lineSeparator; -import static ui.Constants.BYE_COMMAND; -import static ui.Constants.DAB; -import static ui.Constants.GOODBYE_MESSAGE; -import static ui.Constants.HELP_DESCRIPTION_1; -import static ui.Constants.HELP_DESCRIPTION_10; -import static ui.Constants.HELP_DESCRIPTION_11; -import static ui.Constants.HELP_DESCRIPTION_12; -import static ui.Constants.HELP_DESCRIPTION_13; -import static ui.Constants.HELP_DESCRIPTION_14; -import static ui.Constants.HELP_DESCRIPTION_15; -import static ui.Constants.HELP_DESCRIPTION_16; -import static ui.Constants.HELP_DESCRIPTION_17; -import static ui.Constants.HELP_DESCRIPTION_18; -import static ui.Constants.HELP_DESCRIPTION_19; -import static ui.Constants.HELP_DESCRIPTION_2; -import static ui.Constants.HELP_DESCRIPTION_20; -import static ui.Constants.HELP_DESCRIPTION_3; -import static ui.Constants.HELP_DESCRIPTION_4; -import static ui.Constants.HELP_DESCRIPTION_5; -import static ui.Constants.HELP_DESCRIPTION_7; -import static ui.Constants.HELP_DESCRIPTION_8; -import static ui.Constants.HELP_DESCRIPTION_9; -import static ui.Constants.LINE; -import static ui.Constants.MAX_LINE_LENGTH; -import static ui.Constants.SPACE; -import static ui.Constants.START_MESSAGE; -import static ui.Constants.STUDY_COMMAND; -import static ui.Constants.TAB; -import static ui.Constants.TASK_COMMAND; +import static ui.Constants.*; /** * Contains functions used to interact with the user. @@ -134,36 +106,7 @@ public void printStudyArea(StudyArea studyArea) { * Display welcome message. */ public void printWelcomeMessage() { - - //@@author NizarMohd-reused - //Reused logo from http://patorjk.com/software/taag/#p=display&f=Graffiti&t=TypeSomething with minor - // modifications. The website above allows for generation of fonts in ascii format. Therefore, logo is - // generated from the service provided by the website. - String logo = "_______/\\\\\\\\\\_____________________________________________________/\\\\\\\\\\_____/\\\\\\__" - + "__________________________________________/\\\\\\____________\n" - + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" - + "_________________________________________/\\\\\\\\\\\\\\_________\n" - + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" - + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______\n" - + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" - + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" - + "_\\//\\\\\\\\\\\\\\_______\n" - + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" - + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" - + "___\n" - + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" - + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" - + "_____\n" - + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" - + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______\n" - + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" - + "_\\//\\\\\\\\\\\\\\\\/\\\\" - + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" - + "_/\\\\\\_____\n" - + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" - + "_\\///______\\////////_____\\//////////______\\///_____"; - //@@author - this.out.println("Hello from\n" + logo); + this.out.println("Hello from\n" + LOGO); this.out.println("What is your name?"); printLine(); String name = this.in.nextLine(); From c93eb716add4f25c82e8b4d0f02f408769ae8af7 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sun, 15 Mar 2020 16:33:44 +0800 Subject: [PATCH 110/435] Integrate Sanath's Changes with Nizar's --- dukeLogger.log | 10 +- src/main/java/command/AddDeadlineCommand.java | 4 +- src/main/java/command/AddEventCommand.java | 3 +- ...ineCreationFormatNotFollowedException.java | 3 +- ...entCreationFormatNotFollowedException.java | 2 +- .../EventStartTimeAfterEndTimeException.java | 2 - .../command/InvalidEndTimeException.java | 2 - .../TaskPriorityNotIntegerException.java | 2 - src/main/java/resourceloader/TaskLoader.java | 9 +- src/main/java/seedu/duke/Duke.java | 48 +- src/main/java/task/Deadline.java | 4 +- src/main/java/task/Event.java | 1 - src/main/java/ui/Constants.java | 77 +- src/main/java/ui/Ui.java | 2 +- src/test/java/task/event/TaskListTest.java | 1 - text-ui-test/EXPECTED.TXT | 744 +++++++++++++++--- text-ui-test/dukeLogger.log | 22 +- text-ui-test/library/taskList.txt | 2 - 18 files changed, 763 insertions(+), 175 deletions(-) delete mode 100644 text-ui-test/library/taskList.txt diff --git a/dukeLogger.log b/dukeLogger.log index 6039571c0..db381745b 100644 --- a/dukeLogger.log +++ b/dukeLogger.log @@ -1,10 +1,10 @@ -Mar 15, 2020 12:50:44 AM seedu.duke.Duke run +Mar 15, 2020 4:27:23 PM seedu.duke.Duke run INFO: Application started Execution -Mar 15, 2020 12:50:56 AM seedu.duke.Duke run +Mar 15, 2020 4:27:26 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 12:51:01 AM seedu.duke.Duke run +Mar 15, 2020 4:27:30 PM seedu.duke.Duke run INFO: Application transitioning to study area mode -Mar 15, 2020 12:51:05 AM seedu.duke.Duke run +Mar 15, 2020 4:27:38 PM seedu.duke.Duke run INFO: Application is going to exit -Mar 15, 2020 12:51:05 AM seedu.duke.Duke run +Mar 15, 2020 4:27:38 PM seedu.duke.Duke run INFO: Application closed successfully diff --git a/src/main/java/command/AddDeadlineCommand.java b/src/main/java/command/AddDeadlineCommand.java index 6f4ecf072..2859346f0 100644 --- a/src/main/java/command/AddDeadlineCommand.java +++ b/src/main/java/command/AddDeadlineCommand.java @@ -5,13 +5,11 @@ import task.Deadline; import task.TaskList; import ui.Ui; - import java.time.LocalDate; - import static command.AddEventCommand.DATE_BEFORE_CURRENT_DATE_ERROR_MESSAGE; /** - * This command is used to add new deadlines to the Tasklist. + * This command is used to add new deadlines to the TaskList. */ public class AddDeadlineCommand extends Command { diff --git a/src/main/java/command/AddEventCommand.java b/src/main/java/command/AddEventCommand.java index 3901c6e47..bb357a32f 100644 --- a/src/main/java/command/AddEventCommand.java +++ b/src/main/java/command/AddEventCommand.java @@ -5,11 +5,10 @@ import task.Event; import task.TaskList; import ui.Ui; - import java.time.LocalDate; /** - * This command is used to add new events to the Tasklist. + * This command is used to add new events to the TaskList. */ public class AddEventCommand extends Command { diff --git a/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java b/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java index 80f4bbdd9..3a4b327c6 100644 --- a/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java +++ b/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java @@ -1,8 +1,7 @@ package exception.command; - import exception.CustomException; +import static ui.Constants.HELP_DESCRIPTION_5; -import static ui.Ui.HELP_DESCRIPTION_5; public class DeadlineCreationFormatNotFollowedException extends CustomException { public DeadlineCreationFormatNotFollowedException() { diff --git a/src/main/java/exception/command/EventCreationFormatNotFollowedException.java b/src/main/java/exception/command/EventCreationFormatNotFollowedException.java index a28275fa9..523e38596 100644 --- a/src/main/java/exception/command/EventCreationFormatNotFollowedException.java +++ b/src/main/java/exception/command/EventCreationFormatNotFollowedException.java @@ -1,8 +1,8 @@ package exception.command; import exception.CustomException; +import static ui.Constants.HELP_DESCRIPTION_3; -import static ui.Ui.HELP_DESCRIPTION_3; public class EventCreationFormatNotFollowedException extends CustomException { public EventCreationFormatNotFollowedException() { diff --git a/src/main/java/exception/command/EventStartTimeAfterEndTimeException.java b/src/main/java/exception/command/EventStartTimeAfterEndTimeException.java index 293969564..2dcc8a3af 100644 --- a/src/main/java/exception/command/EventStartTimeAfterEndTimeException.java +++ b/src/main/java/exception/command/EventStartTimeAfterEndTimeException.java @@ -2,8 +2,6 @@ import exception.CustomException; -import static ui.Ui.HELP_DESCRIPTION_5; - public class EventStartTimeAfterEndTimeException extends CustomException { public EventStartTimeAfterEndTimeException() { super("Start time should be before End time"); diff --git a/src/main/java/exception/command/InvalidEndTimeException.java b/src/main/java/exception/command/InvalidEndTimeException.java index 234c2f933..371f64e72 100644 --- a/src/main/java/exception/command/InvalidEndTimeException.java +++ b/src/main/java/exception/command/InvalidEndTimeException.java @@ -2,8 +2,6 @@ import exception.CustomException; -import static ui.Ui.HELP_DESCRIPTION_5; - public class InvalidEndTimeException extends CustomException { public InvalidEndTimeException() { super("End time provided is invalid or in wrong format (Should be HH:MM) 24 Hr format"); diff --git a/src/main/java/exception/command/TaskPriorityNotIntegerException.java b/src/main/java/exception/command/TaskPriorityNotIntegerException.java index 2c00ffb57..a0e87c00c 100644 --- a/src/main/java/exception/command/TaskPriorityNotIntegerException.java +++ b/src/main/java/exception/command/TaskPriorityNotIntegerException.java @@ -2,8 +2,6 @@ import exception.CustomException; -import static ui.Ui.HELP_DESCRIPTION_5; - public class TaskPriorityNotIntegerException extends CustomException { public TaskPriorityNotIntegerException() { super("Priority should be an integer"); diff --git a/src/main/java/resourceloader/TaskLoader.java b/src/main/java/resourceloader/TaskLoader.java index ee157d365..4d467aa3b 100644 --- a/src/main/java/resourceloader/TaskLoader.java +++ b/src/main/java/resourceloader/TaskLoader.java @@ -14,15 +14,14 @@ import java.util.ArrayList; import java.util.Scanner; -import static ui.Constants.FILE_PATH_DICTIONARY; -import static ui.Constants.FILE_PATH_STUDYAREAS; - - /** * Handles the task of loading and storing events. */ public class TaskLoader { + public static final String INVALID_TASK_TYPE_MESSAGE = "Invalid task type identified when parsing tasks from " + + "taskList.txt"; + /** Location of data file. */ private String filePath; /** Directory of data file. */ @@ -87,6 +86,8 @@ private Task parseTaskDetails(String details) throws Exception { break; default: // Error handling + assert false : INVALID_TASK_TYPE_MESSAGE; + break; } return newTask; } diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 3a160c86c..37bcb4659 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -15,7 +15,13 @@ import static ui.Constants.GOODBYE_MESSAGE; import static ui.Constants.INTERMEDIATE_MESSAGE; import static ui.Constants.WRONG_INPUT; - +import java.io.IOException; +import java.util.logging.ConsoleHandler; +import java.util.logging.FileHandler; +import java.util.logging.Level; +import java.util.logging.LogManager; +import java.util.logging.Logger; +import java.util.logging.SimpleFormatter; /** * This is Duke class, which forms the main class of the program. @@ -23,52 +29,87 @@ public class Duke { public static final String FILE_PATH_EVENTS = "library" + File.separator + "taskList.txt"; - public static final String FILE_PATH_STUDYAREAS = "library" + File.separator + "locations.txt"; + public static final String FILE_PATH_STUDY_AREAS = "library" + File.separator + "locations.txt"; + public static final String EXCEPTION_ENCOUNTERED_MESSAGE = "Exception encountered when Duke was constructed"; + public static final String DUKE_LOGGER_LOG = "dukeLogger.log"; + public static final String FILE_LOGGER_NOT_WORKING_MESSAGE = "File Logger not working"; + public static final String APPLICATION_STARTED_EXECUTION = "Application started Execution"; + public static final String APPLICATION_GOING_TO_EXIT = "Application is going to exit"; + public static final String TASK_MODE = "Application transitioning to task mode"; + public static final String STUDY_AREA_MODE = "Application transitioning to study area mode"; + public static final String WRONG_COMMAND = "Wrong command entered by user"; + public static final String APPLICATION_CLOSED_SUCCESSFULLY = "Application closed successfully"; private static TaskLoader taskLoader; protected static StudyAreaLoader studyAreaLoader; private static TaskList taskList = new TaskList(); private static StudyAreaList studyAreaList; private static Ui ui = new Ui(); private static Parser parser; + private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); /** * This is the constructor to create a new Duke program every time user runs the main loop. */ public Duke() { try { + setupLogger(); parser = new Parser(); taskLoader = new TaskLoader(FILE_PATH_EVENTS); taskList = new TaskList(taskLoader.loadFile()); - studyAreaLoader = new StudyAreaLoader(FILE_PATH_STUDYAREAS); + studyAreaLoader = new StudyAreaLoader(FILE_PATH_STUDY_AREAS); studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); } catch (FileNotFoundException | IllegalStudyAreaException e) { + LOGGER.log(Level.SEVERE, EXCEPTION_ENCOUNTERED_MESSAGE, e); ui.printLine(); ui.printMessage(e.getMessage()); ui.printLine(); } } + private void setupLogger() { + LogManager.getLogManager().reset(); + LOGGER.setLevel(Level.INFO); + ConsoleHandler ch = new ConsoleHandler(); + ch.setLevel(Level.SEVERE); + ch.setFormatter(new SimpleFormatter()); + LOGGER.addHandler(ch); + try { + FileHandler fh = new FileHandler(DUKE_LOGGER_LOG); + fh.setLevel(Level.INFO); + fh.setFormatter(new SimpleFormatter()); + LOGGER.addHandler(fh); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, FILE_LOGGER_NOT_WORKING_MESSAGE, e); + } + } + + /** * This method runs the program. */ public void run() { ui.printWelcomeMessage(); + LOGGER.log(Level.INFO, APPLICATION_STARTED_EXECUTION); boolean status = true; while (status) { int mode = ui.getMode(); switch (mode) { case -1: + LOGGER.log(Level.INFO, APPLICATION_GOING_TO_EXIT); status = false; break; case 1: + LOGGER.log(Level.INFO, TASK_MODE); TaskCommand.runCommands(taskList, ui, parser); ui.printMessage(INTERMEDIATE_MESSAGE); break; case 2: + LOGGER.log(Level.INFO, STUDY_AREA_MODE); StudyAreaCommand.runCommands(studyAreaList, ui); ui.printMessage(INTERMEDIATE_MESSAGE); break; default: + LOGGER.log(Level.INFO, WRONG_COMMAND); ui.printLine(); ui.printMessage(WRONG_INPUT); break; @@ -78,6 +119,7 @@ public void run() { taskLoader.saveTasks(taskList.tasks); ui.printMessage(GOODBYE_MESSAGE + DAB); ui.close(); + LOGGER.log(Level.INFO, APPLICATION_CLOSED_SUCCESSFULLY); } /** diff --git a/src/main/java/task/Deadline.java b/src/main/java/task/Deadline.java index ceb14df79..93f7ac542 100644 --- a/src/main/java/task/Deadline.java +++ b/src/main/java/task/Deadline.java @@ -6,7 +6,6 @@ import exception.command.TaskDateBeforeCurrentDateException; import exception.command.TaskPriorityNotIntegerException; import ui.Ui; - import java.time.LocalDate; import java.time.LocalTime; import java.time.format.DateTimeFormatter; @@ -14,7 +13,6 @@ import java.time.temporal.ChronoUnit; import java.util.logging.Level; import java.util.logging.Logger; - import static task.Event.AT; import static task.Event.DATE_AFTER_CURRENT_DATE; import static task.Event.DATE_PATTERN; @@ -41,6 +39,7 @@ import static task.Event.WRONG_OPTION; + /** * Represents an deadline and contains the related functions. */ @@ -65,6 +64,7 @@ public class Deadline extends Task { private int priority; private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + /** * Setter for priority of the deadline. * diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java index f04001a9a..2e9b9ccac 100644 --- a/src/main/java/task/Event.java +++ b/src/main/java/task/Event.java @@ -8,7 +8,6 @@ import exception.command.TaskDateBeforeCurrentDateException; import exception.command.TaskPriorityNotIntegerException; import ui.Ui; - import java.time.LocalDate; import java.time.LocalTime; import java.time.format.DateTimeFormatter; diff --git a/src/main/java/ui/Constants.java b/src/main/java/ui/Constants.java index 82c586756..2f9ef9335 100644 --- a/src/main/java/ui/Constants.java +++ b/src/main/java/ui/Constants.java @@ -30,8 +30,9 @@ public class Constants { + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" + " location is entered. When you are done with the search, enter \"bye\"."; public static final String PROMPT_USER = "Please enter the location for your desired study area."; - public static final String FLAGS = "Here is a list of supported flags!\n\t -p for study areas with ports\n\t" - + " -i for study areas that are indoors\n\t -i for study areas that are outdoors\n\t " + public static final String FLAGS = "Here is a list of supported flags!" + System.lineSeparator() + "\t -p for study" + + " areas with ports" + System.lineSeparator() + "\t -i for study areas that are indoors" + + System.lineSeparator() + "\t -o for study areas that are outdoors" + System.lineSeparator() + "\t " + "-s {size} for maximum number of pax"; public static final String AVAILABLE_STUDY_AREAS = "Here are the available study areas!"; public static final String EMPTY_LIST = "Oops! Based on your criteria we were not able to find a compatible study" @@ -43,7 +44,7 @@ public class Constants { public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"task\" to start" - + " your event list! If you are in the mood to mug and you" + + System.lineSeparator() + " your task list! If you are in the mood to mug and you" + " want to start your study area list, enter \"study\" !If" + " you want to exit, enter \"bye\" !"; public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; @@ -91,31 +92,32 @@ public class Constants { //@@author NizarMohd-reused //Reused from https://www.netclipart.com/isee/iRwmhJb_bt21-rj-transparent-background/ and https://asciiart.club/ //Image for public static final String DAB is obtained from the first link and then generated in second link. - public static final String DAB = "\t ``````````````````````````````````````````````````````````\n" - + "\t ````````````````````````````````:v(v'`````````````````````\n" - + "\t ```````````````````````````,)4|ex` `L}````````````````````\n" - + "\t `````````````````````````!s\"'h `M: ^z_;)T```````````````\n" - + "\t `````````````````````````Z u|}Z: \"}``````````````\n" - + "\t ``````````````````````:=?) 'B?L'```````````\n" - + "\t `````````````````````'Z ;Yp\"```````````\n" - + "\t `````````````````````.e ?_```````````\n" - + "\t ```````````````````'QDGH .5````````````\n" - + "\t ````````````````````I#g' '_` ||````````````\n" - + "\t ```````````:mX_``````YhL` `'q!` ? h````````````\n" - + "\t ```````````'Qbs)|L=_V\" 'Y} ^'q@&b=c=_` ,Z````````````\n" - + "\t ````````````q> 'T, ,o\" ;\"@c. .sVx~`````````````\n" - + "\t ````````````c! \"bh` `,p z:``````````````\n" - + "\t `````````````q. ngDQmh8s X'``````````````\n" - + "\t ``````````````LY\" :n}>``b; _V```````````````\n" - + "\t ````````````````q?, ?; \"V````````````````\n" - + "\t ``````````````KvR ' )x_`````````````````\n" - + "\t ``````````````zjL GLY\"```````````````````\n" - + "\t ```````````````M .I)``````````````````````\n" - + "\t ```````````````Lz `D:``````````````````````\n" - + "\t ``````````````vu` (I)_;\"\". P.`````````````````````\n" - + "\t ``````````````p :X.':^,\"=n \"q``````````````````````\n" - + "\t `````````````)0X?^:)I````````m' :j``````````````````````\n" - + "\t `````````````.IGD8k'`````````<&G55M```````````````````````\n" + public static final String DAB = "\t ``````````````````````````````````````````````````````````" + + System.lineSeparator() + + "\t ````````````````````````````````:v(v'`````````````````````" + System.lineSeparator() + + "\t ```````````````````````````,)4|ex` `L}````````````````````" + System.lineSeparator() + + "\t `````````````````````````!s\"'h `M: ^z_;)T```````````````" + System.lineSeparator() + + "\t `````````````````````````Z u|}Z: \"}``````````````" + System.lineSeparator() + + "\t ``````````````````````:=?) 'B?L'```````````" + System.lineSeparator() + + "\t `````````````````````'Z ;Yp\"```````````" + System.lineSeparator() + + "\t `````````````````````.e ?_```````````" + System.lineSeparator() + + "\t ```````````````````'QDGH .5````````````" + System.lineSeparator() + + "\t ````````````````````I#g' '_` ||````````````" + System.lineSeparator() + + "\t ```````````:mX_``````YhL` `'q!` ? h````````````" + System.lineSeparator() + + "\t ```````````'Qbs)|L=_V\" 'Y} ^'q@&b=c=_` ,Z````````````" + System.lineSeparator() + + "\t ````````````q> 'T, ,o\" ;\"@c. .sVx~`````````````" + System.lineSeparator() + + "\t ````````````c! \"bh` `,p z:``````````````" + System.lineSeparator() + + "\t `````````````q. ngDQmh8s X'``````````````" + System.lineSeparator() + + "\t ``````````````LY\" :n}>``b; _V```````````````" + System.lineSeparator() + + "\t ````````````````q?, ?; \"V````````````````" + System.lineSeparator() + + "\t ``````````````KvR ' )x_`````````````````" + System.lineSeparator() + + "\t ``````````````zjL GLY\"```````````````````" + System.lineSeparator() + + "\t ```````````````M .I)``````````````````````" + System.lineSeparator() + + "\t ```````````````Lz `D:``````````````````````" + System.lineSeparator() + + "\t ``````````````vu` (I)_;\"\". P.`````````````````````" + System.lineSeparator() + + "\t ``````````````p :X.':^,\"=n \"q``````````````````````" + System.lineSeparator() + + "\t `````````````)0X?^:)I````````m' :j``````````````````````" + System.lineSeparator() + + "\t `````````````.IGD8k'`````````<&G55M```````````````````````" + System.lineSeparator() + "\t ``````````````````````````````````````````````````````````"; //@@author @@ -125,27 +127,30 @@ public class Constants { // generated from the service provided by the website. public static final String LOGO = "_______/\\\\\\\\\\___________________________________________________" + "__/\\\\\\\\\\_____/\\\\\\__" - + "__________________________________________/\\\\\\____________\n" + + "__________________________________________/\\\\\\____________" + System.lineSeparator() + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" - + "_________________________________________/\\\\\\\\\\\\\\_________\n" + + "_________________________________________/\\\\\\\\\\\\\\_________" + System.lineSeparator() + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" - + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______\n" + + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______" + + System.lineSeparator() + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" - + "_\\//\\\\\\\\\\\\\\_______\n" + + "_\\//\\\\\\\\\\\\\\_______" + System.lineSeparator() + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" - + "___\n" + + "___" + System.lineSeparator() + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" - + "_____\n" + + "_____" + System.lineSeparator() + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" - + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______\n" + + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______" + + System.lineSeparator() + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" + "_\\//\\\\\\\\\\\\\\\\/\\\\" + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" - + "_/\\\\\\_____\n" + + "_/\\\\\\_____" + System.lineSeparator() + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" + "_\\///______\\////////_____\\//////////______\\///_____"; //@@author + } diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index ce4dea398..d1f3ac5fe 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -106,7 +106,7 @@ public void printStudyArea(StudyArea studyArea) { * Display welcome message. */ public void printWelcomeMessage() { - this.out.println("Hello from\n" + LOGO); + this.out.println("Hello from" + System.lineSeparator() + LOGO); this.out.println("What is your name?"); printLine(); String name = this.in.nextLine(); diff --git a/src/test/java/task/event/TaskListTest.java b/src/test/java/task/event/TaskListTest.java index 87ab16f9c..00024062b 100644 --- a/src/test/java/task/event/TaskListTest.java +++ b/src/test/java/task/event/TaskListTest.java @@ -3,7 +3,6 @@ import org.junit.jupiter.api.Test; import task.Event; import ui.Ui; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index c2a573af3..fce17e46c 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -9,15 +9,15 @@ ________\///\\\__/\\\_____\/\\\___________/\\_____\\\___/\\\/////\\\___\/\\\__\/ ____________\///\\\\\/______\/\\\__________\//\\\\\\\\___\//\\\\\\\\/\\_\/\\\___\//\\\\\__\/\\\___\///\\\\\\\\___\//\\\\\\\\\\______/\\\_____ ______________\/////________\///____________\////////_____\////////\//___\///_____\/////___\///______\////////_____\//////////______\///_____ What is your name? -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Hello James Gosling! Welcome to OrgaNice! To start, enter "task" to start - your task list! If you are in the mood to mug and you - want to start your study area list, enter "study" !If - you want to exit, enter "bye" ! -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ + your task list! If you are in the mood to mug and you want + to start your study area list, enter "study" !If you want + to exit, enter "bye" ! +________________________________________________________________________________________________ +________________________________________________________________________________________________ OrgaNice! Supports the following commands Please enter the keywords followed by the information shown in the brackets event /d /s /e /p @@ -37,74 +37,69 @@ ________________________________________________________________________________ *All dates should follow YYYY-MM-DD format *All timing should follow 24 hour clock *There are 4 levels of priority, with 1 being the most urgent, and 4 being the least urgent -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The list of tasks is cleared. -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - A new event with the following information has been - added. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + A new event with the following information has been added. [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Here is the list of events added so far: 1) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - A new event with the following information has been - added. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + A new event with the following information has been added. [D] assignment on May 2 2020 at 14:00 with priority 2 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Here is the list of tasks added so far displayed in decreasing order of priority: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 + 1) [D] assignment on May 2 2020 at 14:00 with priority 2 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Here is the list of events added so far: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 + 1) [D] assignment on May 2 2020 at 14:00 with priority 2 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The search string entered is empty. -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Empty Line entered, Please enter a valid line -________________________________________________________________________________________________________ +________________________________________________________________________________________________ 1) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ +________________________________________________________________________________________________ The list is empty. -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Invalid index entered. Please enter a valid index to be deleted -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Please follow the correct format to add a new event event /d /s /e /p -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Enter a valid integer index (1-based) to delete/edit - the corresponding event (format: delete/edit index) -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Enter a valid integer index (1-based) to delete/edit the + corresponding event (format: delete/edit index) +________________________________________________________________________________________________ +________________________________________________________________________________________________ Here is the list of events added so far: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 + 1) [D] assignment on May 2 2020 at 14:00 with priority 2 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The event details are as follows: [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 @@ -122,20 +117,19 @@ ________________________________________________________________________________ Updated Details: [E] team meeting at May 5 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The task at the mentioned index has been edited successfully -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Here is the list of events added so far: - 1) [D] assignment on May 2 2020 at 14:00 with priority - 2 - 2) [E] team meeting at May 5 2020 from 12:00 to 13:00 - with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ + 1) [D] assignment on May 2 2020 at 14:00 with priority 2 + 2) [E] team meeting at May 5 2020 from 12:00 to 13:00 with + priority 1 +________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The event details are as follows: [E] team meeting at May 5 2020 from 12:00 to 13:00 with priority 1 @@ -153,17 +147,17 @@ ________________________________________________________________________________ Updated Details: [E] team meeting at Jun 6 2020 from 12:00 to 13:00 with priority 1 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The task at the mentioned index has been edited successfully -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The deadline details are as follows: [D] assignment on May 2 2020 at 14:00 with priority 2 - Which field of the deadline to edit? (Enter - Corresponding Number) + Which field of the deadline to edit? (Enter Corresponding + Number) 1. Description 2. Date 3. Due Time @@ -173,28 +167,28 @@ ________________________________________________________________________________ Enter new description: Updated Details: [D] assignment on May 2 2020 at 14:00 with priority 2 -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ The task at the mentioned index has been edited successfully -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Event details are not provided -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Wrong command used to view events (Should be :view ) -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ Invalid command entered, Please enter a valid command -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Exiting task interface -________________________________________________________________________________________________________ - Please enter "event" to continue with your event list - or "study" to continue with your study area list. To - leave, enter "bye". -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Bye!!!!!! +________________________________________________________________________________________________ + Please enter "task" to continue with your event list or + "study" to continue with your study area list. To leave, + enter "bye". +________________________________________________________________________________________________ +________________________________________________________________________________________________ OrgaNice! Supports the following commands Please enter the keywords followed by the information shown in the brackets event /d /s /e /p @@ -214,19 +208,577 @@ ________________________________________________________________________________ *All dates should follow YYYY-MM-DD format *All timing should follow 24 hour clock *There are 4 levels of priority, with 1 being the most urgent, and 4 being the least urgent -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Wrong command used to view countdown of events (Should - be :countdown ) -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ - Exiting task interface -________________________________________________________________________________________________________ - Please enter "event" to continue with your event list - or "study" to continue with your study area list. To - leave, enter "bye". -________________________________________________________________________________________________________ -________________________________________________________________________________________________________ +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Wrong command used to view countdown of events (Should be + :countdown ) +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Bye!!!!!! +________________________________________________________________________________________________ + Please enter "task" to continue with your event list or + "study" to continue with your study area list. To leave, + enter "bye". +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Please enter the location for your desired study area. + Enter "help" for a list of supported flags. Flags should + only come after location, if a criteria for location is + entered. When you are done with the search, enter "bye". +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Location entered is empty! Please type a location to + search for StudyAreas! +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here is a list of supported flags! + -p for study areas + with ports + -i for study areas that are indoors + -o + for study areas that are outdoors + -s {size} for maximum + number of pax +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: Opposite Town Green (Outside Starbucks) + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Starbucks + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: MacCommons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: PC Commons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Ian and Peony Ferguson Study + Address: 2 College Ave West Education Resource Centre, + Level 3 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: The Study + Address: 2 College Ave West Education Resource Centre, + Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: OCBC + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 2 + __________________________________________________________ + __________________________________________________________ + Name: SuperSnacks + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: Opposite Town Green (Outside Starbucks) + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Starbucks + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 5 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Duplicate flags entered! +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Duplicate flags entered! +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: MacCommons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: PC Commons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Ian and Peony Ferguson Study + Address: 2 College Ave West Education Resource Centre, + Level 3 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: The Study + Address: 2 College Ave West Education Resource Centre, + Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Town Plaza Seminar Rooms Waiting Area + Address: 2 College Ave West, Town Plaza, Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: SuperSnacks + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 1 + Address: 9 Engineering Drive 1,EA, Level 1 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 2 + Address: 9 Engineering Drive 1,EA, Level 2 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 3 + Address: 9 Engineering Drive 1,EA, Level 3 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 6 + Address: 9 Engineering Drive 1,EA, Level 6, EA06-23 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Central Library + Address: Central Library 12 Kent Ridge Crescent + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: YIH Study Room + Address: Yusof Ishak House, Level 2 + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: Opposite Town Green (Outside Starbucks) + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Starbucks + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: MacCommons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: PC Commons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Ian and Peony Ferguson Study + Address: 2 College Ave West Education Resource Centre, + Level 3 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: The Study + Address: 2 College Ave West Education Resource Centre, + Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Town Plaza Seminar Rooms Waiting Area + Address: 2 College Ave West, Town Plaza, Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: OCBC + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 2 + __________________________________________________________ + __________________________________________________________ + Name: SuperSnacks + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 1 + Address: 9 Engineering Drive 1,EA, Level 1 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 2 + Address: 9 Engineering Drive 1,EA, Level 2 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 3 + Address: 9 Engineering Drive 1,EA, Level 3 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 4 + Address: 9 Engineering Drive 1,EA, Level 4, Outside Staff + Offices + Faculty: Engineering + Port: true + Indoor: false + Maximum number of Pax: 6 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 5 + Address: 9 Engineering Drive 1,EA, Level 5, Outside of the + door beside EA05 + Faculty: Engineering + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 6 + Address: 9 Engineering Drive 1,EA, Level 6, EA06-23 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Central Library + Address: Central Library 12 Kent Ridge Crescent + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: YIH Study Room + Address: Yusof Ishak House, Level 2 + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Max Size is not indicated. Please indicate accordingly! +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Argument used after size flag "-s" is not an integer +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Oops! Based on your criteria we were not able to find a + compatible study area! + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Here are the available study areas! + __________________________________________________________ + Name: Opposite Town Green (Outside Starbucks) + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Starbucks + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: MacCommons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: PC Commons + Address: 2 College Avenue West Education Resource Centre, + Level 1 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Ian and Peony Ferguson Study + Address: 2 College Ave West Education Resource Centre, + Level 3 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: The Study + Address: 2 College Ave West Education Resource Centre, + Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: Town Plaza Seminar Rooms Waiting Area + Address: 2 College Ave West, Town Plaza, Level 2 + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: OCBC + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: false + Maximum number of Pax: 2 + __________________________________________________________ + __________________________________________________________ + Name: SuperSnacks + Address: 2 College Ave West, Stephen Riady Centre, Ground + Level + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 1 + Address: 9 Engineering Drive 1,EA, Level 1 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 2 + Address: 9 Engineering Drive 1,EA, Level 2 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 3 + Address: 9 Engineering Drive 1,EA, Level 3 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 4 + Address: 9 Engineering Drive 1,EA, Level 4, Outside Staff + Offices + Faculty: Engineering + Port: true + Indoor: false + Maximum number of Pax: 6 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 5 + Address: 9 Engineering Drive 1,EA, Level 5, Outside of the + door beside EA05 + Faculty: Engineering + Port: true + Indoor: false + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: EA Level 6 + Address: 9 Engineering Drive 1,EA, Level 6, EA06-23 + Faculty: Engineering + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + __________________________________________________________ + Name: Central Library + Address: Central Library 12 Kent Ridge Crescent + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ + Name: YIH Study Room + Address: Yusof Ishak House, Level 2 + Faculty: - + Port: true + Indoor: true + Maximum number of Pax: 4 + __________________________________________________________ + Please enter the location for your desired study area. +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Please enter the flag along with "-" +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Flags indicated are wrongly used. Please enter "help" for + the supported flags! +________________________________________________________________________________________________ +________________________________________________________________________________________________ + Thank you for using our study area search service! +________________________________________________________________________________________________ + Please enter "task" to continue with your event list or + "study" to continue with your study area list. To leave, + enter "bye". +________________________________________________________________________________________________ +________________________________________________________________________________________________ Goodbye! Hope to see you again! `````````````````````````````````````````````````````````` ````````````````````````````````:v(v'````````````````````` diff --git a/text-ui-test/dukeLogger.log b/text-ui-test/dukeLogger.log index 1c8c54b65..ad089bf24 100644 --- a/text-ui-test/dukeLogger.log +++ b/text-ui-test/dukeLogger.log @@ -1,20 +1,22 @@ -Mar 15, 2020 1:39:19 AM seedu.duke.Duke run +Mar 15, 2020 4:31:25 PM seedu.duke.Duke run INFO: Application started Execution -Mar 15, 2020 1:39:19 AM seedu.duke.Duke run +Mar 15, 2020 4:31:25 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 1:39:19 AM task.Event getFieldToBeEdited +Mar 15, 2020 4:31:26 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 1:39:19 AM task.Event getFieldToBeEdited +Mar 15, 2020 4:31:26 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 1:39:19 AM task.Event parseDate +Mar 15, 2020 4:31:26 PM task.Event parseDate INFO: Date after current date exception thrown -Mar 15, 2020 1:39:19 AM task.Event editDate +Mar 15, 2020 4:31:26 PM task.Event editDate INFO: Invalid date entered by user -Mar 15, 2020 1:39:19 AM task.Deadline getFieldToBeEdited +Mar 15, 2020 4:31:26 PM task.Deadline getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 1:39:19 AM seedu.duke.Duke run +Mar 15, 2020 4:31:26 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 1:39:19 AM seedu.duke.Duke run +Mar 15, 2020 4:31:26 PM seedu.duke.Duke run +INFO: Application transitioning to study area mode +Mar 15, 2020 4:31:26 PM seedu.duke.Duke run INFO: Application is going to exit -Mar 15, 2020 1:39:19 AM seedu.duke.Duke run +Mar 15, 2020 4:31:26 PM seedu.duke.Duke run INFO: Application closed successfully diff --git a/text-ui-test/library/taskList.txt b/text-ui-test/library/taskList.txt deleted file mode 100644 index a8754e4e2..000000000 --- a/text-ui-test/library/taskList.txt +++ /dev/null @@ -1,2 +0,0 @@ -D#assignment#2020-05-02#14:00#2 -E#team meeting#2020-06-06#12:00#13:00#1 From dd66b05fbacae24a21f7eac2ef6c574c716c133a Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sun, 15 Mar 2020 16:39:40 +0800 Subject: [PATCH 111/435] edit code to pass checkstyle --- ...ineCreationFormatNotFollowedException.java | 2 +- src/main/java/ui/Constants.java | 56 +++++++++---------- src/main/java/ui/Ui.java | 31 +++++++++- 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java b/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java index 3a4b327c6..cf4d051f5 100644 --- a/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java +++ b/src/main/java/exception/command/DeadlineCreationFormatNotFollowedException.java @@ -1,8 +1,8 @@ package exception.command; + import exception.CustomException; import static ui.Constants.HELP_DESCRIPTION_5; - public class DeadlineCreationFormatNotFollowedException extends CustomException { public DeadlineCreationFormatNotFollowedException() { super("Please follow the correct format to add a new deadline" + System.lineSeparator() + HELP_DESCRIPTION_5); diff --git a/src/main/java/ui/Constants.java b/src/main/java/ui/Constants.java index 2f9ef9335..cc42dd044 100644 --- a/src/main/java/ui/Constants.java +++ b/src/main/java/ui/Constants.java @@ -119,38 +119,38 @@ public class Constants { + "\t `````````````)0X?^:)I````````m' :j``````````````````````" + System.lineSeparator() + "\t `````````````.IGD8k'`````````<&G55M```````````````````````" + System.lineSeparator() + "\t ``````````````````````````````````````````````````````````"; - //@@author + //@@author //@@author NizarMohd-reused //Reused logo from http://patorjk.com/software/taag/#p=display&f=Graffiti&t=TypeSomething with minor // modifications. The website above allows for generation of fonts in ascii format. Therefore, logo is // generated from the service provided by the website. - public static final String LOGO = "_______/\\\\\\\\\\___________________________________________________" - + "__/\\\\\\\\\\_____/\\\\\\__" - + "__________________________________________/\\\\\\____________" + System.lineSeparator() - + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" - + "_________________________________________/\\\\\\\\\\\\\\_________" + System.lineSeparator() - + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" - + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______" - + System.lineSeparator() - + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" - + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" - + "_\\//\\\\\\\\\\\\\\_______" + System.lineSeparator() - + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" - + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" - + "___" + System.lineSeparator() - + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" - + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" - + "_____" + System.lineSeparator() - + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" - + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______" - + System.lineSeparator() - + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" - + "_\\//\\\\\\\\\\\\\\\\/\\\\" - + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" - + "_/\\\\\\_____" + System.lineSeparator() - + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" - + "_\\///______\\////////_____\\//////////______\\///_____"; - //@@author + public static final String LOGO = "_______/\\\\\\\\\\___________________________________________________" + + "__/\\\\\\\\\\_____/\\\\\\__" + + "__________________________________________/\\\\\\____________" + System.lineSeparator() + + "______/\\\\\\///\\\\\\__________________________________________________\\/\\\\\\\\\\\\___\\/\\\\\\_" + + "_________________________________________/\\\\\\\\\\\\\\_________" + System.lineSeparator() + + "_____/\\\\\\/__\\///\\\\\\____________________/\\\\\\\\\\\\\\\\___________________\\/\\\\\\/\\\\\\_" + + "_\\/\\\\\\___/\\\\\\__________________________________/\\\\\\\\\\\\\\\\\\_______" + + System.lineSeparator() + + "_____/\\\\\\______\\//\\\\\\___/\\\\/\\\\\\\\\\\\\\____/\\\\\\////\\\\\\___/\\\\\\\\\\\\\\\\\\___" + + "__\\/\\\\\\//\\\\\\_\\/\\\\\\__\\///_______/\\\\\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\_______" + System.lineSeparator() + + "_____\\/\\\\\\_______\\/\\\\\\__\\/\\\\\\/////\\\\\\__\\//\\\\\\\\\\\\\\\\\\__\\////////\\\\\\___" + + "_\\/\\\\\\\\//\\\\\\\\/\\\\\\___/\\\\\\____/\\\\\\//////_____/\\\\\\/////\\\\\\___\\//\\\\\\\\\\____" + + "___" + System.lineSeparator() + + "______\\//\\\\\\______/\\\\\\___\\/\\\\\\___\\///____\\///////\\\\\\____/\\\\\\\\\\\\\\\\\\\\__" + + "_\\/\\\\\\_\\//\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\___________/\\\\\\\\\\\\\\\\\\\\\\_____\\//\\\\\\__" + + "_____" + System.lineSeparator() + + "________\\///\\\\\\__/\\\\\\_____\\/\\\\\\___________/\\\\_____\\\\\\___/\\\\\\/////\\\\\\__" + + "_\\/\\\\\\__\\//\\\\\\\\\\\\__\\/\\\\\\__\\//\\\\\\_________\\//\\\\///////_______\\///_______" + + System.lineSeparator() + + "____________\\///\\\\\\\\\\/______\\/\\\\\\__________\\//\\\\\\\\\\\\\\\\__" + + "_\\//\\\\\\\\\\\\\\\\/\\\\" + + "_\\/\\\\\\___\\//\\\\\\\\\\__\\/\\\\\\___\\///\\\\\\\\\\\\\\\\___\\//\\\\\\\\\\\\\\\\\\\\_____" + + "_/\\\\\\_____" + System.lineSeparator() + + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" + + "_\\///______\\////////_____\\//////////______\\///_____"; + //@@author } diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index d1f3ac5fe..ec527d2f3 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -7,7 +7,36 @@ import java.util.Scanner; import java.util.StringTokenizer; import static java.lang.System.lineSeparator; -import static ui.Constants.*; +import static ui.Constants.BYE_COMMAND; +import static ui.Constants.DAB; +import static ui.Constants.GOODBYE_MESSAGE; +import static ui.Constants.HELP_DESCRIPTION_1; +import static ui.Constants.HELP_DESCRIPTION_10; +import static ui.Constants.HELP_DESCRIPTION_11; +import static ui.Constants.HELP_DESCRIPTION_12; +import static ui.Constants.HELP_DESCRIPTION_13; +import static ui.Constants.HELP_DESCRIPTION_14; +import static ui.Constants.HELP_DESCRIPTION_15; +import static ui.Constants.HELP_DESCRIPTION_16; +import static ui.Constants.HELP_DESCRIPTION_17; +import static ui.Constants.HELP_DESCRIPTION_18; +import static ui.Constants.HELP_DESCRIPTION_19; +import static ui.Constants.HELP_DESCRIPTION_2; +import static ui.Constants.HELP_DESCRIPTION_20; +import static ui.Constants.HELP_DESCRIPTION_3; +import static ui.Constants.HELP_DESCRIPTION_4; +import static ui.Constants.HELP_DESCRIPTION_5; +import static ui.Constants.HELP_DESCRIPTION_7; +import static ui.Constants.HELP_DESCRIPTION_8; +import static ui.Constants.HELP_DESCRIPTION_9; +import static ui.Constants.LINE; +import static ui.Constants.LOGO; +import static ui.Constants.MAX_LINE_LENGTH; +import static ui.Constants.SPACE; +import static ui.Constants.START_MESSAGE; +import static ui.Constants.STUDY_COMMAND; +import static ui.Constants.TAB; +import static ui.Constants.TASK_COMMAND; /** * Contains functions used to interact with the user. From be185b76422cc5d3f63ba169596f1ea8527802f7 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sun, 15 Mar 2020 17:01:58 +0800 Subject: [PATCH 112/435] rectify changes --- dukeLogger.log | 10 ++---- src/main/java/command/StudyAreaCommand.java | 2 +- src/main/java/ui/Constants.java | 3 +- src/main/java/ui/Ui.java | 39 +++++---------------- text-ui-test/EXPECTED.TXT | 9 ++--- text-ui-test/dukeLogger.log | 22 ++++++------ 6 files changed, 28 insertions(+), 57 deletions(-) diff --git a/dukeLogger.log b/dukeLogger.log index db381745b..c1d49be92 100644 --- a/dukeLogger.log +++ b/dukeLogger.log @@ -1,10 +1,4 @@ -Mar 15, 2020 4:27:23 PM seedu.duke.Duke run +Mar 15, 2020 4:59:38 PM seedu.duke.Duke run INFO: Application started Execution -Mar 15, 2020 4:27:26 PM seedu.duke.Duke run -INFO: Application transitioning to task mode -Mar 15, 2020 4:27:30 PM seedu.duke.Duke run +Mar 15, 2020 4:59:40 PM seedu.duke.Duke run INFO: Application transitioning to study area mode -Mar 15, 2020 4:27:38 PM seedu.duke.Duke run -INFO: Application is going to exit -Mar 15, 2020 4:27:38 PM seedu.duke.Duke run -INFO: Application closed successfully diff --git a/src/main/java/command/StudyAreaCommand.java b/src/main/java/command/StudyAreaCommand.java index 733a12651..f18150769 100644 --- a/src/main/java/command/StudyAreaCommand.java +++ b/src/main/java/command/StudyAreaCommand.java @@ -60,7 +60,7 @@ public static boolean filterCommand(String command, StudyAreaList studyAreaList, ui.printMessage(END_MESSAGE); return false; case HELP_COMMAND: - ui.printMessage(FLAGS); + ui.printStudyAreaHelp(); break; default: try { diff --git a/src/main/java/ui/Constants.java b/src/main/java/ui/Constants.java index cc42dd044..bf8f46855 100644 --- a/src/main/java/ui/Constants.java +++ b/src/main/java/ui/Constants.java @@ -30,7 +30,8 @@ public class Constants { + "Enter \"help\" for a list of supported flags. Flags should only come after location, if a criteria for" + " location is entered. When you are done with the search, enter \"bye\"."; public static final String PROMPT_USER = "Please enter the location for your desired study area."; - public static final String FLAGS = "Here is a list of supported flags!" + System.lineSeparator() + "\t -p for study" + public static final String FLAGS = "\t Here is a list of supported flags!" + System.lineSeparator() + + "\t -p for study" + " areas with ports" + System.lineSeparator() + "\t -i for study areas that are indoors" + System.lineSeparator() + "\t -o for study areas that are outdoors" + System.lineSeparator() + "\t " + "-s {size} for maximum number of pax"; diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index ec527d2f3..68846830d 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -7,36 +7,7 @@ import java.util.Scanner; import java.util.StringTokenizer; import static java.lang.System.lineSeparator; -import static ui.Constants.BYE_COMMAND; -import static ui.Constants.DAB; -import static ui.Constants.GOODBYE_MESSAGE; -import static ui.Constants.HELP_DESCRIPTION_1; -import static ui.Constants.HELP_DESCRIPTION_10; -import static ui.Constants.HELP_DESCRIPTION_11; -import static ui.Constants.HELP_DESCRIPTION_12; -import static ui.Constants.HELP_DESCRIPTION_13; -import static ui.Constants.HELP_DESCRIPTION_14; -import static ui.Constants.HELP_DESCRIPTION_15; -import static ui.Constants.HELP_DESCRIPTION_16; -import static ui.Constants.HELP_DESCRIPTION_17; -import static ui.Constants.HELP_DESCRIPTION_18; -import static ui.Constants.HELP_DESCRIPTION_19; -import static ui.Constants.HELP_DESCRIPTION_2; -import static ui.Constants.HELP_DESCRIPTION_20; -import static ui.Constants.HELP_DESCRIPTION_3; -import static ui.Constants.HELP_DESCRIPTION_4; -import static ui.Constants.HELP_DESCRIPTION_5; -import static ui.Constants.HELP_DESCRIPTION_7; -import static ui.Constants.HELP_DESCRIPTION_8; -import static ui.Constants.HELP_DESCRIPTION_9; -import static ui.Constants.LINE; -import static ui.Constants.LOGO; -import static ui.Constants.MAX_LINE_LENGTH; -import static ui.Constants.SPACE; -import static ui.Constants.START_MESSAGE; -import static ui.Constants.STUDY_COMMAND; -import static ui.Constants.TAB; -import static ui.Constants.TASK_COMMAND; +import static ui.Constants.*; /** * Contains functions used to interact with the user. @@ -145,6 +116,14 @@ public void printWelcomeMessage() { printLine(); } + /** + * This method prints the list of supported flags for the User. + */ + + public void printStudyAreaHelp(){ + this.out.println(FLAGS); + } + /** * Prints an empty line. */ diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index fce17e46c..8b5ded2b7 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -232,13 +232,10 @@ ________________________________________________________________________________ ________________________________________________________________________________________________ ________________________________________________________________________________________________ Here is a list of supported flags! - -p for study areas - with ports + -p for study areas with ports -i for study areas that are indoors - -o - for study areas that are outdoors - -s {size} for maximum - number of pax + -o for study areas that are outdoors + -s {size} for maximum number of pax ________________________________________________________________________________________________ ________________________________________________________________________________________________ Here are the available study areas! diff --git a/text-ui-test/dukeLogger.log b/text-ui-test/dukeLogger.log index ad089bf24..718f64cf1 100644 --- a/text-ui-test/dukeLogger.log +++ b/text-ui-test/dukeLogger.log @@ -1,22 +1,22 @@ -Mar 15, 2020 4:31:25 PM seedu.duke.Duke run +Mar 15, 2020 5:00:52 PM seedu.duke.Duke run INFO: Application started Execution -Mar 15, 2020 4:31:25 PM seedu.duke.Duke run +Mar 15, 2020 5:00:52 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 4:31:26 PM task.Event getFieldToBeEdited +Mar 15, 2020 5:00:52 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 4:31:26 PM task.Event getFieldToBeEdited +Mar 15, 2020 5:00:52 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 4:31:26 PM task.Event parseDate +Mar 15, 2020 5:00:52 PM task.Event parseDate INFO: Date after current date exception thrown -Mar 15, 2020 4:31:26 PM task.Event editDate +Mar 15, 2020 5:00:52 PM task.Event editDate INFO: Invalid date entered by user -Mar 15, 2020 4:31:26 PM task.Deadline getFieldToBeEdited +Mar 15, 2020 5:00:52 PM task.Deadline getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 4:31:26 PM seedu.duke.Duke run +Mar 15, 2020 5:00:52 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 4:31:26 PM seedu.duke.Duke run +Mar 15, 2020 5:00:52 PM seedu.duke.Duke run INFO: Application transitioning to study area mode -Mar 15, 2020 4:31:26 PM seedu.duke.Duke run +Mar 15, 2020 5:00:52 PM seedu.duke.Duke run INFO: Application is going to exit -Mar 15, 2020 4:31:26 PM seedu.duke.Duke run +Mar 15, 2020 5:00:52 PM seedu.duke.Duke run INFO: Application closed successfully From 3d7d63855fd5dc6914a6d4819729f193458254ac Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sun, 15 Mar 2020 17:04:32 +0800 Subject: [PATCH 113/435] rectify changes --- src/main/java/ui/Ui.java | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 68846830d..7822f800f 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -7,7 +7,37 @@ import java.util.Scanner; import java.util.StringTokenizer; import static java.lang.System.lineSeparator; -import static ui.Constants.*; +import static ui.Constants.BYE_COMMAND; +import static ui.Constants.DAB; +import static ui.Constants.FLAGS; +import static ui.Constants.GOODBYE_MESSAGE; +import static ui.Constants.HELP_DESCRIPTION_1; +import static ui.Constants.HELP_DESCRIPTION_10; +import static ui.Constants.HELP_DESCRIPTION_11; +import static ui.Constants.HELP_DESCRIPTION_12; +import static ui.Constants.HELP_DESCRIPTION_13; +import static ui.Constants.HELP_DESCRIPTION_14; +import static ui.Constants.HELP_DESCRIPTION_15; +import static ui.Constants.HELP_DESCRIPTION_16; +import static ui.Constants.HELP_DESCRIPTION_17; +import static ui.Constants.HELP_DESCRIPTION_18; +import static ui.Constants.HELP_DESCRIPTION_19; +import static ui.Constants.HELP_DESCRIPTION_2; +import static ui.Constants.HELP_DESCRIPTION_20; +import static ui.Constants.HELP_DESCRIPTION_3; +import static ui.Constants.HELP_DESCRIPTION_4; +import static ui.Constants.HELP_DESCRIPTION_5; +import static ui.Constants.HELP_DESCRIPTION_7; +import static ui.Constants.HELP_DESCRIPTION_8; +import static ui.Constants.HELP_DESCRIPTION_9; +import static ui.Constants.LINE; +import static ui.Constants.LOGO; +import static ui.Constants.MAX_LINE_LENGTH; +import static ui.Constants.SPACE; +import static ui.Constants.START_MESSAGE; +import static ui.Constants.STUDY_COMMAND; +import static ui.Constants.TAB; +import static ui.Constants.TASK_COMMAND; /** * Contains functions used to interact with the user. @@ -120,7 +150,7 @@ public void printWelcomeMessage() { * This method prints the list of supported flags for the User. */ - public void printStudyAreaHelp(){ + public void printStudyAreaHelp() { this.out.println(FLAGS); } From cc7d2d32ce2dd0ec6dd3c030be5831c75f7f4abf Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sun, 15 Mar 2020 17:11:28 +0800 Subject: [PATCH 114/435] rectify changes --- src/main/java/ui/Constants.java | 2 +- text-ui-test/EXPECTED.TXT | 8 ++++---- text-ui-test/dukeLogger.log | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/ui/Constants.java b/src/main/java/ui/Constants.java index bf8f46855..e0d7e2fc8 100644 --- a/src/main/java/ui/Constants.java +++ b/src/main/java/ui/Constants.java @@ -45,7 +45,7 @@ public class Constants { public static final String NO_SIZE_INDICATED = "Max Size is not indicated. Please indicate accordingly!"; public static final String END_MESSAGE = "Thank you for using our study area search service!"; public static final String START_MESSAGE = "Welcome to OrgaNice! To start, enter \"task\" to start" - + System.lineSeparator() + " your task list! If you are in the mood to mug and you" + + " your task list! If you are in the mood to mug and you" + " want to start your study area list, enter \"study\" !If" + " you want to exit, enter \"bye\" !"; public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 8b5ded2b7..3b9cf62ef 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -12,10 +12,10 @@ What is your name? ________________________________________________________________________________________________ ________________________________________________________________________________________________ Hello James Gosling! - Welcome to OrgaNice! To start, enter "task" to start - your task list! If you are in the mood to mug and you want - to start your study area list, enter "study" !If you want - to exit, enter "bye" ! + Welcome to OrgaNice! To start, enter "task" to start your + task list! If you are in the mood to mug and you want to + start your study area list, enter "study" !If you want to + exit, enter "bye" ! ________________________________________________________________________________________________ ________________________________________________________________________________________________ OrgaNice! Supports the following commands diff --git a/text-ui-test/dukeLogger.log b/text-ui-test/dukeLogger.log index 718f64cf1..146cb8f87 100644 --- a/text-ui-test/dukeLogger.log +++ b/text-ui-test/dukeLogger.log @@ -1,22 +1,22 @@ -Mar 15, 2020 5:00:52 PM seedu.duke.Duke run +Mar 15, 2020 5:10:13 PM seedu.duke.Duke run INFO: Application started Execution -Mar 15, 2020 5:00:52 PM seedu.duke.Duke run +Mar 15, 2020 5:10:13 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 5:00:52 PM task.Event getFieldToBeEdited +Mar 15, 2020 5:10:13 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 5:00:52 PM task.Event getFieldToBeEdited +Mar 15, 2020 5:10:13 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 5:00:52 PM task.Event parseDate +Mar 15, 2020 5:10:13 PM task.Event parseDate INFO: Date after current date exception thrown -Mar 15, 2020 5:00:52 PM task.Event editDate +Mar 15, 2020 5:10:13 PM task.Event editDate INFO: Invalid date entered by user -Mar 15, 2020 5:00:52 PM task.Deadline getFieldToBeEdited +Mar 15, 2020 5:10:13 PM task.Deadline getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 5:00:52 PM seedu.duke.Duke run +Mar 15, 2020 5:10:13 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 5:00:52 PM seedu.duke.Duke run +Mar 15, 2020 5:10:13 PM seedu.duke.Duke run INFO: Application transitioning to study area mode -Mar 15, 2020 5:00:52 PM seedu.duke.Duke run +Mar 15, 2020 5:10:13 PM seedu.duke.Duke run INFO: Application is going to exit -Mar 15, 2020 5:00:52 PM seedu.duke.Duke run +Mar 15, 2020 5:10:13 PM seedu.duke.Duke run INFO: Application closed successfully From b3addc4169647dd41cc65ae50dcb60b6db123d3f Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 18:23:33 +0800 Subject: [PATCH 115/435] Add logging for StudyAreaList and TaskList --- dukeLogger.log | 10 ++-- library/taskList.txt | 3 -- src/main/java/studyarea/StudyAreaList.java | 24 +++++++++- src/main/java/task/TaskList.java | 48 +++++++++++-------- src/main/java/ui/Constants.java | 31 +++++++++++- text-ui-test/EXPECTED.TXT | 12 ++--- text-ui-test/dukeLogger.log | 22 ++++----- .../library}/dictionary.txt | 0 .../library}/locations.txt | 2 +- text-ui-test/library/taskList.txt | 2 + 10 files changed, 108 insertions(+), 46 deletions(-) delete mode 100644 library/taskList.txt rename {library => text-ui-test/library}/dictionary.txt (100%) rename {library => text-ui-test/library}/locations.txt (96%) create mode 100644 text-ui-test/library/taskList.txt diff --git a/dukeLogger.log b/dukeLogger.log index c1d49be92..1ba981afa 100644 --- a/dukeLogger.log +++ b/dukeLogger.log @@ -1,4 +1,8 @@ -Mar 15, 2020 4:59:38 PM seedu.duke.Duke run +Mar 15, 2020 5:43:55 PM seedu.duke.Duke run INFO: Application started Execution -Mar 15, 2020 4:59:40 PM seedu.duke.Duke run -INFO: Application transitioning to study area mode +Mar 15, 2020 5:44:25 PM seedu.duke.Duke run +INFO: Application transitioning to task mode +Mar 15, 2020 5:44:34 PM seedu.duke.Duke run +INFO: Application is going to exit +Mar 15, 2020 5:44:34 PM seedu.duke.Duke run +INFO: Application closed successfully diff --git a/library/taskList.txt b/library/taskList.txt deleted file mode 100644 index c250d7656..000000000 --- a/library/taskList.txt +++ /dev/null @@ -1,3 +0,0 @@ -D#homework #2020-07-06#12:00#2 -D#Hi#2020-07-05#12:00#2 -E#meeting #2020-05-06#12:00#14:00#1 diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 206d24d19..74e95e42f 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -1,27 +1,37 @@ package studyarea; import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + import static ui.Constants.DUPLICATE_FLAGS; +import static ui.Constants.DUPLICATE_FLAGS_LOG; import static ui.Constants.FLAG; +import static ui.Constants.FLAG_MISPLACED_LOG; +import static ui.Constants.IDENTIFIER_MISSING_LOG; import static ui.Constants.INDOOR_FLAG; import static ui.Constants.MULTIPLE_WHITE_SPACES; +import static ui.Constants.NON_INTEGER_LOG; import static ui.Constants.NON_POSITIVE_INTEGER; +import static ui.Constants.NON_POSITIVE_INTEGER_LOG; import static ui.Constants.NOT_INTEGER; import static ui.Constants.NO_SIZE_INDICATED; +import static ui.Constants.NO_SIZE_INDICATED_LOG; import static ui.Constants.ONLY_FLAG; import static ui.Constants.OUTDOOR_FLAG; import static ui.Constants.PORTS_FLAG; import static ui.Constants.SIZE_FLAG; import static ui.Constants.SPACE; import static ui.Constants.WRONG_FLAG_ARGUMENT_POSITION; +import static ui.Constants.WRONG_FLAG_LOG; import static ui.Constants.WRONG_FLAG_USAGE; /** * This is the class that stores and manages all of the Study Areas in location.txt */ - public class StudyAreaList { private ArrayList studyAreaList; + private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); // Assigns studyAreaList into object's studyAreaList. public StudyAreaList(ArrayList studyAreaList) { @@ -40,18 +50,21 @@ public ArrayList getStudyAreaList() { /** * This method checks for duplicate flags. + * * @param flag this is the array of flags in the system. * @param index this is the index referring to the specific flag to check for duplicate. * @throws IllegalStudyAreaException if flag is not null, ie: if flag has already been mentioned. */ public static void checkDuplicate(String[] flag, int index) throws IllegalStudyAreaException { if (flag[index] != null) { + LOGGER.log(Level.INFO, DUPLICATE_FLAGS_LOG); throw new IllegalStudyAreaException(DUPLICATE_FLAGS); } } /** * This method check if command entered is only flags. + * * @param commands This is the string of commands entered by User. * @param index This is the index in which the method is check if only flag exist. * @throws IllegalStudyAreaException if only flag is entered by user. @@ -59,12 +72,14 @@ public static void checkDuplicate(String[] flag, int index) throws IllegalStudyA public static void checkOnlyFlag(String[] commands, int index) throws IllegalStudyAreaException { if (commands[index].length() == 1) { + LOGGER.log(Level.INFO, IDENTIFIER_MISSING_LOG); throw new IllegalStudyAreaException(ONLY_FLAG); } } /** * This method checks if the command after the size flag is a valid integer. + * * @param commands this is the array of commands entered. * @param index this is the index where the size flag is. * @throws IllegalStudyAreaException if command entered is not a valid integer. @@ -74,11 +89,14 @@ public static void checkInteger(String[] commands, int index) throws IllegalStud try { // try block is to test if command is integer int size = Integer.parseInt(commands[index + 1]); if (size <= 0) { // check if integer is positive, else throw exception. + LOGGER.log(Level.INFO, NON_POSITIVE_INTEGER_LOG); throw new IllegalStudyAreaException(NON_POSITIVE_INTEGER); } } catch (NumberFormatException e) { // catch if command is not integer then throw exception + LOGGER.log(Level.INFO, NON_INTEGER_LOG); throw new IllegalStudyAreaException(NOT_INTEGER); } catch (ArrayIndexOutOfBoundsException e) { // catch if no string exist after "-s" and throw exception + LOGGER.log(Level.INFO, NO_SIZE_INDICATED_LOG); throw new IllegalStudyAreaException(NO_SIZE_INDICATED); } @@ -110,10 +128,12 @@ public static void checkFlag(String[] flags, String[] commands, int index, boole checkDuplicate(flags, 3); break; default: + LOGGER.log(Level.INFO, WRONG_FLAG_LOG); throw new IllegalStudyAreaException(WRONG_FLAG_USAGE); } } else { // if no instances of "-" or "-s" if (!isNotFlag) { // and if there exist previous instances of "-" (i.e: -p EA) + LOGGER.log(Level.INFO, FLAG_MISPLACED_LOG); throw new IllegalStudyAreaException(WRONG_FLAG_ARGUMENT_POSITION); // throw exception } } @@ -157,6 +177,7 @@ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException flags[3] = OUTDOOR_FLAG; break; default: + LOGGER.log(Level.INFO, WRONG_FLAG_LOG); throw new IllegalStudyAreaException(WRONG_FLAG_USAGE); } } else { // if no previous instances of "-" @@ -173,6 +194,7 @@ public String[] getFlagsInfo(String[] commands) throws IllegalStudyAreaException /** * Checks if search key is found in Study Area's Name and Faculty attributes. + * * @param name This is the Study Area's Name Attribute. * @param address This is the Study Area's Address Attribute. * @param faculty This is the Study Area's Faculty Attribute. diff --git a/src/main/java/task/TaskList.java b/src/main/java/task/TaskList.java index 048a65c21..08b071ac1 100644 --- a/src/main/java/task/TaskList.java +++ b/src/main/java/task/TaskList.java @@ -1,10 +1,14 @@ package task; +import ui.Constants; +import ui.Ui; + import java.time.LocalDate; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import ui.Ui; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Handles all functions related to the list of events. @@ -17,6 +21,8 @@ public class TaskList { */ public ArrayList tasks; + private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + /** * Constructor for the TaskList class. */ @@ -51,7 +57,7 @@ public int getTaskListSize() { public void addTask(Task newTask, Ui ui) { tasks.add(newTask); ui.printLine(); - ui.printMessage("A new event with the following information has been added."); + ui.printMessage(Constants.NEW_TASK_ADDED_MESSAGE); ui.printMessage(newTask.getTaskInformation()); ui.printLine(); } @@ -64,14 +70,14 @@ public void addTask(Task newTask, Ui ui) { public void listTasks(Ui ui) { ui.printLine(); if (tasks.size() > 0) { - ui.printMessage("Here is the list of events added so far:"); + ui.printMessage(Constants.TASK_LIST_AS_FOLLOWS); int eventNumber = 1; for (Task task : tasks) { - ui.printMessage(eventNumber + ") " + task.getTaskInformation()); + ui.printMessage(eventNumber + Constants.CLOSING_BRACKET + task.getTaskInformation()); eventNumber++; } } else { - ui.printMessage("The list is empty."); + ui.printMessage(Constants.LIST_EMPTY_MESSAGE); } ui.printLine(); } @@ -90,10 +96,11 @@ public void deleteTask(int index, Ui ui) { } tasks.remove(index - 1); ui.printLine(); - ui.printMessage("The task at the mentioned index has been deleted"); + ui.printMessage(Constants.TASK_AT_INDEX_DELETED_MESSAGE); ui.printLine(); } catch (IndexOutOfBoundsException e) { - ui.printMessage("Invalid index entered. Please enter a valid index to be deleted"); + LOGGER.log(Level.INFO, Constants.INDEX_TO_BE_DELETED_OUT_OF_BOUNDS_LOG); + ui.printMessage(Constants.RE_ENTER_VALID_INDEX_TO_DELETE_MESSAGE); ui.printLine(); } } @@ -113,10 +120,10 @@ public void editTask(int index, Ui ui) { /* Converting to '0' based index */ editTaskAtIndex(index - 1, ui); ui.printLine(); - ui.printMessage("The task at the mentioned index has been edited successfully"); + ui.printMessage(Constants.TASK_AT_INDEX_EDITED_MESSAGE); ui.printLine(); } catch (IndexOutOfBoundsException e) { - ui.printMessage("Invalid index entered. Please enter a valid index to be edited"); + ui.printMessage(Constants.RE_ENTER_VALID_INDEX_TO_EDIT_MESSAGE); ui.printLine(); } } @@ -142,7 +149,8 @@ private void editTaskAtIndex(int index, Ui ui) throws IndexOutOfBoundsException tasks.set(index, updatedDeadline); break; default: - ui.printMessage("Error encountered during execution"); + LOGGER.log(Level.SEVERE, Constants.INVALID_TASK_TYPE_LOG); + ui.printMessage(Constants.ERROR_ENCOUNTERED_DURING_EXECUTION_MESSAGE); break; } } @@ -156,7 +164,7 @@ private void editTaskAtIndex(int index, Ui ui) throws IndexOutOfBoundsException public void clearTasks(Ui ui) { tasks.clear(); ui.printLine(); - ui.printMessage("The list of tasks is cleared."); + ui.printMessage(Constants.TASK_LIST_CLEARED_MESSAGE); ui.printLine(); } @@ -173,7 +181,7 @@ public void priorityView(Ui ui) { if (tasks.size() > 0) { printTasksSortedByPriority(ui, tasksSortedByPriority); } else { - ui.printMessage("The list is empty."); + ui.printMessage(Constants.LIST_EMPTY_MESSAGE); } ui.printLine(); } @@ -186,9 +194,9 @@ public void priorityView(Ui ui) { */ private void printTasksSortedByPriority(Ui ui, ArrayList tasksSortedByPriority) { int taskNumber = 1; - ui.printMessage("Here is the list of tasks added so far displayed in decreasing order of priority:"); + ui.printMessage(Constants.LIST_SORTED_BY_PRIORITY_MESSAGE); for (Task task : tasksSortedByPriority) { - ui.printMessage(taskNumber + ") " + task.getTaskInformation()); + ui.printMessage(taskNumber + Constants.CLOSING_BRACKET + task.getTaskInformation()); taskNumber++; } } @@ -205,7 +213,7 @@ public void countdownView(Ui ui) { if (tasks.size() > 0) { printTasksSortedByDate(ui, tasksSortedByDate); } else { - ui.printMessage("The list is empty."); + ui.printMessage(Constants.LIST_EMPTY_MESSAGE); } ui.printLine(); } @@ -218,11 +226,11 @@ public void countdownView(Ui ui) { */ private void printTasksSortedByDate(Ui ui, ArrayList tasksSortedByDate) { int taskNumber = 1; - ui.printMessage("Here is the list of tasks with sorted based on the number of days left:"); + ui.printMessage(Constants.LIST_SORTED_ON_DAYS_LEFT_MESSAGE); for (Task task : tasksSortedByDate) { if (!task.getDate().isBefore(LocalDate.now())) { - ui.printMessage(taskNumber + ") " + task.getTaskInformation() + " ---> " + task.numberOfDaysLeft() - + " day(s) left"); + ui.printMessage(taskNumber + Constants.CLOSING_BRACKET + task.getTaskInformation() + + Constants.ARROW_SYMBOL + task.numberOfDaysLeft() + Constants.DAYS_LEFT); taskNumber++; } } @@ -240,7 +248,7 @@ public void searchTasks(String keyword, Ui ui) throws Exception { if (hasMatchedTask) { printMatchedTasks(keyword, ui); } else { - ui.printMessage("The list is empty."); + ui.printMessage(Constants.LIST_EMPTY_MESSAGE); } ui.printLine(); } @@ -274,7 +282,7 @@ private void printMatchedTasks(String keyword, Ui ui) throws Exception { int taskNumber = 1; for (Task task : tasks) { if (task.hasKeyword(keyword)) { - ui.printMessage(taskNumber + ") " + task.getTaskInformation()); + ui.printMessage(taskNumber + Constants.CLOSING_BRACKET + task.getTaskInformation()); taskNumber++; } } diff --git a/src/main/java/ui/Constants.java b/src/main/java/ui/Constants.java index e0d7e2fc8..dfaa7dc5b 100644 --- a/src/main/java/ui/Constants.java +++ b/src/main/java/ui/Constants.java @@ -152,6 +152,35 @@ public class Constants { + "_/\\\\\\_____" + System.lineSeparator() + "______________\\/////________\\///____________\\////////_____\\////////\\//___\\///_____\\/////__" + "_\\///______\\////////_____\\//////////______\\///_____"; - //@@author + //@@author + + public static final String NON_POSITIVE_INTEGER_LOG = "User entered a non positive integer"; + public static final String NON_INTEGER_LOG = "User entered an invalid number for integer input"; + public static final String DUPLICATE_FLAGS_LOG = "Duplicate flags entered by user"; + public static final String IDENTIFIER_MISSING_LOG = "Identifier not entered with flag by user"; + public static final String NO_SIZE_INDICATED_LOG = "no string exist after \"-s\""; + public static final String WRONG_FLAG_LOG = "Wrong flag used by user while searching for study areas"; + public static final String FLAG_MISPLACED_LOG = "Flag is placed in the wrong position in the user input"; + public static final String NEW_TASK_ADDED_MESSAGE = "A new task with the following information has been added."; + public static final String TASK_LIST_AS_FOLLOWS = "Here is the list of tasks added so far:"; + public static final String CLOSING_BRACKET = ") "; + public static final String LIST_EMPTY_MESSAGE = "The list is empty."; + public static final String TASK_AT_INDEX_DELETED_MESSAGE = "The task at the mentioned index has been deleted"; + public static final String INDEX_TO_BE_DELETED_OUT_OF_BOUNDS_LOG = "Index specified to be deleted is out of bounds"; + public static final String RE_ENTER_VALID_INDEX_TO_DELETE_MESSAGE = "Invalid index entered. Please enter a valid" + + " index to be deleted"; + public static final String TASK_AT_INDEX_EDITED_MESSAGE = "The task at the mentioned index has been " + + "edited successfully"; + public static final String RE_ENTER_VALID_INDEX_TO_EDIT_MESSAGE = "Invalid index entered. Please enter a" + + " valid index to be edited"; + public static final String INVALID_TASK_TYPE_LOG = "Task type of the task to be edited not recognized"; + public static final String ERROR_ENCOUNTERED_DURING_EXECUTION_MESSAGE = "Error encountered during execution"; + public static final String TASK_LIST_CLEARED_MESSAGE = "The list of tasks is cleared."; + public static final String LIST_SORTED_BY_PRIORITY_MESSAGE = "Here is the list of tasks added so far displayed " + + "in decreasing order of priority:"; + public static final String LIST_SORTED_ON_DAYS_LEFT_MESSAGE = "Here is the list of tasks with sorted based" + + " on the number of days left:"; + public static final String ARROW_SYMBOL = " ---> "; + public static final String DAYS_LEFT = " day(s) left"; } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 3b9cf62ef..8046f7941 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -42,17 +42,17 @@ ________________________________________________________________________________ The list of tasks is cleared. ________________________________________________________________________________________________ ________________________________________________________________________________________________ - A new event with the following information has been added. + A new task with the following information has been added. [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 ________________________________________________________________________________________________ ________________________________________________________________________________________________ - Here is the list of events added so far: + Here is the list of tasks added so far: 1) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 ________________________________________________________________________________________________ ________________________________________________________________________________________________ - A new event with the following information has been added. + A new task with the following information has been added. [D] assignment on May 2 2020 at 14:00 with priority 2 ________________________________________________________________________________________________ ________________________________________________________________________________________________ @@ -63,7 +63,7 @@ ________________________________________________________________________________ priority 1 ________________________________________________________________________________________________ ________________________________________________________________________________________________ - Here is the list of events added so far: + Here is the list of tasks added so far: 1) [D] assignment on May 2 2020 at 14:00 with priority 2 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 @@ -93,7 +93,7 @@ ________________________________________________________________________________ corresponding event (format: delete/edit index) ________________________________________________________________________________________________ ________________________________________________________________________________________________ - Here is the list of events added so far: + Here is the list of tasks added so far: 1) [D] assignment on May 2 2020 at 14:00 with priority 2 2) [E] meeting at May 5 2020 from 12:00 to 13:00 with priority 1 @@ -123,7 +123,7 @@ ________________________________________________________________________________ successfully ________________________________________________________________________________________________ ________________________________________________________________________________________________ - Here is the list of events added so far: + Here is the list of tasks added so far: 1) [D] assignment on May 2 2020 at 14:00 with priority 2 2) [E] team meeting at May 5 2020 from 12:00 to 13:00 with priority 1 diff --git a/text-ui-test/dukeLogger.log b/text-ui-test/dukeLogger.log index 146cb8f87..ff13807fd 100644 --- a/text-ui-test/dukeLogger.log +++ b/text-ui-test/dukeLogger.log @@ -1,22 +1,22 @@ -Mar 15, 2020 5:10:13 PM seedu.duke.Duke run +Mar 15, 2020 5:40:27 PM seedu.duke.Duke run INFO: Application started Execution -Mar 15, 2020 5:10:13 PM seedu.duke.Duke run +Mar 15, 2020 5:40:27 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 5:10:13 PM task.Event getFieldToBeEdited +Mar 15, 2020 5:40:27 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 5:10:13 PM task.Event getFieldToBeEdited +Mar 15, 2020 5:40:27 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 5:10:13 PM task.Event parseDate +Mar 15, 2020 5:40:27 PM task.Event parseDate INFO: Date after current date exception thrown -Mar 15, 2020 5:10:13 PM task.Event editDate +Mar 15, 2020 5:40:27 PM task.Event editDate INFO: Invalid date entered by user -Mar 15, 2020 5:10:13 PM task.Deadline getFieldToBeEdited +Mar 15, 2020 5:40:27 PM task.Deadline getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 5:10:13 PM seedu.duke.Duke run +Mar 15, 2020 5:40:27 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 5:10:13 PM seedu.duke.Duke run +Mar 15, 2020 5:40:27 PM seedu.duke.Duke run INFO: Application transitioning to study area mode -Mar 15, 2020 5:10:13 PM seedu.duke.Duke run +Mar 15, 2020 5:40:27 PM seedu.duke.Duke run INFO: Application is going to exit -Mar 15, 2020 5:10:13 PM seedu.duke.Duke run +Mar 15, 2020 5:40:27 PM seedu.duke.Duke run INFO: Application closed successfully diff --git a/library/dictionary.txt b/text-ui-test/library/dictionary.txt similarity index 100% rename from library/dictionary.txt rename to text-ui-test/library/dictionary.txt diff --git a/library/locations.txt b/text-ui-test/library/locations.txt similarity index 96% rename from library/locations.txt rename to text-ui-test/library/locations.txt index 25cc285e0..cbe7dd5f6 100644 --- a/library/locations.txt +++ b/text-ui-test/library/locations.txt @@ -14,4 +14,4 @@ EA Level 4~9 Engineering Drive 1,EA, Level 4, Outside Staff Offices~Engineering~ EA Level 5~9 Engineering Drive 1,EA, Level 5, Outside of the door beside EA05~Engineering~true~false~4 EA Level 6~9 Engineering Drive 1,EA, Level 6, EA06-23~Engineering~true~true~4 Central Library~Central Library 12 Kent Ridge Crescent~-~true~true~5 -YIH Study Room~Yusof Ishak House, Level 2~-~true~true~4 \ No newline at end of file +YIH Study Room~Yusof Ishak House, Level 2~-~true~true~4 diff --git a/text-ui-test/library/taskList.txt b/text-ui-test/library/taskList.txt new file mode 100644 index 000000000..a8754e4e2 --- /dev/null +++ b/text-ui-test/library/taskList.txt @@ -0,0 +1,2 @@ +D#assignment#2020-05-02#14:00#2 +E#team meeting#2020-06-06#12:00#13:00#1 From 9c0a45ec384131e5eed709cf07eeb7d61b50e629 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 18:27:15 +0800 Subject: [PATCH 116/435] Change runtest.bat file to delete library folder before execution --- text-ui-test/runtest.bat | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index a8f0bf153..00e635a0b 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -2,10 +2,17 @@ setlocal enableextensions pushd %~dp0 +if exist ..\library del ..\library + cd .. call gradlew shadowJar +if exist ..\library del ..\library + cd build\libs + +if exist ..\library del ..\library + for /f "tokens=*" %%a in ( 'dir /b *.jar' ) do ( From 633233456f901cb1bf64c2b7a4da07f979a270d7 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sun, 15 Mar 2020 18:48:17 +0800 Subject: [PATCH 117/435] Update message --- src/main/java/ui/Constants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ui/Constants.java b/src/main/java/ui/Constants.java index dfaa7dc5b..1ec0c1721 100644 --- a/src/main/java/ui/Constants.java +++ b/src/main/java/ui/Constants.java @@ -48,7 +48,7 @@ public class Constants { + " your task list! If you are in the mood to mug and you" + " want to start your study area list, enter \"study\" !If" + " you want to exit, enter \"bye\" !"; - public static final String WRONG_INPUT = "Wrong input! Please enter either \"event\" or \"study\" only!"; + public static final String WRONG_INPUT = "Wrong input! Please enter either \"task\" or \"study\" only!"; public static final String TASK_COMMAND = "task"; public static final String STUDY_COMMAND = "study"; public static final String GOODBYE_MESSAGE = " Goodbye! Hope to see you again!"; From 6937490f88356ba64dbc0c519b2b025355777b96 Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Sun, 15 Mar 2020 21:01:50 +0800 Subject: [PATCH 118/435] Add experimental booking system --- .../java/bookingsystem/BookingSystem.java | 79 +++++++++++++++++++ src/main/java/bookingsystem/Test.java | 68 ++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 src/main/java/bookingsystem/BookingSystem.java create mode 100644 src/main/java/bookingsystem/Test.java diff --git a/src/main/java/bookingsystem/BookingSystem.java b/src/main/java/bookingsystem/BookingSystem.java new file mode 100644 index 000000000..35d2eba5a --- /dev/null +++ b/src/main/java/bookingsystem/BookingSystem.java @@ -0,0 +1,79 @@ +package bookingsystem; + +import studyarea.StudyArea; + +public class BookingSystem extends StudyArea { + private boolean isAvailable = true; + private String bookedBy = null; + + /** + * Constructs a StudyArea class for a study area with its information + * Precondition: 'All variables have to be filled. + * + * @param name name of StudyArea + * @param address address of StudyArea + * @param faculty faculty of StudyArea + * @param hasPort true for availability of ports, else false + * @param isIndoor true for indoor, else false + * @param maxPax maximum number of seats for this StudyArea + */ + public BookingSystem(String name, String address, String faculty, boolean hasPort, boolean isIndoor, int maxPax) { + super(name, address, faculty, hasPort, isIndoor, maxPax); + } + + /** + * Method for booking study area. + * @param bookedBy id supplied by user in the form of matric number + * @return true when successfully booked + */ + public boolean bookStudyArea(String bookedBy) { + if (isBooked()) { + return false; + } else { + if (isValidID(bookedBy)) { + isAvailable = false; + this.bookedBy = bookedBy; + return true; + } + } + return false; + } + + /** + * Check if study area is available. + * @return + */ + public boolean isBooked() { + return !(isAvailable); + } + + /** + * Remove booking made by existing user. + * @param id matric number of user that booked the system + */ + public void removeBooking(String id) { + if (idMatchesBookedBy(id)) { + this.isAvailable = true; + bookedBy = null; + } + } + + private boolean idMatchesBookedBy(String id) { + return bookedBy.equals(id); + } + + /** + * Check if id is a valid matric number. + * @param id matric number + * @return true when it is valid + */ + public boolean isValidID(String id) { + if (id.length() != 9) { + return false; + } + if (!(Character.isAlphabetic(id.charAt(0)) && Character.isAlphabetic(id.charAt(id.length() - 1)))) { + return false; + } + return true; + } +} diff --git a/src/main/java/bookingsystem/Test.java b/src/main/java/bookingsystem/Test.java new file mode 100644 index 000000000..49d7a1831 --- /dev/null +++ b/src/main/java/bookingsystem/Test.java @@ -0,0 +1,68 @@ +package bookingsystem; + +import java.io.IOException; +import java.util.Scanner; + +class Test { + /** + * Demonstrates a booking system for a study area. + * Commands available are: book, check, cancel + * @param args not in use + */ + public static void main(String[] args) throws IOException { + BookingSystem studyArea = new BookingSystem("MacCommons", "ERC", "nil", true, + true, 5); + + String command = null; + String userId = null; + Scanner input = new Scanner(System.in); + + while (!"bye".equals(command)) { + System.out.println("\n_____________________________________________________________"); + System.out.println("Booking system for MacCommons"); + System.out.println("[book] to book the study area, [cancel] to cancel, [check] to " + + "check the " + "availability of the study area"); + System.out.println("_____________________________________________________________\n"); + + command = input.nextLine(); + switch (command) { + case "book": + System.out.println("Please enter your id:"); + userId = input.nextLine(); + System.out.println("Hang in there... Processing your booking."); + if (studyArea.bookStudyArea(userId)) { + System.out.println("Your booking has been confirmed."); + } else if (!studyArea.isValidID(userId)) { + System.out.println("Please enter a valid matric number."); + } else { + System.out.println("Sorry the study area is currently booked by someone else."); + } + break; + case "check": + if (studyArea.isBooked()) { + System.out.println("The study area is booked"); + } else { + System.out.println("It is free for booking"); + } + break; + case "cancel": + if (studyArea.isBooked()) { + System.out.println("Please enter your id"); + userId = input.nextLine(); + System.out.println("Hang in there... Processing your request"); + studyArea.removeBooking(userId); + if (studyArea.isBooked()) { + System.out.println("Sorry you are not the owner of the booking."); + } else { + System.out.println("Your booking has been cancelled."); + } + } else { + System.out.println("The study area is not booked at the moment."); + } + break; + default: + break; + } + } + } +} From 5226c19e563fe6c578990674d4f50def5d53576a Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Sun, 15 Mar 2020 21:10:20 +0800 Subject: [PATCH 119/435] Add assert, logger --- src/main/java/bookingsystem/BookingSystem.java | 4 ++++ src/main/java/bookingsystem/Test.java | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/bookingsystem/BookingSystem.java b/src/main/java/bookingsystem/BookingSystem.java index 35d2eba5a..c50d4498b 100644 --- a/src/main/java/bookingsystem/BookingSystem.java +++ b/src/main/java/bookingsystem/BookingSystem.java @@ -2,6 +2,8 @@ import studyarea.StudyArea; +import java.util.logging.Logger; + public class BookingSystem extends StudyArea { private boolean isAvailable = true; private String bookedBy = null; @@ -19,6 +21,8 @@ public class BookingSystem extends StudyArea { */ public BookingSystem(String name, String address, String faculty, boolean hasPort, boolean isIndoor, int maxPax) { super(name, address, faculty, hasPort, isIndoor, maxPax); + Logger logger = Logger.getLogger(BookingSystem.class.getName()); + logger.warning("This is a warning"); } /** diff --git a/src/main/java/bookingsystem/Test.java b/src/main/java/bookingsystem/Test.java index 49d7a1831..7f792370b 100644 --- a/src/main/java/bookingsystem/Test.java +++ b/src/main/java/bookingsystem/Test.java @@ -1,6 +1,5 @@ package bookingsystem; -import java.io.IOException; import java.util.Scanner; class Test { @@ -9,10 +8,10 @@ class Test { * Commands available are: book, check, cancel * @param args not in use */ - public static void main(String[] args) throws IOException { + public static void main(String[] args) { BookingSystem studyArea = new BookingSystem("MacCommons", "ERC", "nil", true, true, 5); - + assert true; String command = null; String userId = null; Scanner input = new Scanner(System.in); From 7ef5f3a2673076c24ce19ebc5e6706c89a03eb90 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Sun, 15 Mar 2020 23:57:16 +0800 Subject: [PATCH 120/435] ensure study area data files are read only --- .../java/resourceloader/StudyAreaLoader.java | 23 ++++++++++++------- src/main/java/resourceloader/TaskLoader.java | 10 +++++++- text-ui-test/library/dictionary.txt | 10 -------- text-ui-test/library/locations.txt | 17 -------------- text-ui-test/library/taskList.txt | 2 -- 5 files changed, 24 insertions(+), 38 deletions(-) delete mode 100644 text-ui-test/library/dictionary.txt delete mode 100644 text-ui-test/library/locations.txt delete mode 100644 text-ui-test/library/taskList.txt diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index 8e49e8ba6..721df38e5 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -73,19 +73,26 @@ public ArrayList pushToDatabase() throws IllegalStudyAreaException, F return buffer; } + /** * This method creates a new data file for locations.txt and dictionary.txt. + * @param filePath this is the path of the data file to be created. * @throws IOException if cannot create file. */ - public static void createNewStudyAreaData() throws IOException { - Files.createFile(Paths.get(FILE_PATH_STUDYAREAS)); - Files.createFile(Paths.get(FILE_PATH_DICTIONARY)); - PrintWriter dataBuffer = new PrintWriter(new File(FILE_PATH_STUDYAREAS)); - dataBuffer.println(BackUpData.BACKUP_LOCATIONS); - dataBuffer.close(); - dataBuffer = new PrintWriter(new File(FILE_PATH_DICTIONARY)); - dataBuffer.println(BackUpData.BACKUP_DICTIONARY); + public static void createNewStudyAreaData(String filePath) throws IOException, IllegalStudyAreaException { + Files.createFile(Paths.get(filePath)); + PrintWriter dataBuffer = new PrintWriter(new File(filePath)); + if (filePath.equals(FILE_PATH_STUDYAREAS)) { + dataBuffer.println(BackUpData.BACKUP_LOCATIONS); + } else { + dataBuffer.println(BackUpData.BACKUP_DICTIONARY); + } dataBuffer.close(); + File dataFile = new File (filePath); + boolean isLocked = dataFile.setWritable(false); + if (!isLocked) { + throw new IllegalStudyAreaException("Cannot make read-only"); + } } } diff --git a/src/main/java/resourceloader/TaskLoader.java b/src/main/java/resourceloader/TaskLoader.java index 4d467aa3b..54067b1ec 100644 --- a/src/main/java/resourceloader/TaskLoader.java +++ b/src/main/java/resourceloader/TaskLoader.java @@ -1,5 +1,7 @@ package resourceloader; +import studyarea.IllegalStudyAreaException; +import studyarea.StudyArea; import task.Task; import task.Deadline; import task.Event; @@ -14,6 +16,9 @@ import java.util.ArrayList; import java.util.Scanner; +import static ui.Constants.FILE_PATH_DICTIONARY; +import static ui.Constants.FILE_PATH_STUDYAREAS; + /** * Handles the task of loading and storing events. */ @@ -136,9 +141,12 @@ private void createNewDataFile() { try { Files.createDirectories(fileDirectory); Files.createFile(Paths.get(filePath)); - StudyAreaLoader.createNewStudyAreaData(); + StudyAreaLoader.createNewStudyAreaData(FILE_PATH_STUDYAREAS); + StudyAreaLoader.createNewStudyAreaData(FILE_PATH_DICTIONARY); } catch (IOException e) { e.printStackTrace(); + } catch (IllegalStudyAreaException e) { + System.out.println(e.getMessage()); } } diff --git a/text-ui-test/library/dictionary.txt b/text-ui-test/library/dictionary.txt deleted file mode 100644 index e644c92a5..000000000 --- a/text-ui-test/library/dictionary.txt +++ /dev/null @@ -1,10 +0,0 @@ -engineering~eng~engin~engine~foe -utown~university town~u-town~u town -maccommons~mccommons~mac commons -education resource centre~erc -stephen riady centre~stephen~riady~src -ocbc~frank~frank by ocbc -starbucks~bucks~bux~sbux -pc commons~pccommons~pccommon -yih~yusof ishak~yusof~ishak -supersnacks~super snacks~super snack diff --git a/text-ui-test/library/locations.txt b/text-ui-test/library/locations.txt deleted file mode 100644 index cbe7dd5f6..000000000 --- a/text-ui-test/library/locations.txt +++ /dev/null @@ -1,17 +0,0 @@ -Opposite Town Green (Outside Starbucks)~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~4 -Starbucks~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~5 -MacCommons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 -PC Commons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 -Ian and Peony Ferguson Study~2 College Ave West Education Resource Centre, Level 3~Utown~true~true~4 -The Study~2 College Ave West Education Resource Centre, Level 2~Utown~true~true~5 -Town Plaza Seminar Rooms Waiting Area~2 College Ave West, Town Plaza, Level 2~Utown~true~true~4 -OCBC~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~false~2 -SuperSnacks~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~true~4 -EA Level 1~9 Engineering Drive 1,EA, Level 1~Engineering~true~true~4 -EA Level 2~9 Engineering Drive 1,EA, Level 2~Engineering~true~true~4 -EA Level 3~9 Engineering Drive 1,EA, Level 3~Engineering~true~true~4 -EA Level 4~9 Engineering Drive 1,EA, Level 4, Outside Staff Offices~Engineering~true~false~6 -EA Level 5~9 Engineering Drive 1,EA, Level 5, Outside of the door beside EA05~Engineering~true~false~4 -EA Level 6~9 Engineering Drive 1,EA, Level 6, EA06-23~Engineering~true~true~4 -Central Library~Central Library 12 Kent Ridge Crescent~-~true~true~5 -YIH Study Room~Yusof Ishak House, Level 2~-~true~true~4 diff --git a/text-ui-test/library/taskList.txt b/text-ui-test/library/taskList.txt deleted file mode 100644 index a8754e4e2..000000000 --- a/text-ui-test/library/taskList.txt +++ /dev/null @@ -1,2 +0,0 @@ -D#assignment#2020-05-02#14:00#2 -E#team meeting#2020-06-06#12:00#13:00#1 From 486f24c2ebf36056260b7d0cbebfa2204050cc5a Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Mon, 16 Mar 2020 00:04:05 +0800 Subject: [PATCH 121/435] edit javadoc and run check style --- src/main/java/resourceloader/StudyAreaLoader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index 721df38e5..8989b3021 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -78,6 +78,7 @@ public ArrayList pushToDatabase() throws IllegalStudyAreaException, F * This method creates a new data file for locations.txt and dictionary.txt. * @param filePath this is the path of the data file to be created. * @throws IOException if cannot create file. + * @throws IllegalStudyAreaException if the data files cannot be set to read-only. */ public static void createNewStudyAreaData(String filePath) throws IOException, IllegalStudyAreaException { Files.createFile(Paths.get(filePath)); @@ -88,7 +89,7 @@ public static void createNewStudyAreaData(String filePath) throws IOException, I dataBuffer.println(BackUpData.BACKUP_DICTIONARY); } dataBuffer.close(); - File dataFile = new File (filePath); + File dataFile = new File(filePath); boolean isLocked = dataFile.setWritable(false); if (!isLocked) { throw new IllegalStudyAreaException("Cannot make read-only"); From 237df9516738c6d0c686727686538de58dc03ec6 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Mon, 16 Mar 2020 15:02:07 +0800 Subject: [PATCH 122/435] Refactor code --- src/main/java/seedu/duke/Duke.java | 58 +++++++++++++----------------- src/main/java/ui/Constants.java | 14 ++++++++ src/main/java/ui/Ui.java | 8 ++++- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 37bcb4659..a95838f8d 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,20 +1,17 @@ package seedu.duke; -import parser.Parser; -import command.TaskCommand; import command.StudyAreaCommand; -import resourceloader.TaskLoader; +import command.TaskCommand; +import parser.Parser; import resourceloader.StudyAreaLoader; +import resourceloader.TaskLoader; import studyarea.IllegalStudyAreaException; import studyarea.StudyAreaList; import task.TaskList; +import ui.Constants; import ui.Ui; -import java.io.File; + import java.io.FileNotFoundException; -import static ui.Constants.DAB; -import static ui.Constants.GOODBYE_MESSAGE; -import static ui.Constants.INTERMEDIATE_MESSAGE; -import static ui.Constants.WRONG_INPUT; import java.io.IOException; import java.util.logging.ConsoleHandler; import java.util.logging.FileHandler; @@ -23,22 +20,14 @@ import java.util.logging.Logger; import java.util.logging.SimpleFormatter; +import static ui.Constants.INTERMEDIATE_MESSAGE; +import static ui.Constants.WRONG_INPUT; + /** * This is Duke class, which forms the main class of the program. */ public class Duke { - public static final String FILE_PATH_EVENTS = "library" + File.separator + "taskList.txt"; - public static final String FILE_PATH_STUDY_AREAS = "library" + File.separator + "locations.txt"; - public static final String EXCEPTION_ENCOUNTERED_MESSAGE = "Exception encountered when Duke was constructed"; - public static final String DUKE_LOGGER_LOG = "dukeLogger.log"; - public static final String FILE_LOGGER_NOT_WORKING_MESSAGE = "File Logger not working"; - public static final String APPLICATION_STARTED_EXECUTION = "Application started Execution"; - public static final String APPLICATION_GOING_TO_EXIT = "Application is going to exit"; - public static final String TASK_MODE = "Application transitioning to task mode"; - public static final String STUDY_AREA_MODE = "Application transitioning to study area mode"; - public static final String WRONG_COMMAND = "Wrong command entered by user"; - public static final String APPLICATION_CLOSED_SUCCESSFULLY = "Application closed successfully"; private static TaskLoader taskLoader; protected static StudyAreaLoader studyAreaLoader; private static TaskList taskList = new TaskList(); @@ -54,12 +43,12 @@ public Duke() { try { setupLogger(); parser = new Parser(); - taskLoader = new TaskLoader(FILE_PATH_EVENTS); + taskLoader = new TaskLoader(Constants.FILE_PATH_EVENTS); taskList = new TaskList(taskLoader.loadFile()); - studyAreaLoader = new StudyAreaLoader(FILE_PATH_STUDY_AREAS); + studyAreaLoader = new StudyAreaLoader(Constants.FILE_PATH_STUDY_AREAS); studyAreaList = new StudyAreaList(studyAreaLoader.pushToDatabase()); } catch (FileNotFoundException | IllegalStudyAreaException e) { - LOGGER.log(Level.SEVERE, EXCEPTION_ENCOUNTERED_MESSAGE, e); + LOGGER.log(Level.SEVERE, Constants.EXCEPTION_ENCOUNTERED_MESSAGE, e); ui.printLine(); ui.printMessage(e.getMessage()); ui.printLine(); @@ -74,12 +63,12 @@ private void setupLogger() { ch.setFormatter(new SimpleFormatter()); LOGGER.addHandler(ch); try { - FileHandler fh = new FileHandler(DUKE_LOGGER_LOG); + FileHandler fh = new FileHandler(Constants.DUKE_LOGGER_LOG); fh.setLevel(Level.INFO); fh.setFormatter(new SimpleFormatter()); LOGGER.addHandler(fh); } catch (IOException e) { - LOGGER.log(Level.SEVERE, FILE_LOGGER_NOT_WORKING_MESSAGE, e); + LOGGER.log(Level.SEVERE, Constants.FILE_LOGGER_NOT_WORKING_MESSAGE, e); } } @@ -89,27 +78,27 @@ private void setupLogger() { */ public void run() { ui.printWelcomeMessage(); - LOGGER.log(Level.INFO, APPLICATION_STARTED_EXECUTION); + LOGGER.log(Level.INFO, Constants.APPLICATION_STARTED_EXECUTION); boolean status = true; while (status) { int mode = ui.getMode(); switch (mode) { - case -1: - LOGGER.log(Level.INFO, APPLICATION_GOING_TO_EXIT); + case Constants.EXIT: + LOGGER.log(Level.INFO, Constants.APPLICATION_GOING_TO_EXIT); status = false; break; - case 1: - LOGGER.log(Level.INFO, TASK_MODE); + case Constants.TASK_MODE_SELECTED: + LOGGER.log(Level.INFO, Constants.TASK_MODE); TaskCommand.runCommands(taskList, ui, parser); ui.printMessage(INTERMEDIATE_MESSAGE); break; - case 2: - LOGGER.log(Level.INFO, STUDY_AREA_MODE); + case Constants.STUDY_AREA_MODE_SELECTED: + LOGGER.log(Level.INFO, Constants.STUDY_AREA_MODE); StudyAreaCommand.runCommands(studyAreaList, ui); ui.printMessage(INTERMEDIATE_MESSAGE); break; default: - LOGGER.log(Level.INFO, WRONG_COMMAND); + LOGGER.log(Level.INFO, Constants.WRONG_COMMAND); ui.printLine(); ui.printMessage(WRONG_INPUT); break; @@ -117,11 +106,12 @@ public void run() { ui.printLine(); } taskLoader.saveTasks(taskList.tasks); - ui.printMessage(GOODBYE_MESSAGE + DAB); + ui.printByeMessage(); ui.close(); - LOGGER.log(Level.INFO, APPLICATION_CLOSED_SUCCESSFULLY); + LOGGER.log(Level.INFO, Constants.APPLICATION_CLOSED_SUCCESSFULLY); } + /** * Main entry-point for the java.duke.Duke application. * diff --git a/src/main/java/ui/Constants.java b/src/main/java/ui/Constants.java index 1ec0c1721..18282c0d7 100644 --- a/src/main/java/ui/Constants.java +++ b/src/main/java/ui/Constants.java @@ -183,4 +183,18 @@ public class Constants { + " on the number of days left:"; public static final String ARROW_SYMBOL = " ---> "; public static final String DAYS_LEFT = " day(s) left"; + public static final String FILE_PATH_EVENTS = "library" + File.separator + "taskList.txt"; + public static final String FILE_PATH_STUDY_AREAS = "library" + File.separator + "locations.txt"; + public static final String EXCEPTION_ENCOUNTERED_MESSAGE = "Exception encountered when Duke was constructed"; + public static final String DUKE_LOGGER_LOG = "dukeLogger.log"; + public static final String FILE_LOGGER_NOT_WORKING_MESSAGE = "File Logger not working"; + public static final String APPLICATION_STARTED_EXECUTION = "Application started Execution"; + public static final String APPLICATION_GOING_TO_EXIT = "Application is going to exit"; + public static final String TASK_MODE = "Application transitioning to task mode"; + public static final String STUDY_AREA_MODE = "Application transitioning to study area mode"; + public static final String WRONG_COMMAND = "Wrong command entered by user"; + public static final String APPLICATION_CLOSED_SUCCESSFULLY = "Application closed successfully"; + public static final int TASK_MODE_SELECTED = 1; + public static final int STUDY_AREA_MODE_SELECTED = 2; + public static final int EXIT = -1; } diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 7822f800f..cb817f4ac 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -149,7 +149,6 @@ public void printWelcomeMessage() { /** * This method prints the list of supported flags for the User. */ - public void printStudyAreaHelp() { this.out.println(FLAGS); } @@ -161,6 +160,13 @@ public void printEmptyLine() { System.out.println(); } + /** + * Prints the closing message. + */ + public void printByeMessage() { + printMessage(GOODBYE_MESSAGE + DAB); + } + /** * Display the list of supported commands. */ From 31bd20d0789926f0492f2525e231b75755217bfc Mon Sep 17 00:00:00 2001 From: Terry Tay Date: Mon, 16 Mar 2020 16:08:12 +0800 Subject: [PATCH 123/435] Add logging and assertion to booking system --- dukeLogger.log | 8 -------- gradle/wrapper/gradle-wrapper.properties | 5 +++-- library/dictionary.txt | 10 ++++++++++ library/locations.txt | 17 +++++++++++++++++ library/taskList.txt | 0 src/main/java/bookingsystem/BookingSystem.java | 2 +- src/main/java/bookingsystem/Test.java | 7 ++++++- 7 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 library/dictionary.txt create mode 100644 library/locations.txt create mode 100644 library/taskList.txt diff --git a/dukeLogger.log b/dukeLogger.log index 1ba981afa..e69de29bb 100644 --- a/dukeLogger.log +++ b/dukeLogger.log @@ -1,8 +0,0 @@ -Mar 15, 2020 5:43:55 PM seedu.duke.Duke run -INFO: Application started Execution -Mar 15, 2020 5:44:25 PM seedu.duke.Duke run -INFO: Application transitioning to task mode -Mar 15, 2020 5:44:34 PM seedu.duke.Duke run -INFO: Application is going to exit -Mar 15, 2020 5:44:34 PM seedu.duke.Duke run -INFO: Application closed successfully diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b7c8c5dbf..cb8c1755e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Mon Mar 16 15:56:40 SGT 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/library/dictionary.txt b/library/dictionary.txt new file mode 100644 index 000000000..e644c92a5 --- /dev/null +++ b/library/dictionary.txt @@ -0,0 +1,10 @@ +engineering~eng~engin~engine~foe +utown~university town~u-town~u town +maccommons~mccommons~mac commons +education resource centre~erc +stephen riady centre~stephen~riady~src +ocbc~frank~frank by ocbc +starbucks~bucks~bux~sbux +pc commons~pccommons~pccommon +yih~yusof ishak~yusof~ishak +supersnacks~super snacks~super snack diff --git a/library/locations.txt b/library/locations.txt new file mode 100644 index 000000000..cbe7dd5f6 --- /dev/null +++ b/library/locations.txt @@ -0,0 +1,17 @@ +Opposite Town Green (Outside Starbucks)~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~4 +Starbucks~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~5 +MacCommons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 +PC Commons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 +Ian and Peony Ferguson Study~2 College Ave West Education Resource Centre, Level 3~Utown~true~true~4 +The Study~2 College Ave West Education Resource Centre, Level 2~Utown~true~true~5 +Town Plaza Seminar Rooms Waiting Area~2 College Ave West, Town Plaza, Level 2~Utown~true~true~4 +OCBC~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~false~2 +SuperSnacks~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~true~4 +EA Level 1~9 Engineering Drive 1,EA, Level 1~Engineering~true~true~4 +EA Level 2~9 Engineering Drive 1,EA, Level 2~Engineering~true~true~4 +EA Level 3~9 Engineering Drive 1,EA, Level 3~Engineering~true~true~4 +EA Level 4~9 Engineering Drive 1,EA, Level 4, Outside Staff Offices~Engineering~true~false~6 +EA Level 5~9 Engineering Drive 1,EA, Level 5, Outside of the door beside EA05~Engineering~true~false~4 +EA Level 6~9 Engineering Drive 1,EA, Level 6, EA06-23~Engineering~true~true~4 +Central Library~Central Library 12 Kent Ridge Crescent~-~true~true~5 +YIH Study Room~Yusof Ishak House, Level 2~-~true~true~4 diff --git a/library/taskList.txt b/library/taskList.txt new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/java/bookingsystem/BookingSystem.java b/src/main/java/bookingsystem/BookingSystem.java index c50d4498b..b01cbc9f3 100644 --- a/src/main/java/bookingsystem/BookingSystem.java +++ b/src/main/java/bookingsystem/BookingSystem.java @@ -45,7 +45,7 @@ public boolean bookStudyArea(String bookedBy) { /** * Check if study area is available. - * @return + * @return true if available */ public boolean isBooked() { return !(isAvailable); diff --git a/src/main/java/bookingsystem/Test.java b/src/main/java/bookingsystem/Test.java index 7f792370b..7d474a014 100644 --- a/src/main/java/bookingsystem/Test.java +++ b/src/main/java/bookingsystem/Test.java @@ -1,8 +1,12 @@ package bookingsystem; import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; class Test { + private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + /** * Demonstrates a booking system for a study area. * Commands available are: book, check, cancel @@ -11,7 +15,6 @@ class Test { public static void main(String[] args) { BookingSystem studyArea = new BookingSystem("MacCommons", "ERC", "nil", true, true, 5); - assert true; String command = null; String userId = null; Scanner input = new Scanner(System.in); @@ -60,6 +63,8 @@ public static void main(String[] args) { } break; default: + LOGGER.log(Level.INFO, "Uncaught scenario"); + assert false; break; } } From d10338a0396bf023cc9dbb9fd25f5de36b6ee5b7 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Mon, 16 Mar 2020 22:24:24 +0800 Subject: [PATCH 124/435] rectify bug --- dukeLogger.log | 8 ---- src/main/java/resourceloader/BackUpData.java | 2 +- src/main/java/studyarea/StudyAreaList.java | 39 ++++++++++---------- 3 files changed, 21 insertions(+), 28 deletions(-) delete mode 100644 dukeLogger.log diff --git a/dukeLogger.log b/dukeLogger.log deleted file mode 100644 index 1ba981afa..000000000 --- a/dukeLogger.log +++ /dev/null @@ -1,8 +0,0 @@ -Mar 15, 2020 5:43:55 PM seedu.duke.Duke run -INFO: Application started Execution -Mar 15, 2020 5:44:25 PM seedu.duke.Duke run -INFO: Application transitioning to task mode -Mar 15, 2020 5:44:34 PM seedu.duke.Duke run -INFO: Application is going to exit -Mar 15, 2020 5:44:34 PM seedu.duke.Duke run -INFO: Application closed successfully diff --git a/src/main/java/resourceloader/BackUpData.java b/src/main/java/resourceloader/BackUpData.java index ec6234972..55d2e39ca 100644 --- a/src/main/java/resourceloader/BackUpData.java +++ b/src/main/java/resourceloader/BackUpData.java @@ -18,7 +18,7 @@ class BackUpData { static final String BACKUP_LOCATIONS = "Opposite Town Green (Outside Starbucks)~2 College Avenue West Education " + "Resource Centre, Ground Level~Utown~true~false~4\n" - + "Starbucks~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~5\n" + + "Starbucks~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~true~5\n" + "MacCommons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5\n" + "PC Commons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5\n" + "Ian and Peony Ferguson Study~2 College Ave West Education Resource Centre, Level 3~Utown~" diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index 74e95e42f..ab1fe7555 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -224,30 +224,31 @@ public ArrayList searchList(String userIn) throws IllegalStudyAreaExc String[] flags = getFlagsInfo(temp); ArrayList availStudyAreas = new ArrayList<>(); for (StudyArea studyArea : this.studyAreaList) { - boolean isAvail = true; int index = 0; + boolean isAvail = true; for (String flag : flags) { - if (flag != null && isAvail && index != 1) { + if (flag != null && isAvail && index!=1) { switch (flag) { - case PORTS_FLAG: - isAvail = studyArea.hasPort(); - break; - case INDOOR_FLAG: - isAvail = studyArea.isIndoor(); - break; - case OUTDOOR_FLAG: - isAvail = !studyArea.isIndoor(); - break; - case SIZE_FLAG: // allows user to find by capacity <= MaxPax - isAvail = Integer.parseInt(flags[1]) <= studyArea.getMaxPax(); - break; - default: // toLowerCase() so casing does not affect matching - isAvail = containsKey(studyArea.getName().toLowerCase(), studyArea.getAddress().toLowerCase(), - studyArea.getFaculty().toLowerCase(), flags[4].toLowerCase()); - break; + case PORTS_FLAG: + isAvail = studyArea.hasPort(); + break; + case INDOOR_FLAG: + isAvail = studyArea.isIndoor(); + break; + case OUTDOOR_FLAG: + isAvail = !studyArea.isIndoor(); + break; + case SIZE_FLAG: // allows user to find by capacity <= MaxPax + isAvail = Integer.parseInt(flags[1]) <= studyArea.getMaxPax(); + break; + default: // toLowerCase() so casing does not affect matching + isAvail = containsKey(studyArea.getName().toLowerCase(), + studyArea.getAddress().toLowerCase(), + studyArea.getFaculty().toLowerCase(), flags[4].toLowerCase()); + break; } - index++; } + index++; } if (isAvail) { availStudyAreas.add(studyArea); From 854e04c8bfeda76a6685056781a96df05870df1a Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Mon, 16 Mar 2020 22:28:54 +0800 Subject: [PATCH 125/435] run checkstyle --- src/main/java/studyarea/StudyAreaList.java | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/studyarea/StudyAreaList.java b/src/main/java/studyarea/StudyAreaList.java index ab1fe7555..8ac9c96aa 100644 --- a/src/main/java/studyarea/StudyAreaList.java +++ b/src/main/java/studyarea/StudyAreaList.java @@ -227,25 +227,25 @@ public ArrayList searchList(String userIn) throws IllegalStudyAreaExc int index = 0; boolean isAvail = true; for (String flag : flags) { - if (flag != null && isAvail && index!=1) { + if (flag != null && isAvail && index != 1) { switch (flag) { - case PORTS_FLAG: - isAvail = studyArea.hasPort(); - break; - case INDOOR_FLAG: - isAvail = studyArea.isIndoor(); - break; - case OUTDOOR_FLAG: - isAvail = !studyArea.isIndoor(); - break; - case SIZE_FLAG: // allows user to find by capacity <= MaxPax - isAvail = Integer.parseInt(flags[1]) <= studyArea.getMaxPax(); - break; - default: // toLowerCase() so casing does not affect matching - isAvail = containsKey(studyArea.getName().toLowerCase(), - studyArea.getAddress().toLowerCase(), - studyArea.getFaculty().toLowerCase(), flags[4].toLowerCase()); - break; + case PORTS_FLAG: + isAvail = studyArea.hasPort(); + break; + case INDOOR_FLAG: + isAvail = studyArea.isIndoor(); + break; + case OUTDOOR_FLAG: + isAvail = !studyArea.isIndoor(); + break; + case SIZE_FLAG: // allows user to find by capacity <= MaxPax + isAvail = Integer.parseInt(flags[1]) <= studyArea.getMaxPax(); + break; + default: // toLowerCase() so casing does not affect matching + isAvail = containsKey(studyArea.getName().toLowerCase(), + studyArea.getAddress().toLowerCase(), + studyArea.getFaculty().toLowerCase(), flags[4].toLowerCase()); + break; } } index++; From f3df5850349e5471a6eb891f83d5276f300bbdd9 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Mon, 16 Mar 2020 22:31:19 +0800 Subject: [PATCH 126/435] edit text ui --- text-ui-test/EXPECTED.TXT | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 8046f7941..284691a01 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -254,7 +254,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ __________________________________________________________ @@ -334,7 +334,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ Please enter the location for your desired study area. @@ -348,6 +348,15 @@ ________________________________________________________________________________ ________________________________________________________________________________________________ Here are the available study areas! __________________________________________________________ + Name: Starbucks + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ Name: MacCommons Address: 2 College Avenue West Education Resource Centre, Level 1 @@ -467,7 +476,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ __________________________________________________________ @@ -628,7 +637,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ __________________________________________________________ From 150f9582c80f237b05e865c7b1d3ddf85a821b5f Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Mon, 16 Mar 2020 22:38:57 +0800 Subject: [PATCH 127/435] Refactor code --- dukeLogger.log | 8 ----- library/taskList.txt | 2 ++ .../command/EmptyDescriptionException.java | 9 +++++ src/main/java/task/Deadline.java | 26 +++++++++++--- src/main/java/task/Event.java | 26 +++++++++++--- .../{event/TaskTest.java => EventTest.java} | 5 ++- .../java/task/{event => }/TaskListTest.java | 4 +-- text-ui-test/dukeLogger.log | 36 +++++++++++++------ text-ui-test/library/dictionary.txt | 10 ++++++ text-ui-test/library/locations.txt | 17 +++++++++ text-ui-test/library/taskList.txt | 2 ++ 11 files changed, 112 insertions(+), 33 deletions(-) create mode 100644 library/taskList.txt create mode 100644 src/main/java/exception/command/EmptyDescriptionException.java rename src/test/java/task/{event/TaskTest.java => EventTest.java} (98%) rename src/test/java/task/{event => }/TaskListTest.java (96%) create mode 100644 text-ui-test/library/dictionary.txt create mode 100644 text-ui-test/library/locations.txt create mode 100644 text-ui-test/library/taskList.txt diff --git a/dukeLogger.log b/dukeLogger.log index 1ba981afa..e69de29bb 100644 --- a/dukeLogger.log +++ b/dukeLogger.log @@ -1,8 +0,0 @@ -Mar 15, 2020 5:43:55 PM seedu.duke.Duke run -INFO: Application started Execution -Mar 15, 2020 5:44:25 PM seedu.duke.Duke run -INFO: Application transitioning to task mode -Mar 15, 2020 5:44:34 PM seedu.duke.Duke run -INFO: Application is going to exit -Mar 15, 2020 5:44:34 PM seedu.duke.Duke run -INFO: Application closed successfully diff --git a/library/taskList.txt b/library/taskList.txt new file mode 100644 index 000000000..ec1b98421 --- /dev/null +++ b/library/taskList.txt @@ -0,0 +1,2 @@ +E#hi #2020-05-05#12:00#13:00#1 +D#hi #2020-05-05#14:00#3 diff --git a/src/main/java/exception/command/EmptyDescriptionException.java b/src/main/java/exception/command/EmptyDescriptionException.java new file mode 100644 index 000000000..68cae04da --- /dev/null +++ b/src/main/java/exception/command/EmptyDescriptionException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class EmptyDescriptionException extends CustomException { + public EmptyDescriptionException() { + super("Description shouldn't be empty"); + } +} \ No newline at end of file diff --git a/src/main/java/task/Deadline.java b/src/main/java/task/Deadline.java index 93f7ac542..9d2f4ba3e 100644 --- a/src/main/java/task/Deadline.java +++ b/src/main/java/task/Deadline.java @@ -1,5 +1,6 @@ package task; +import exception.command.EmptyDescriptionException; import exception.command.InvalidDateException; import exception.command.InvalidDueTimeException; import exception.command.SearchKeywordEmptyException; @@ -13,12 +14,14 @@ import java.time.temporal.ChronoUnit; import java.util.logging.Level; import java.util.logging.Logger; + import static task.Event.AT; import static task.Event.DATE_AFTER_CURRENT_DATE; import static task.Event.DATE_PATTERN; import static task.Event.DELIMITER; import static task.Event.EDIT_DATE; import static task.Event.EDIT_DESCRIPTION; +import static task.Event.EMPTY_DESCRIPTION_MESSAGE; import static task.Event.EMPTY_STRING; import static task.Event.ENTER_NEW_DATE_MESSAGE; import static task.Event.ENTER_NEW_DESCRIPTION_MESSAGE; @@ -39,7 +42,6 @@ import static task.Event.WRONG_OPTION; - /** * Represents an deadline and contains the related functions. */ @@ -155,8 +157,12 @@ private void parseDate(String date) throws Exception { * Parses the description from the string entered by user for the description field. * * @param description String entered by user for the description field. + * @throws EmptyDescriptionException If the description of the task provided is empty. */ - private void parseDescription(String description) { + private void parseDescription(String description) throws EmptyDescriptionException { + if (description.trim().equals(Event.EMPTY_STRING)) { + throw new EmptyDescriptionException(); + } this.description = description; } @@ -323,9 +329,19 @@ private void editDate(Ui ui) { * @param ui Used to interact with the user. */ private void editDescription(Ui ui) { - ui.printMessage(ENTER_NEW_DESCRIPTION_MESSAGE); - String newDescription = ui.getUserIn(); - parseDescription(newDescription); + boolean exceptionEncountered; + do { + exceptionEncountered = false; + ui.printMessage(ENTER_NEW_DESCRIPTION_MESSAGE); + String newDescription = ui.getUserIn(); + try { + parseDescription(newDescription); + } catch (Exception e) { + LOGGER.log(Level.INFO, EMPTY_DESCRIPTION_MESSAGE); + ui.printMessage(e.getMessage()); + exceptionEncountered = true; + } + } while (exceptionEncountered); } /** diff --git a/src/main/java/task/Event.java b/src/main/java/task/Event.java index 2e9b9ccac..0c23b9198 100644 --- a/src/main/java/task/Event.java +++ b/src/main/java/task/Event.java @@ -1,5 +1,6 @@ package task; +import exception.command.EmptyDescriptionException; import exception.command.EventStartTimeAfterEndTimeException; import exception.command.InvalidDateException; import exception.command.InvalidEndTimeException; @@ -8,6 +9,7 @@ import exception.command.TaskDateBeforeCurrentDateException; import exception.command.TaskPriorityNotIntegerException; import ui.Ui; + import java.time.LocalDate; import java.time.LocalTime; import java.time.format.DateTimeFormatter; @@ -65,6 +67,8 @@ public class Event extends Task { public static final String INVALID_START_TIME_ENTERED = "Invalid start time entered by user"; public static final String INVALID_DATE_ENTERED = "Invalid date entered by user"; public static final String INVALID_OPTION_ENTERED = "Invalid option entered by user"; + public static final String EMPTY_DESCRIPTION_MESSAGE = "New description entered by user while editing " + + "the task is empty"; private String description; private LocalDate date; @@ -193,8 +197,12 @@ private void parseDate(String date) throws Exception { * Parses the description from the string entered by user for the description field. * * @param description String entered by user for the description field. + * @throws EmptyDescriptionException If the description of the task provided is empty. */ - private void parseDescription(String description) { + private void parseDescription(String description) throws EmptyDescriptionException { + if (description.trim().equals(Event.EMPTY_STRING)) { + throw new EmptyDescriptionException(); + } this.description = description; } @@ -401,9 +409,19 @@ private void editDate(Ui ui) { * @param ui Used to interact with the user. */ private void editDescription(Ui ui) { - ui.printMessage(ENTER_NEW_DESCRIPTION_MESSAGE); - String newDescription = ui.getUserIn(); - parseDescription(newDescription); + boolean exceptionEncountered; + do { + exceptionEncountered = false; + ui.printMessage(ENTER_NEW_DESCRIPTION_MESSAGE); + String newDescription = ui.getUserIn(); + try { + parseDescription(newDescription); + } catch (Exception e) { + LOGGER.log(Level.INFO, EMPTY_DESCRIPTION_MESSAGE); + ui.printMessage(e.getMessage()); + exceptionEncountered = true; + } + } while (exceptionEncountered); } /** diff --git a/src/test/java/task/event/TaskTest.java b/src/test/java/task/EventTest.java similarity index 98% rename from src/test/java/task/event/TaskTest.java rename to src/test/java/task/EventTest.java index 4fc99078c..00347dd8e 100644 --- a/src/test/java/task/event/TaskTest.java +++ b/src/test/java/task/EventTest.java @@ -1,7 +1,6 @@ -package task.event; +package task; import org.junit.jupiter.api.Test; -import task.Event; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -9,7 +8,7 @@ /** * Contains all the tests related to the Event class. */ -class TaskTest { +class EventTest { @Test void eventInformation() throws Exception { diff --git a/src/test/java/task/event/TaskListTest.java b/src/test/java/task/TaskListTest.java similarity index 96% rename from src/test/java/task/event/TaskListTest.java rename to src/test/java/task/TaskListTest.java index 00024062b..cef2a761d 100644 --- a/src/test/java/task/event/TaskListTest.java +++ b/src/test/java/task/TaskListTest.java @@ -1,8 +1,8 @@ -package task.event; +package task; import org.junit.jupiter.api.Test; -import task.Event; import ui.Ui; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; diff --git a/text-ui-test/dukeLogger.log b/text-ui-test/dukeLogger.log index ff13807fd..0ca28d2bc 100644 --- a/text-ui-test/dukeLogger.log +++ b/text-ui-test/dukeLogger.log @@ -1,22 +1,36 @@ -Mar 15, 2020 5:40:27 PM seedu.duke.Duke run +Mar 16, 2020 10:22:22 PM seedu.duke.Duke run INFO: Application started Execution -Mar 15, 2020 5:40:27 PM seedu.duke.Duke run +Mar 16, 2020 10:22:22 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 5:40:27 PM task.Event getFieldToBeEdited +Mar 16, 2020 10:22:22 PM task.TaskList deleteTask +INFO: Index specified to be deleted is out of bounds +Mar 16, 2020 10:22:22 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 5:40:27 PM task.Event getFieldToBeEdited +Mar 16, 2020 10:22:22 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 5:40:27 PM task.Event parseDate +Mar 16, 2020 10:22:22 PM task.Event parseDate INFO: Date after current date exception thrown -Mar 15, 2020 5:40:27 PM task.Event editDate +Mar 16, 2020 10:22:22 PM task.Event editDate INFO: Invalid date entered by user -Mar 15, 2020 5:40:27 PM task.Deadline getFieldToBeEdited +Mar 16, 2020 10:22:22 PM task.Deadline getFieldToBeEdited INFO: Invalid option entered by user -Mar 15, 2020 5:40:27 PM seedu.duke.Duke run +Mar 16, 2020 10:22:22 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 15, 2020 5:40:27 PM seedu.duke.Duke run +Mar 16, 2020 10:22:22 PM seedu.duke.Duke run INFO: Application transitioning to study area mode -Mar 15, 2020 5:40:27 PM seedu.duke.Duke run +Mar 16, 2020 10:22:23 PM studyarea.StudyAreaList checkDuplicate +INFO: Duplicate flags entered by user +Mar 16, 2020 10:22:23 PM studyarea.StudyAreaList checkDuplicate +INFO: Duplicate flags entered by user +Mar 16, 2020 10:22:23 PM studyarea.StudyAreaList checkInteger +INFO: no string exist after "-s" +Mar 16, 2020 10:22:23 PM studyarea.StudyAreaList checkInteger +INFO: User entered an invalid number for integer input +Mar 16, 2020 10:22:23 PM studyarea.StudyAreaList checkOnlyFlag +INFO: Identifier not entered with flag by user +Mar 16, 2020 10:22:23 PM studyarea.StudyAreaList checkFlag +INFO: Wrong flag used by user while searching for study areas +Mar 16, 2020 10:22:23 PM seedu.duke.Duke run INFO: Application is going to exit -Mar 15, 2020 5:40:27 PM seedu.duke.Duke run +Mar 16, 2020 10:22:23 PM seedu.duke.Duke run INFO: Application closed successfully diff --git a/text-ui-test/library/dictionary.txt b/text-ui-test/library/dictionary.txt new file mode 100644 index 000000000..e644c92a5 --- /dev/null +++ b/text-ui-test/library/dictionary.txt @@ -0,0 +1,10 @@ +engineering~eng~engin~engine~foe +utown~university town~u-town~u town +maccommons~mccommons~mac commons +education resource centre~erc +stephen riady centre~stephen~riady~src +ocbc~frank~frank by ocbc +starbucks~bucks~bux~sbux +pc commons~pccommons~pccommon +yih~yusof ishak~yusof~ishak +supersnacks~super snacks~super snack diff --git a/text-ui-test/library/locations.txt b/text-ui-test/library/locations.txt new file mode 100644 index 000000000..cbe7dd5f6 --- /dev/null +++ b/text-ui-test/library/locations.txt @@ -0,0 +1,17 @@ +Opposite Town Green (Outside Starbucks)~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~4 +Starbucks~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~5 +MacCommons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 +PC Commons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 +Ian and Peony Ferguson Study~2 College Ave West Education Resource Centre, Level 3~Utown~true~true~4 +The Study~2 College Ave West Education Resource Centre, Level 2~Utown~true~true~5 +Town Plaza Seminar Rooms Waiting Area~2 College Ave West, Town Plaza, Level 2~Utown~true~true~4 +OCBC~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~false~2 +SuperSnacks~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~true~4 +EA Level 1~9 Engineering Drive 1,EA, Level 1~Engineering~true~true~4 +EA Level 2~9 Engineering Drive 1,EA, Level 2~Engineering~true~true~4 +EA Level 3~9 Engineering Drive 1,EA, Level 3~Engineering~true~true~4 +EA Level 4~9 Engineering Drive 1,EA, Level 4, Outside Staff Offices~Engineering~true~false~6 +EA Level 5~9 Engineering Drive 1,EA, Level 5, Outside of the door beside EA05~Engineering~true~false~4 +EA Level 6~9 Engineering Drive 1,EA, Level 6, EA06-23~Engineering~true~true~4 +Central Library~Central Library 12 Kent Ridge Crescent~-~true~true~5 +YIH Study Room~Yusof Ishak House, Level 2~-~true~true~4 diff --git a/text-ui-test/library/taskList.txt b/text-ui-test/library/taskList.txt new file mode 100644 index 000000000..a8754e4e2 --- /dev/null +++ b/text-ui-test/library/taskList.txt @@ -0,0 +1,2 @@ +D#assignment#2020-05-02#14:00#2 +E#team meeting#2020-06-06#12:00#13:00#1 From c0e7fba14648211a6df2ea8ccb50671fa3fda5b9 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Mon, 16 Mar 2020 23:03:00 +0800 Subject: [PATCH 128/435] Update text-ui-test file --- text-ui-test/EXPECTED.TXT | 17 ++++++++++---- text-ui-test/dukeLogger.log | 36 ++++++++++++++--------------- text-ui-test/library/dictionary.txt | 10 -------- text-ui-test/library/locations.txt | 17 -------------- text-ui-test/library/taskList.txt | 2 -- 5 files changed, 31 insertions(+), 51 deletions(-) delete mode 100644 text-ui-test/library/dictionary.txt delete mode 100644 text-ui-test/library/locations.txt delete mode 100644 text-ui-test/library/taskList.txt diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 8046f7941..284691a01 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -254,7 +254,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ __________________________________________________________ @@ -334,7 +334,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ Please enter the location for your desired study area. @@ -348,6 +348,15 @@ ________________________________________________________________________________ ________________________________________________________________________________________________ Here are the available study areas! __________________________________________________________ + Name: Starbucks + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ Name: MacCommons Address: 2 College Avenue West Education Resource Centre, Level 1 @@ -467,7 +476,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ __________________________________________________________ @@ -628,7 +637,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ __________________________________________________________ diff --git a/text-ui-test/dukeLogger.log b/text-ui-test/dukeLogger.log index 00d47c847..9688f67a1 100644 --- a/text-ui-test/dukeLogger.log +++ b/text-ui-test/dukeLogger.log @@ -1,36 +1,36 @@ -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run INFO: Application started Execution -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 16, 2020 10:42:22 PM task.TaskList deleteTask +Mar 16, 2020 11:02:13 PM task.TaskList deleteTask INFO: Index specified to be deleted is out of bounds -Mar 16, 2020 10:42:22 PM task.Event getFieldToBeEdited +Mar 16, 2020 11:02:13 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 16, 2020 10:42:22 PM task.Event getFieldToBeEdited +Mar 16, 2020 11:02:13 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 16, 2020 10:42:22 PM task.Event parseDate +Mar 16, 2020 11:02:13 PM task.Event parseDate INFO: Date after current date exception thrown -Mar 16, 2020 10:42:22 PM task.Event editDate +Mar 16, 2020 11:02:13 PM task.Event editDate INFO: Invalid date entered by user -Mar 16, 2020 10:42:22 PM task.Deadline getFieldToBeEdited +Mar 16, 2020 11:02:13 PM task.Deadline getFieldToBeEdited INFO: Invalid option entered by user -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run INFO: Application transitioning to study area mode -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkDuplicate +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkDuplicate INFO: Duplicate flags entered by user -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkDuplicate +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkDuplicate INFO: Duplicate flags entered by user -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkInteger +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkInteger INFO: no string exist after "-s" -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkInteger +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkInteger INFO: User entered an invalid number for integer input -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkOnlyFlag +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkOnlyFlag INFO: Identifier not entered with flag by user -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkFlag +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkFlag INFO: Wrong flag used by user while searching for study areas -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run INFO: Application is going to exit -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run INFO: Application closed successfully diff --git a/text-ui-test/library/dictionary.txt b/text-ui-test/library/dictionary.txt deleted file mode 100644 index e644c92a5..000000000 --- a/text-ui-test/library/dictionary.txt +++ /dev/null @@ -1,10 +0,0 @@ -engineering~eng~engin~engine~foe -utown~university town~u-town~u town -maccommons~mccommons~mac commons -education resource centre~erc -stephen riady centre~stephen~riady~src -ocbc~frank~frank by ocbc -starbucks~bucks~bux~sbux -pc commons~pccommons~pccommon -yih~yusof ishak~yusof~ishak -supersnacks~super snacks~super snack diff --git a/text-ui-test/library/locations.txt b/text-ui-test/library/locations.txt deleted file mode 100644 index cbe7dd5f6..000000000 --- a/text-ui-test/library/locations.txt +++ /dev/null @@ -1,17 +0,0 @@ -Opposite Town Green (Outside Starbucks)~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~4 -Starbucks~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~5 -MacCommons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 -PC Commons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 -Ian and Peony Ferguson Study~2 College Ave West Education Resource Centre, Level 3~Utown~true~true~4 -The Study~2 College Ave West Education Resource Centre, Level 2~Utown~true~true~5 -Town Plaza Seminar Rooms Waiting Area~2 College Ave West, Town Plaza, Level 2~Utown~true~true~4 -OCBC~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~false~2 -SuperSnacks~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~true~4 -EA Level 1~9 Engineering Drive 1,EA, Level 1~Engineering~true~true~4 -EA Level 2~9 Engineering Drive 1,EA, Level 2~Engineering~true~true~4 -EA Level 3~9 Engineering Drive 1,EA, Level 3~Engineering~true~true~4 -EA Level 4~9 Engineering Drive 1,EA, Level 4, Outside Staff Offices~Engineering~true~false~6 -EA Level 5~9 Engineering Drive 1,EA, Level 5, Outside of the door beside EA05~Engineering~true~false~4 -EA Level 6~9 Engineering Drive 1,EA, Level 6, EA06-23~Engineering~true~true~4 -Central Library~Central Library 12 Kent Ridge Crescent~-~true~true~5 -YIH Study Room~Yusof Ishak House, Level 2~-~true~true~4 diff --git a/text-ui-test/library/taskList.txt b/text-ui-test/library/taskList.txt deleted file mode 100644 index a8754e4e2..000000000 --- a/text-ui-test/library/taskList.txt +++ /dev/null @@ -1,2 +0,0 @@ -D#assignment#2020-05-02#14:00#2 -E#team meeting#2020-06-06#12:00#13:00#1 From 96a1326e8eb98e2bdb75b7750c6d0ad62c42de04 Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Mon, 16 Mar 2020 23:20:42 +0800 Subject: [PATCH 129/435] rectify changes --- .../java/resourceloader/StudyAreaLoader.java | 8 +---- src/main/java/resourceloader/TaskLoader.java | 2 -- text-ui-test/EXPECTED.TXT | 17 ++++++--- text-ui-test/dukeLogger.log | 36 +++++++++---------- text-ui-test/library/dictionary.txt | 10 ------ text-ui-test/library/locations.txt | 17 --------- text-ui-test/library/taskList.txt | 2 -- 7 files changed, 32 insertions(+), 60 deletions(-) delete mode 100644 text-ui-test/library/dictionary.txt delete mode 100644 text-ui-test/library/locations.txt delete mode 100644 text-ui-test/library/taskList.txt diff --git a/src/main/java/resourceloader/StudyAreaLoader.java b/src/main/java/resourceloader/StudyAreaLoader.java index 8989b3021..5fc00f85c 100644 --- a/src/main/java/resourceloader/StudyAreaLoader.java +++ b/src/main/java/resourceloader/StudyAreaLoader.java @@ -78,9 +78,8 @@ public ArrayList pushToDatabase() throws IllegalStudyAreaException, F * This method creates a new data file for locations.txt and dictionary.txt. * @param filePath this is the path of the data file to be created. * @throws IOException if cannot create file. - * @throws IllegalStudyAreaException if the data files cannot be set to read-only. */ - public static void createNewStudyAreaData(String filePath) throws IOException, IllegalStudyAreaException { + public static void createNewStudyAreaData(String filePath) throws IOException { Files.createFile(Paths.get(filePath)); PrintWriter dataBuffer = new PrintWriter(new File(filePath)); if (filePath.equals(FILE_PATH_STUDYAREAS)) { @@ -89,11 +88,6 @@ public static void createNewStudyAreaData(String filePath) throws IOException, I dataBuffer.println(BackUpData.BACKUP_DICTIONARY); } dataBuffer.close(); - File dataFile = new File(filePath); - boolean isLocked = dataFile.setWritable(false); - if (!isLocked) { - throw new IllegalStudyAreaException("Cannot make read-only"); - } } } diff --git a/src/main/java/resourceloader/TaskLoader.java b/src/main/java/resourceloader/TaskLoader.java index 54067b1ec..49480930d 100644 --- a/src/main/java/resourceloader/TaskLoader.java +++ b/src/main/java/resourceloader/TaskLoader.java @@ -145,8 +145,6 @@ private void createNewDataFile() { StudyAreaLoader.createNewStudyAreaData(FILE_PATH_DICTIONARY); } catch (IOException e) { e.printStackTrace(); - } catch (IllegalStudyAreaException e) { - System.out.println(e.getMessage()); } } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 8046f7941..284691a01 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -254,7 +254,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ __________________________________________________________ @@ -334,7 +334,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ Please enter the location for your desired study area. @@ -348,6 +348,15 @@ ________________________________________________________________________________ ________________________________________________________________________________________________ Here are the available study areas! __________________________________________________________ + Name: Starbucks + Address: 2 College Avenue West Education Resource Centre, + Ground Level + Faculty: Utown + Port: true + Indoor: true + Maximum number of Pax: 5 + __________________________________________________________ + __________________________________________________________ Name: MacCommons Address: 2 College Avenue West Education Resource Centre, Level 1 @@ -467,7 +476,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ __________________________________________________________ @@ -628,7 +637,7 @@ ________________________________________________________________________________ Ground Level Faculty: Utown Port: true - Indoor: false + Indoor: true Maximum number of Pax: 5 __________________________________________________________ __________________________________________________________ diff --git a/text-ui-test/dukeLogger.log b/text-ui-test/dukeLogger.log index 00d47c847..149f30871 100644 --- a/text-ui-test/dukeLogger.log +++ b/text-ui-test/dukeLogger.log @@ -1,36 +1,36 @@ -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:16:35 PM seedu.duke.Duke run INFO: Application started Execution -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:16:35 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 16, 2020 10:42:22 PM task.TaskList deleteTask +Mar 16, 2020 11:16:35 PM task.TaskList deleteTask INFO: Index specified to be deleted is out of bounds -Mar 16, 2020 10:42:22 PM task.Event getFieldToBeEdited +Mar 16, 2020 11:16:35 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 16, 2020 10:42:22 PM task.Event getFieldToBeEdited +Mar 16, 2020 11:16:35 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 16, 2020 10:42:22 PM task.Event parseDate +Mar 16, 2020 11:16:35 PM task.Event parseDate INFO: Date after current date exception thrown -Mar 16, 2020 10:42:22 PM task.Event editDate +Mar 16, 2020 11:16:35 PM task.Event editDate INFO: Invalid date entered by user -Mar 16, 2020 10:42:22 PM task.Deadline getFieldToBeEdited +Mar 16, 2020 11:16:35 PM task.Deadline getFieldToBeEdited INFO: Invalid option entered by user -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:16:35 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:16:35 PM seedu.duke.Duke run INFO: Application transitioning to study area mode -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkDuplicate +Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkDuplicate INFO: Duplicate flags entered by user -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkDuplicate +Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkDuplicate INFO: Duplicate flags entered by user -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkInteger +Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkInteger INFO: no string exist after "-s" -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkInteger +Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkInteger INFO: User entered an invalid number for integer input -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkOnlyFlag +Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkOnlyFlag INFO: Identifier not entered with flag by user -Mar 16, 2020 10:42:22 PM studyarea.StudyAreaList checkFlag +Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkFlag INFO: Wrong flag used by user while searching for study areas -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:16:35 PM seedu.duke.Duke run INFO: Application is going to exit -Mar 16, 2020 10:42:22 PM seedu.duke.Duke run +Mar 16, 2020 11:16:35 PM seedu.duke.Duke run INFO: Application closed successfully diff --git a/text-ui-test/library/dictionary.txt b/text-ui-test/library/dictionary.txt deleted file mode 100644 index e644c92a5..000000000 --- a/text-ui-test/library/dictionary.txt +++ /dev/null @@ -1,10 +0,0 @@ -engineering~eng~engin~engine~foe -utown~university town~u-town~u town -maccommons~mccommons~mac commons -education resource centre~erc -stephen riady centre~stephen~riady~src -ocbc~frank~frank by ocbc -starbucks~bucks~bux~sbux -pc commons~pccommons~pccommon -yih~yusof ishak~yusof~ishak -supersnacks~super snacks~super snack diff --git a/text-ui-test/library/locations.txt b/text-ui-test/library/locations.txt deleted file mode 100644 index cbe7dd5f6..000000000 --- a/text-ui-test/library/locations.txt +++ /dev/null @@ -1,17 +0,0 @@ -Opposite Town Green (Outside Starbucks)~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~4 -Starbucks~2 College Avenue West Education Resource Centre, Ground Level~Utown~true~false~5 -MacCommons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 -PC Commons~2 College Avenue West Education Resource Centre, Level 1~Utown~true~true~5 -Ian and Peony Ferguson Study~2 College Ave West Education Resource Centre, Level 3~Utown~true~true~4 -The Study~2 College Ave West Education Resource Centre, Level 2~Utown~true~true~5 -Town Plaza Seminar Rooms Waiting Area~2 College Ave West, Town Plaza, Level 2~Utown~true~true~4 -OCBC~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~false~2 -SuperSnacks~2 College Ave West, Stephen Riady Centre, Ground Level~Utown~true~true~4 -EA Level 1~9 Engineering Drive 1,EA, Level 1~Engineering~true~true~4 -EA Level 2~9 Engineering Drive 1,EA, Level 2~Engineering~true~true~4 -EA Level 3~9 Engineering Drive 1,EA, Level 3~Engineering~true~true~4 -EA Level 4~9 Engineering Drive 1,EA, Level 4, Outside Staff Offices~Engineering~true~false~6 -EA Level 5~9 Engineering Drive 1,EA, Level 5, Outside of the door beside EA05~Engineering~true~false~4 -EA Level 6~9 Engineering Drive 1,EA, Level 6, EA06-23~Engineering~true~true~4 -Central Library~Central Library 12 Kent Ridge Crescent~-~true~true~5 -YIH Study Room~Yusof Ishak House, Level 2~-~true~true~4 diff --git a/text-ui-test/library/taskList.txt b/text-ui-test/library/taskList.txt deleted file mode 100644 index a8754e4e2..000000000 --- a/text-ui-test/library/taskList.txt +++ /dev/null @@ -1,2 +0,0 @@ -D#assignment#2020-05-02#14:00#2 -E#team meeting#2020-06-06#12:00#13:00#1 From 851a62bda83a5b33266645926f48f2ca7c936b01 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Mon, 16 Mar 2020 23:23:47 +0800 Subject: [PATCH 130/435] Update runtest.bat file to auto delete library folder --- text-ui-test/runtest.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 00e635a0b..1d34d041f 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -7,7 +7,7 @@ if exist ..\library del ..\library cd .. call gradlew shadowJar -if exist ..\library del ..\library +if exist ..\library del ..\library /Q cd build\libs From 771a6a7927a3c6a59d2206e671319deef0f84d7e Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Mon, 16 Mar 2020 23:23:48 +0800 Subject: [PATCH 131/435] add changes --- dukeLogger.log | 36 ++++++++++++++++++++++++++++++++++++ text-ui-test/dukeLogger.log | 36 ++++++++++++++++++------------------ 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/dukeLogger.log b/dukeLogger.log index e69de29bb..af79ecf8e 100644 --- a/dukeLogger.log +++ b/dukeLogger.log @@ -0,0 +1,36 @@ +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run +INFO: Application started Execution +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run +INFO: Application transitioning to task mode +Mar 16, 2020 11:02:13 PM task.TaskList deleteTask +INFO: Index specified to be deleted is out of bounds +Mar 16, 2020 11:02:13 PM task.Event getFieldToBeEdited +INFO: Invalid option entered by user +Mar 16, 2020 11:02:13 PM task.Event getFieldToBeEdited +INFO: Invalid option entered by user +Mar 16, 2020 11:02:13 PM task.Event parseDate +INFO: Date after current date exception thrown +Mar 16, 2020 11:02:13 PM task.Event editDate +INFO: Invalid date entered by user +Mar 16, 2020 11:02:13 PM task.Deadline getFieldToBeEdited +INFO: Invalid option entered by user +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run +INFO: Application transitioning to task mode +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run +INFO: Application transitioning to study area mode +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkDuplicate +INFO: Duplicate flags entered by user +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkDuplicate +INFO: Duplicate flags entered by user +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkInteger +INFO: no string exist after "-s" +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkInteger +INFO: User entered an invalid number for integer input +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkOnlyFlag +INFO: Identifier not entered with flag by user +Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkFlag +INFO: Wrong flag used by user while searching for study areas +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run +INFO: Application is going to exit +Mar 16, 2020 11:02:13 PM seedu.duke.Duke run +INFO: Application closed successfully \ No newline at end of file diff --git a/text-ui-test/dukeLogger.log b/text-ui-test/dukeLogger.log index 149f30871..3ca40cbed 100644 --- a/text-ui-test/dukeLogger.log +++ b/text-ui-test/dukeLogger.log @@ -1,36 +1,36 @@ -Mar 16, 2020 11:16:35 PM seedu.duke.Duke run +Mar 16, 2020 11:19:24 PM seedu.duke.Duke run INFO: Application started Execution -Mar 16, 2020 11:16:35 PM seedu.duke.Duke run +Mar 16, 2020 11:19:24 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 16, 2020 11:16:35 PM task.TaskList deleteTask +Mar 16, 2020 11:19:24 PM task.TaskList deleteTask INFO: Index specified to be deleted is out of bounds -Mar 16, 2020 11:16:35 PM task.Event getFieldToBeEdited +Mar 16, 2020 11:19:24 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 16, 2020 11:16:35 PM task.Event getFieldToBeEdited +Mar 16, 2020 11:19:24 PM task.Event getFieldToBeEdited INFO: Invalid option entered by user -Mar 16, 2020 11:16:35 PM task.Event parseDate +Mar 16, 2020 11:19:24 PM task.Event parseDate INFO: Date after current date exception thrown -Mar 16, 2020 11:16:35 PM task.Event editDate +Mar 16, 2020 11:19:24 PM task.Event editDate INFO: Invalid date entered by user -Mar 16, 2020 11:16:35 PM task.Deadline getFieldToBeEdited +Mar 16, 2020 11:19:24 PM task.Deadline getFieldToBeEdited INFO: Invalid option entered by user -Mar 16, 2020 11:16:35 PM seedu.duke.Duke run +Mar 16, 2020 11:19:24 PM seedu.duke.Duke run INFO: Application transitioning to task mode -Mar 16, 2020 11:16:35 PM seedu.duke.Duke run +Mar 16, 2020 11:19:24 PM seedu.duke.Duke run INFO: Application transitioning to study area mode -Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkDuplicate +Mar 16, 2020 11:19:24 PM studyarea.StudyAreaList checkDuplicate INFO: Duplicate flags entered by user -Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkDuplicate +Mar 16, 2020 11:19:24 PM studyarea.StudyAreaList checkDuplicate INFO: Duplicate flags entered by user -Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkInteger +Mar 16, 2020 11:19:24 PM studyarea.StudyAreaList checkInteger INFO: no string exist after "-s" -Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkInteger +Mar 16, 2020 11:19:24 PM studyarea.StudyAreaList checkInteger INFO: User entered an invalid number for integer input -Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkOnlyFlag +Mar 16, 2020 11:19:24 PM studyarea.StudyAreaList checkOnlyFlag INFO: Identifier not entered with flag by user -Mar 16, 2020 11:16:35 PM studyarea.StudyAreaList checkFlag +Mar 16, 2020 11:19:24 PM studyarea.StudyAreaList checkFlag INFO: Wrong flag used by user while searching for study areas -Mar 16, 2020 11:16:35 PM seedu.duke.Duke run +Mar 16, 2020 11:19:24 PM seedu.duke.Duke run INFO: Application is going to exit -Mar 16, 2020 11:16:35 PM seedu.duke.Duke run +Mar 16, 2020 11:19:25 PM seedu.duke.Duke run INFO: Application closed successfully From bbb58b43579c118bbe756400f53474b816dba63d Mon Sep 17 00:00:00 2001 From: NizarMohd Date: Mon, 16 Mar 2020 23:25:42 +0800 Subject: [PATCH 132/435] add changes --- dukeLogger.log | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/dukeLogger.log b/dukeLogger.log index af79ecf8e..1a6aa740b 100644 --- a/dukeLogger.log +++ b/dukeLogger.log @@ -1,36 +1,8 @@ -Mar 16, 2020 11:02:13 PM seedu.duke.Duke run +Mar 16, 2020 11:25:14 PM seedu.duke.Duke run INFO: Application started Execution -Mar 16, 2020 11:02:13 PM seedu.duke.Duke run -INFO: Application transitioning to task mode -Mar 16, 2020 11:02:13 PM task.TaskList deleteTask -INFO: Index specified to be deleted is out of bounds -Mar 16, 2020 11:02:13 PM task.Event getFieldToBeEdited -INFO: Invalid option entered by user -Mar 16, 2020 11:02:13 PM task.Event getFieldToBeEdited -INFO: Invalid option entered by user -Mar 16, 2020 11:02:13 PM task.Event parseDate -INFO: Date after current date exception thrown -Mar 16, 2020 11:02:13 PM task.Event editDate -INFO: Invalid date entered by user -Mar 16, 2020 11:02:13 PM task.Deadline getFieldToBeEdited -INFO: Invalid option entered by user -Mar 16, 2020 11:02:13 PM seedu.duke.Duke run -INFO: Application transitioning to task mode -Mar 16, 2020 11:02:13 PM seedu.duke.Duke run +Mar 16, 2020 11:25:16 PM seedu.duke.Duke run INFO: Application transitioning to study area mode -Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkDuplicate -INFO: Duplicate flags entered by user -Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkDuplicate -INFO: Duplicate flags entered by user -Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkInteger -INFO: no string exist after "-s" -Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkInteger -INFO: User entered an invalid number for integer input -Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkOnlyFlag -INFO: Identifier not entered with flag by user -Mar 16, 2020 11:02:13 PM studyarea.StudyAreaList checkFlag -INFO: Wrong flag used by user while searching for study areas -Mar 16, 2020 11:02:13 PM seedu.duke.Duke run +Mar 16, 2020 11:25:27 PM seedu.duke.Duke run INFO: Application is going to exit -Mar 16, 2020 11:02:13 PM seedu.duke.Duke run -INFO: Application closed successfully \ No newline at end of file +Mar 16, 2020 11:25:27 PM seedu.duke.Duke run +INFO: Application closed successfully From 777c517abd9ff9e3f93d08d3a8fc5fadeb2f5b20 Mon Sep 17 00:00:00 2001 From: GanapathySanathBalaji Date: Sat, 21 Mar 2020 00:37:43 +0800 Subject: [PATCH 133/435] Add basic support for scheduling tasks --- dukeLogger.log | 8 +++ src/main/java/command/CreateSchedule.java | 49 +++++++++++++++ .../MisuseOfClearCommandException.java | 2 +- .../MisuseOfScheduleCommandException.java | 9 +++ ...sksToBeScheduledNotAnIntegerException.java | 9 +++ ...asksToBeScheduledNotPositiveException.java | 9 +++ src/main/java/parser/Parser.java | 18 ++---- src/main/java/task/SchedulableTask.java | 8 +++ src/main/java/task/TaskComparator.java | 11 ++++ src/main/java/task/TaskScheduler.java | 60 +++++++++++++++++++ src/main/java/ui/Constants.java | 13 ++-- 11 files changed, 176 insertions(+), 20 deletions(-) create mode 100644 src/main/java/command/CreateSchedule.java create mode 100644 src/main/java/exception/command/MisuseOfScheduleCommandException.java create mode 100644 src/main/java/exception/command/NumberOfTasksToBeScheduledNotAnIntegerException.java create mode 100644 src/main/java/exception/command/NumberOfTasksToBeScheduledNotPositiveException.java create mode 100644 src/main/java/task/SchedulableTask.java create mode 100644 src/main/java/task/TaskComparator.java create mode 100644 src/main/java/task/TaskScheduler.java diff --git a/dukeLogger.log b/dukeLogger.log index e69de29bb..524d2ed8c 100644 --- a/dukeLogger.log +++ b/dukeLogger.log @@ -0,0 +1,8 @@ +Mar 21, 2020 12:25:35 AM seedu.duke.Duke run +INFO: Application started Execution +Mar 21, 2020 12:25:38 AM seedu.duke.Duke run +INFO: Application transitioning to task mode +Mar 21, 2020 12:28:01 AM seedu.duke.Duke run +INFO: Application is going to exit +Mar 21, 2020 12:28:01 AM seedu.duke.Duke run +INFO: Application closed successfully diff --git a/src/main/java/command/CreateSchedule.java b/src/main/java/command/CreateSchedule.java new file mode 100644 index 000000000..79565e224 --- /dev/null +++ b/src/main/java/command/CreateSchedule.java @@ -0,0 +1,49 @@ +package command; + +import exception.command.MisuseOfScheduleCommandException; +import exception.command.NumberOfTasksToBeScheduledNotAnIntegerException; +import exception.command.NumberOfTasksToBeScheduledNotPositiveException; +import task.TaskList; +import task.TaskScheduler; +import ui.Ui; + +/** + * This command is used to create schedule based on user input if its feasible. + */ +public class CreateSchedule extends Command { + + TaskScheduler taskScheduler; + + /** + * Constructor for the CreateSchedule Object. + * Checks if the user given input follows the correct format and creates a new object. + * + * @param isOneWordCommand Denotes whether the user given input is single or multi worded. + * @param commandSplit Contains the information regarding the number of tasks to be scheduled. + * @throws Exception If the wrong format is used. + */ + public CreateSchedule(boolean isOneWordCommand, String[] commandSplit) throws Exception { + if (isOneWordCommand) { + throw new MisuseOfScheduleCommandException(); + } + try { + int numberOfTasksToSchedule = Integer.parseInt(commandSplit[1]); + if (numberOfTasksToSchedule <= 0) { + throw new NumberOfTasksToBeScheduledNotPositiveException(); + } + taskScheduler = new TaskScheduler(numberOfTasksToSchedule); + } catch (NumberFormatException e) { + throw new NumberOfTasksToBeScheduledNotAnIntegerException(); + } + } + + @Override + public void executeCommand(TaskList taskList, Ui ui) { + taskScheduler.getTasks(ui); + if(taskScheduler.scheduleTasks(ui)) { + ui.printMessage("Tasks successfully scheduled."); + } else { + ui.printMessage("Tasks couldn't be scheduled."); + } + } +} diff --git a/src/main/java/exception/command/MisuseOfClearCommandException.java b/src/main/java/exception/command/MisuseOfClearCommandException.java index f50e3b87b..475c67dba 100644 --- a/src/main/java/exception/command/MisuseOfClearCommandException.java +++ b/src/main/java/exception/command/MisuseOfClearCommandException.java @@ -4,6 +4,6 @@ public class MisuseOfClearCommandException extends CustomException { public MisuseOfClearCommandException() { - super("Wrong command clear events (Should be :clear )"); + super("Wrong command to clear events (Should be :clear )"); } } diff --git a/src/main/java/exception/command/MisuseOfScheduleCommandException.java b/src/main/java/exception/command/MisuseOfScheduleCommandException.java new file mode 100644 index 000000000..d7bd294a6 --- /dev/null +++ b/src/main/java/exception/command/MisuseOfScheduleCommandException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class MisuseOfScheduleCommandException extends CustomException { + public MisuseOfScheduleCommandException() { + super("Wrong command to create schedule events (Should be :schedule )"); + } +} diff --git a/src/main/java/exception/command/NumberOfTasksToBeScheduledNotAnIntegerException.java b/src/main/java/exception/command/NumberOfTasksToBeScheduledNotAnIntegerException.java new file mode 100644 index 000000000..8dff72ddc --- /dev/null +++ b/src/main/java/exception/command/NumberOfTasksToBeScheduledNotAnIntegerException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class NumberOfTasksToBeScheduledNotAnIntegerException extends CustomException { + public NumberOfTasksToBeScheduledNotAnIntegerException() { + super("Number of tasks to be scheduled as mentioned is not an integer"); + } +} \ No newline at end of file diff --git a/src/main/java/exception/command/NumberOfTasksToBeScheduledNotPositiveException.java b/src/main/java/exception/command/NumberOfTasksToBeScheduledNotPositiveException.java new file mode 100644 index 000000000..1989f7715 --- /dev/null +++ b/src/main/java/exception/command/NumberOfTasksToBeScheduledNotPositiveException.java @@ -0,0 +1,9 @@ +package exception.command; + +import exception.CustomException; + +public class NumberOfTasksToBeScheduledNotPositiveException extends CustomException { + public NumberOfTasksToBeScheduledNotPositiveException() { + super("Number of tasks to be scheduled as mentioned is not a positive integer"); + } +} \ No newline at end of file diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java index 64914e5cf..f7cfcd23a 100644 --- a/src/main/java/parser/Parser.java +++ b/src/main/java/parser/Parser.java @@ -1,16 +1,6 @@ package parser; -import command.AddDeadlineCommand; -import command.AddEventCommand; -import command.ClearCommand; -import command.Command; -import command.CountdownCommand; -import command.DeleteCommand; -import command.EditCommand; -import command.HelpCommand; -import command.PriorityViewCommand; -import command.SearchCommand; -import command.ViewCommand; +import command.*; /** * This class is used to parse the user input into executable commands. @@ -28,6 +18,7 @@ public class Parser { public static final String EDIT_COMMAND = "edit"; public static final String EMPTY_COMMAND = ""; public static final String HELP_COMMAND = "help"; + public static final String CREATE_SCHEDULE_COMMAND = "schedule"; /** * This method takes in the user input parses it and returns the command to be executed. @@ -39,7 +30,7 @@ public Command parseCommand(String fullCommand) throws Exception { String[] commandSplit = fullCommand.split(" ",2); String commandType = commandSplit[0]; - Command command; + Command command = null; boolean isOneWordCommand = commandSplit.length == 1 || commandSplit[1].isBlank(); switch (commandType) { case ADD_DEADLINE_COMMAND: @@ -72,6 +63,9 @@ public Command parseCommand(String fullCommand) throws Exception { case HELP_COMMAND: command = new HelpCommand(isOneWordCommand); break; + case CREATE_SCHEDULE_COMMAND: + command = new CreateSchedule(isOneWordCommand, commandSplit); + break; case EMPTY_COMMAND: throw new Exception("Empty Line entered, Please enter a valid line"); // Break statement can't be reached if added diff --git a/src/main/java/task/SchedulableTask.java b/src/main/java/task/SchedulableTask.java new file mode 100644 index 000000000..612790d1b --- /dev/null +++ b/src/main/java/task/SchedulableTask.java @@ -0,0 +1,8 @@ +package task; + +public class SchedulableTask { + + public int numberOfDaysLeft; + public int numberOfDaysRequiredToFinishTask; + +} diff --git a/src/main/java/task/TaskComparator.java b/src/main/java/task/TaskComparator.java new file mode 100644 index 000000000..f16323d07 --- /dev/null +++ b/src/main/java/task/TaskComparator.java @@ -0,0 +1,11 @@ +package task; + +import java.util.Comparator; + +public class TaskComparator implements Comparator { + + @Override + public int compare(SchedulableTask schedulableTask1, SchedulableTask schedulableTask2) { + return schedulableTask1.numberOfDaysLeft - schedulableTask2.numberOfDaysLeft; + } +} diff --git a/src/main/java/task/TaskScheduler.java b/src/main/java/task/TaskScheduler.java new file mode 100644 index 000000000..064a4abad --- /dev/null +++ b/src/main/java/task/TaskScheduler.java @@ -0,0 +1,60 @@ +package task; + +import ui.Constants; +import ui.Ui; + +import java.time.LocalDate; +import java.util.PriorityQueue; + +public class TaskScheduler { + + private int numberOfTasksToSchedule; + private PriorityQueue taskQueue; + + public TaskScheduler(int numberOfTasksToSchedule) { + this.numberOfTasksToSchedule = numberOfTasksToSchedule; + this.taskQueue = new PriorityQueue<>(numberOfTasksToSchedule, new TaskComparator()); + } + + public void getTasks(Ui ui) { + ui.printLine(); + ui.printMessage("Enter tasks in the following format:"); + ui.printMessage("