-
Notifications
You must be signed in to change notification settings - Fork 435
[Tan Hin Khai Stephen] iP #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
blackonyyx
wants to merge
44
commits into
nus-cs2103-AY2021S1:master
Choose a base branch
from
blackonyyx:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
3b19ba1
Add Gradle support
04795bd
Level 1 added
blackonyyx af52847
Level 2 is here
blackonyyx 6dbdb55
Level 3
blackonyyx 00166f5
A-Classes used classes to represent tasks
blackonyyx 962693b
Added Inheritance for tasks and managed tasks via manager
blackonyyx 69ac44d
Added sh script automated testing
blackonyyx 379eb1c
Added Enums, Packaged Related classes together, Error handling
blackonyyx 8e70ce3
Added Delete command to the list of supported commands
blackonyyx 7287ce9
Added IO file handling to the Chatbot Application such that the Chatbot
blackonyyx cd26774
Added datetime parsing to the TimedTask Classes
blackonyyx 25b8c2a
Merge branch 'branch-Level-8'
blackonyyx f909eb3
More OOP
blackonyyx b90a157
1. Add jUnit Testing on Timed Task and TextParser Class
blackonyyx 04db2ff
Branch for Level 9 of Duke Project.
blackonyyx 8ad3c66
Make Code adheres to java code standards of module.
blackonyyx 5a72d63
Add javadocs for all constructors and class headers,
blackonyyx 535afe7
Merge branch 'A-JavaDoc' of https://github.com/blackonyyx/ip
blackonyyx f7f5414
Merge branch 'branch-Level-9' of https://github.com/blackonyyx/ip
blackonyyx 08208e0
Merge branch 'add-gradle-support' of https://github.com/blackonyyx/ip
blackonyyx 6261301
Add gradle integration into master branch.
blackonyyx 454fbd2
Enforced CheckStyle on all violating code blocks
blackonyyx 0c58a00
Add a GUI for the Duke Application
blackonyyx bf97679
Add Major overhaul and refactor of code base to follow a more functional
blackonyyx 4ab281c
Add new refactoring of GUI to have better feel.
blackonyyx ad6ee84
Amend Code to conform with Checkstyle requirements.
blackonyyx 34dc6db
Minor String Formatting modifications
blackonyyx 1cabdc8
Merge pull request #1 from blackonyyx/branch-A-Assertions
blackonyyx fa1e1bb
Minor Code Formatting modifications
blackonyyx 26295c2
Merge branch 'master' into branch-A-CodeQuality
blackonyyx 97fccd0
Create gradle.yml
blackonyyx 58e7cc9
Merge pull request #4 from blackonyyx/Continuous-Integ-2
blackonyyx 3ae73c5
Merge pull request #3 from blackonyyx/branch-A-CodeQuality
blackonyyx 42861a1
stuff
blackonyyx 0371616
Merge branch 'master' of https://github.com/blackonyyx/ip
blackonyyx 9caac97
Amend Code to contain less this.<attribute / method> to conform with the
blackonyyx 4f15860
Add User Guide to the project repository and update README.md to reflect
blackonyyx 40edbce
Add README.md and Userguide help.
blackonyyx e4d5cf5
Set theme jekyll-theme-dinky
blackonyyx c94b6d0
Merge branch 'master' of https://github.com/blackonyyx/ip
blackonyyx ec13865
Add README.md and Userguide help.
blackonyyx b45c888
Set theme jekyll-theme-dinky
blackonyyx bb34eff
Removed boiler plate code
blackonyyx c275aea
Merge branch 'master' of https://github.com/blackonyyx/ip
blackonyyx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import exceptions.DukeException; | ||
| import exceptions.DukeIOException; | ||
| import exceptions.DukeUnknownException; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| /** | ||
| * Front End Facing Script for the UI of ChatbotApplication | ||
| */ | ||
| public class ChatbotApplication { | ||
| private final String linebreaker; | ||
| Duke dukeProgram; | ||
| boolean isChatbotRunning; | ||
|
|
||
| /** | ||
| * Constructor class of the ChatbotApplication | ||
| * @param linebreaker the display aesthetic of the output from Duke | ||
| * @param pth the path to read a file from. | ||
| */ | ||
| ChatbotApplication(String linebreaker, String pth){ | ||
| dukeProgram = new Duke(pth); | ||
| isChatbotRunning = true; | ||
| this.linebreaker = linebreaker.repeat(50) + "\n"; | ||
| } | ||
|
|
||
| /** | ||
| * Takes a scanner object as user input and initialises the dukeLoop | ||
| * @param sc UserInput for the Application. | ||
| */ | ||
| public void dukeLoop(Scanner sc) { | ||
| print("Please Enter your name"); | ||
| String name = sc.nextLine(); | ||
| print(dukeProgram.greeting(name)); | ||
| String in = ""; | ||
| String out = ""; | ||
| while (this.isRunning()) { | ||
| in = sc.nextLine(); | ||
| try { | ||
| out = dukeProgram.takeInput(in); | ||
| if (Boolean.parseBoolean(out)) { | ||
| this.setChatbotRunning(false); | ||
| } else { | ||
| print(out); | ||
| } | ||
| } catch (DukeUnknownException e) { | ||
| print(e.toString()); | ||
| this.setChatbotRunning(false); | ||
| } catch (DukeException e) { | ||
| print(e.toString()); | ||
| } | ||
| } | ||
| try { | ||
| dukeProgram.saveTasks(); | ||
| } catch (DukeIOException e) { | ||
| print(e.toString()); | ||
| } | ||
| sc.close(); | ||
| print(dukeProgram.goodbye(name)); | ||
| } | ||
|
|
||
| /** | ||
| * Running state of the Duke Application | ||
| * @return State of Duke running | ||
| */ | ||
| private boolean isRunning() { | ||
| return this.isChatbotRunning; | ||
| } | ||
|
|
||
| /** | ||
| * Wraps all text output and prints to the console | ||
| * @param s String output | ||
| */ | ||
| private void print(String s){ | ||
| System.out.printf("%s%s\n%s%n",linebreaker,s,linebreaker); | ||
| } | ||
|
|
||
| /** | ||
| * Setter for the status of the Chatbot Object | ||
| * @param b toggle on or off for chatbot | ||
| */ | ||
| private void setChatbotRunning(boolean b){ | ||
| this.isChatbotRunning = b; | ||
| } | ||
| /** | ||
| * Execution Class to contain main loop | ||
| * @param args args | ||
| */ | ||
| public static void main(String[] args) { | ||
| Scanner sc = new Scanner(System.in); | ||
| //System.out.println("What is your name?"); | ||
| String path = System.getProperty("user.dir"); | ||
| ChatbotApplication d = new ChatbotApplication("##", path); | ||
| // To refactor ChatbotApplication to hold mainloop such that UI elements to be added in future | ||
| // can be interactive with the application through ChatbotApplication class directly. | ||
| d.dukeLoop(sc); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,143 @@ | ||
| public class Duke { | ||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| import exceptions.*; | ||
| import tasks.Command; | ||
| import tasks.TaskManager; | ||
| import tasks.TextParser; | ||
|
|
||
| /** | ||
| * Backend Object Class for the Duke Chatbot Interface | ||
| */ | ||
| class Duke { | ||
| private final TaskManager taskManager; | ||
| private final TextParser textParser; | ||
|
|
||
| /** | ||
| * Constructor for the Duke Chatbot, if is old initialisation, will read from txt file | ||
| * Eles it will initialise a new TaskManager class | ||
| * @param path The path of the home initialisation. | ||
| */ | ||
| public Duke(String path) { | ||
| TaskManager list1; | ||
| try { | ||
| list1 = new TaskManager(path); | ||
| } catch (DukeIOException e) { | ||
| list1 = new TaskManager(path, true); | ||
| } | ||
| this.textParser = new TextParser(); | ||
| this.taskManager = list1; | ||
| } | ||
|
|
||
| /** | ||
| * Manages all internal dataflow from Main or textual interaction | ||
| * with the chatbot, by cleaning it | ||
| * @param input User Input from the UI | ||
| * @return String form of command to output to UI | ||
| * @throws DukeException when there is an exception thrown | ||
| */ | ||
| public String takeInput(String input) throws DukeException { | ||
| //To prevent an Security Concern or Code Injection Cleaning of text is first performed and authenticated | ||
| // by adding an ending token | ||
| //TODO eventually to convert the input -> Command with getter for task, deadline(if applicable) | ||
| String cleaned = cleanInput(input); | ||
| // There is minimally a sep | ||
| String[] words = cleaned.split(" "); | ||
| cleaned = cleaned.replace(" [sep]", ""); | ||
| // Take out command from the words | ||
| String text_input = cleaned.replaceFirst(words[0], ""); | ||
| //Sep token is added to prevent index errors | ||
| Command c = textParser.parseCommand(words[0]); | ||
|
|
||
| switch (c) { | ||
| case BYE: | ||
| return Boolean.TRUE.toString(); | ||
| case HELP: | ||
| return this.help(); | ||
| case DONE: | ||
| return taskManager.doTask(words[1]); | ||
| case DELETE: | ||
| return taskManager.deleteTask(words[1]); | ||
| case LIST: | ||
| return taskManager.parseoutput(); | ||
| case SEARCH: | ||
| return taskManager.findTasks(words[1]); | ||
| case TODO: | ||
| return this.taskManager.addToDo(text_input); | ||
| case DEADLINE: | ||
| return this.taskManager.addDeadline(text_input); | ||
| case EVENT: | ||
| return this.taskManager.addEvent(text_input); | ||
| case BLANK: | ||
| throw new DukeBlankCommandException("''"); | ||
| case ERROR: | ||
| throw new DukeCommandException(words[0]); | ||
| default: | ||
| throw new DukeUnknownException(text_input); | ||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * inputs string, processes and cleans the text for the chatbot | ||
| * via adding a ending token seperator | ||
| * @param userInput Direct user input of the string | ||
| * @return Cleaned user input | ||
| */ | ||
| private String cleanInput(String userInput) { | ||
| return userInput + " [sep]"; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a help message about all commands supported by Duke | ||
| * @return help message | ||
| */ | ||
| public String help() { | ||
| //eventually to add command help <command> | ||
| return "\t Need some help huh?\n" + | ||
| "\t Heres a list of my commands!\n" + | ||
| "\t- 'bye' to close the application\n" + | ||
| "\t- 'list' to list the current list of tasks and their statuses\n" + | ||
| "\t- 'done' to set a task as done\n" + | ||
| "\t- 'find' to find a task using regex or a query text string\n" + | ||
| "\t- 'todo' to list a untimed task\n" + | ||
| "\t- 'deadline' to list a timed deadline task, please structure with " + | ||
| "[deadline <task name> /by dd-MM-YYYY]\n" + | ||
| "\t- 'event' to list a timed event task, please structure with [event <task name> /at dd-MM-YYYY]\n" + | ||
| "\t- 'help' to list these commands again\n"; | ||
| } | ||
|
|
||
| /** | ||
| * Greeting from Duke Bot | ||
| * @param name Name of the user | ||
| * @return Sends a greeting from dukebot to the user | ||
| */ | ||
| String greeting(String name) { | ||
|
|
||
| String logo = "\tHello from\n" + | ||
| " ____ _ \n" + | ||
| "| _ \\ _ _| | _____ \n" + | ||
| "| | | | | | | |/ / _ \\\n" + | ||
| "| |_| | |_| | < __/\n" + | ||
| "|____/ \\__,_|_|\\_\\___|\n" + | ||
| "\tHello! I'm Duke\n\tWhat can I do for you " + | ||
| name + | ||
| "\n"; | ||
| return logo; | ||
| } | ||
|
|
||
| /** | ||
| * Goodbye from DukeBot | ||
| * @param name Name of the user | ||
| * @return Sends a goodbye message from dukebot to the user | ||
| */ | ||
| String goodbye(String name){ | ||
| return "Bye " + name +"! Hope to see you again soon!"; | ||
| } | ||
|
|
||
| /** | ||
| * Message passing from mainloop to save tasks. | ||
| * @throws DukeIOException if something goes wrong with the IO Savefiles | ||
| */ | ||
| void saveTasks() throws DukeIOException { | ||
| this.taskManager.saveTasks(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Manifest-Version: 1.0 | ||
| Main-Class: ChatbotApplication | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package exceptions; | ||
|
|
||
| /** | ||
| * Error Type of a Blank Command in Duke Application. | ||
| */ | ||
| public class DukeBlankCommandException extends DukeException{ | ||
| /** | ||
| * Constructor for DukeBlankCommandException for a blank command | ||
| * @param s String form of the bad input | ||
| */ | ||
| public DukeBlankCommandException(String s){ | ||
| super(s,4); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package exceptions; | ||
|
|
||
| /** | ||
| * Error Type of a Invalid Command in Duke Application. | ||
| */ | ||
| public class DukeCommandException extends DukeException { | ||
| /** | ||
| * Constructor class for DukeCommandException | ||
| * @param bad_cmd the command that is unrecognisable by Duke Application | ||
| */ | ||
| public DukeCommandException(String bad_cmd) { | ||
blackonyyx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| super(bad_cmd, 1); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package exceptions; | ||
|
|
||
| /** | ||
| * Error Type of a DateTimeError in Duke Application. | ||
| * This error is thrown if the DateTime does not match or is incompatible with the DateTimeFormatter | ||
| */ | ||
| public class DukeDateTimeException extends DukeException { | ||
| /** | ||
| * Constructor class for DukeDateTimeException | ||
| * @param cmd the invalid command | ||
| */ | ||
| public DukeDateTimeException(String cmd){ | ||
| super(cmd,3); | ||
| } | ||
|
|
||
| /** | ||
| * Takes in the given bad input and the code | ||
| * @return String | ||
| */ | ||
| public String message(String s) { | ||
| StringBuilder b = new StringBuilder(); | ||
| b.append("\t Oops you did not mark your datetime! Not sure what you mean by:\n"); | ||
| b.append("\t ").append(bad_cmd).append("\n"); | ||
| b.append("\t ").append(s); | ||
| b.append(": ").append(code.toString()).append("\n"); | ||
| b.append("\t Heres a tip, use the 'help' command to learn about my commands!\n"); | ||
| return b.toString(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package exceptions; | ||
|
|
||
| /** | ||
| * DukeException is a classification of errors that pertain to any running problems within Duke Class applications | ||
| * Some errors that may occur in the hierarchy of data flow: | ||
| * 1. FileRead Error (WIP): For handling stored memory and I/O errors | ||
| * 2. Bad Command Given: When a Command that is unknown is given | ||
| * 3. No Input given: When in the flow for a given command, no description is detected | ||
| * 4. Bad Date Given: For handling datetime parsing errors. | ||
| * 5. Blank Command Given: For handling when a Blank command is given to a input. | ||
| * 6. Index Error: When a invalid index is given | ||
| * 7. UnknownException: For handling anything exceptionally unexpected | ||
| */ | ||
blackonyyx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public abstract class DukeException extends Exception { | ||
|
|
||
| String bad_cmd; | ||
| ErrorEncode code; | ||
blackonyyx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Constructor class for a Generic DukeException for any errortype encountered in Duke | ||
blackonyyx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @param bad_cmd The command or user input that is causing the error | ||
| * @param code The enumeration to encode the error message. | ||
| */ | ||
| protected DukeException(String bad_cmd, int code){ | ||
| this.bad_cmd = bad_cmd; | ||
| this.code = ErrorEncode.parseCode(code); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the template user error message of the DukeException class | ||
| * @return String message to be printed out to player. | ||
| */ | ||
| public String message(String s) { | ||
| StringBuilder b = new StringBuilder(); | ||
| b.append("\t Oops you used a invalid command! Not sure what you mean by:\n"); | ||
| b.append("\t ").append(bad_cmd).append("\n"); | ||
| b.append("\t ").append(s); | ||
| b.append(": ").append(code.toString()).append("\n"); | ||
| b.append("\t Heres a tip, use the 'help' command to learn about my commands!\n"); | ||
| return b.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
|
|
||
| return message(super.toString()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package exceptions; | ||
|
|
||
| /** | ||
| * Error type for I/O that appear when trying to perform a read or write command. | ||
| */ | ||
| public class DukeIOException extends DukeException{ | ||
| /** | ||
| * Constructor for I/O exception class. | ||
| * @param bad_cmd the part of the I/O process that is causing an error | ||
| */ | ||
| public DukeIOException(String bad_cmd){ | ||
| super(bad_cmd, 0); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.