Skip to content

Commit

Permalink
Pass checkstyle, add new jar file
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybunny123 committed Sep 15, 2020
1 parent 476560f commit b8c91d1
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 61 deletions.
13 changes: 9 additions & 4 deletions src/main/java/duke/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ public String formattedDateString() {
return "[D]" + super.toString() + " (by: " + formattedDate + ")";
}

/**
* Returns the Deadline description, formatted date, and tags to the user.
*
* @return Deadline description, date and tags.
*/
public String formattedDateStringWithTags() {
return "[D]" + super.toString() + " (at: " + formattedDate + ")" +
(this.tags.size() == 0 ? "" :"\ntags: " + super.getTags());
return "[D]" + super.toString() + " (at: " + formattedDate + ")"
+ (this.tags.size() == 0 ? "" : "\ntags: " + super.getTags());
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")" +
(this.tags.size() == 0 ? "" :"\ntags: " + super.getTags());
return "[D]" + super.toString() + " (by: " + by + ")"
+ (this.tags.size() == 0 ? "" : "\ntags: " + super.getTags());
}
}
13 changes: 9 additions & 4 deletions src/main/java/duke/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ public String formattedDateString() {
return "[E]" + super.toString() + " (at: " + formattedDate + ")";
}

/**
* Returns the Event description, formatted date and tags to the user.
*
* @return Event description, data and tags
*/
public String formattedDateStringWithTags() {
return "[E]" + super.toString() + " (at: " + formattedDate + ")" +
(this.tags.size() == 0 ? "" :"\ntags: " + super.getTags());
return "[E]" + super.toString() + " (at: " + formattedDate + ")"
+ (this.tags.size() == 0 ? "" : "\ntags: " + super.getTags());
}

@Override
public String toString() {
return "[E]" + super.toString() + " (at: " + start + ")" +
(this.tags.size() == 0 ? "" :"\ntags: " + super.getTags());
return "[E]" + super.toString() + " (at: " + start + ")"
+ (this.tags.size() == 0 ? "" : "\ntags: " + super.getTags());
}
}
4 changes: 2 additions & 2 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static String executeTagCommand(
if (index > tasks.size() || index < 0) {
throw new DukeException("That task number does not exist.");
}
Tag tag = Tag.StringToTag(userInputWords[2]);
Tag tag = Tag.stringToTag(userInputWords[2]);
tasks.get(index - 1).addTag(tag);
Task t = tasks.get(index - 1);
ArrayList<Task> tasksCopy = tasks.clone();
Expand Down Expand Up @@ -262,7 +262,7 @@ public static String parse(String inputted, TaskList tasks) throws DukeException
return executeDeleteCommand(userInputWords, tasks);
} else if (userInputWords.length == 2 && userInputWords[0].equals(FIND_COMMAND)) {
return executeFindCommand(userInputWords, tasks);
} else if (userInputWords.length == 2 && userInputWords[0].equals(FIND_TAG_COMMAND)) {
} else if (userInputWords.length == 2 && userInputWords[0].equals(FIND_TAG_COMMAND)) {
return executeFindTagCommand(userInputWords, tasks);
} else if (userInputWords.length == 3 && userInputWords[0].equals(TAG_COMMAND)) {
return executeTagCommand(userInputWords, tasks);
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public TaskList load() throws DukeException {
break;
case (TAG):
String[] tags = task.split(" ");
TAG_COMMAND(loadedTasks, tags);
tagCommand(loadedTasks, tags);
break;
default:
throw new DukeException("I'm sorry, something went wrong!");
Expand All @@ -152,10 +152,17 @@ public TaskList load() throws DukeException {
return new TaskList(loadedTasks);
}

public void TAG_COMMAND(ArrayList<Task> tasks, String[] tags) throws DukeException {
/**
* Adds the tags to the rightmost task.
*
* @param tasks Loaded tasks from tasks.txt
* @param tags Array of tags.
* @throws DukeException If one of the tags in the file do not exist.
*/
public void tagCommand(ArrayList<Task> tasks, String[] tags) throws DukeException {
for (int i = 1; i < tags.length; i++) {
String tag = tags[i].substring(1).toLowerCase();
Tag tagToBeAdded = Tag.StringToTag(tag);
Tag tagToBeAdded = Tag.stringToTag(tag);
int indexToAddTags = tasks.size() - 1;
tasks.get(indexToAddTags).addTag(tagToBeAdded);
}
Expand Down
83 changes: 47 additions & 36 deletions src/main/java/duke/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,58 @@
public enum Tag {
FUN, BORING, EXCITING, URGENT, CHILL, SIAN, LAZE, DUMMY;

public static Tag StringToTag(String input) throws DukeException {
/**
* Converts the input string into a Tag.
*
* @return The tag corresponding to the input string.
* @throws DukeException If Duke does not recognise the specified tag.
*/
public static Tag stringToTag(String input) throws DukeException {
switch (input) {
case "fun":
return FUN;
case "boring":
return BORING;
case "exciting":
return EXCITING;
case "urgent":
return URGENT;
case "chill":
return CHILL;
case "sian":
return SIAN;
case "laze":
return LAZE;
case "dummy":
return DUMMY;
default:
throw new DukeException("Sorry, Duke does not recognise that tag name :(");
case "fun":
return FUN;
case "boring":
return BORING;
case "exciting":
return EXCITING;
case "urgent":
return URGENT;
case "chill":
return CHILL;
case "sian":
return SIAN;
case "laze":
return LAZE;
case "dummy":
return DUMMY;
default:
throw new DukeException("Sorry, Duke does not recognise that tag name :(");
}
}

public static String TagToString(Tag tag) {
/**
* Converts the input tag into a String.
*
* @return The string corresponding to the input tag.
*/
public static String tagToString(Tag tag) {
switch (tag) {
case FUN:
return "fun";
case BORING:
return "boring";
case EXCITING:
return "exciting";
case URGENT:
return "urgent";
case CHILL:
return "chill";
case SIAN:
return "sian";
case LAZE:
return "laze";
default:
return "dummy";
case FUN:
return "fun";
case BORING:
return "boring";
case EXCITING:
return "exciting";
case URGENT:
return "urgent";
case CHILL:
return "chill";
case SIAN:
return "sian";
case LAZE:
return "laze";
default:
return "dummy";
}
}
}
21 changes: 18 additions & 3 deletions src/main/java/duke/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public Task(String description) {
}

/**
* Returns a tick if task is completed, a cross if otherwise.
* Returns an "O" if task is completed, an "X" if otherwise.
*
* @return Tick if completed, cross if not.
* @return "O" if completed, "X" if not.
*/
public String getStatusIcon() {
return (isDone ? "O" : "X");
Expand All @@ -31,6 +31,11 @@ public String getDescription() {
return this.description;
}

/**
* Returns all the tags tagged to the task.
*
* @return The tasks tagged to the task.
*/
public String getTags() {
String response = "";
for (Tag tag : tags) {
Expand All @@ -39,19 +44,29 @@ public String getTags() {
return response;
}

/**
* Adds a tag to the task.
*/
public void addTag(Tag tag) {
this.tags.add(tag);
}

/**
* Removes the specified tag from the task if it exists.
*
* @param tagString The specified tag.
* @return Returns 1 if tag was found and removed, 0 if tag was not found.
*/
public int removeTag(String tagString) {
for (int i = 0; i < this.tags.size(); i++) {
if (Tag.TagToString(this.tags.get(i)).equals(tagString)) {
if (Tag.tagToString(this.tags.get(i)).equals(tagString)) {
this.tags.remove(i);
return 1;
}
}
return 0;
}

/**
* Sets the task to be completed.
*/
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/duke/ToDo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@ public ToDo(String description) {
super(description);
}

/**
* Returns the Todo description to the user.
*
* @return Todo description.
*/
public String formattedDateString() {
return "[T]" + super.toString();
}

/**
* Returns the Todo description and tags to the user.
*
* @return Todo description with tags.
*/
public String formattedDateStringWithTags() {
return toString();
}

@Override
public String toString() {
return "[T]" + super.toString() +
(this.tags.size() == 0 ? "" :"\ntags: " + super.getTags());
return "[T]" + super.toString()
+ (this.tags.size() == 0 ? "" : "\ntags: " + super.getTags());
}
}
27 changes: 24 additions & 3 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void greeting() {
/**
* Simulates an exit event when the user inputs the bye command.
*
* @return Returns "Bye" if the user inputs the bye command.
* @return Returns a response to the user.
*/
public String goodbye() {
return "Bye! Hope to see you again soon!";
Expand All @@ -35,6 +35,7 @@ public String goodbye() {
* Displays the user's current task list.
*
* @param tasks The current TaskList of the User.
* @return Returns the user's current task list.
*/
public String list(TaskList tasks) {
if (tasks.size() == 0) {
Expand All @@ -49,6 +50,12 @@ public String list(TaskList tasks) {
}
}

/**
* Displays the user's current task list and their respective tags.
*
* @param tasks The current TaskList of the User.
* @return Returns the user's current task list and their respective tags..
*/
public String showTags(TaskList tasks) {
if (tasks.size() == 0) {
return "There are no tasks in your list yet.";
Expand All @@ -66,6 +73,7 @@ public String showTags(TaskList tasks) {
* Notifies the user that the specified task has been marked done.
*
* @param t The specified task that was marked done.
* @return Returns a response to the user that the specified task has been marked done.
*/
public String done(Task t) {
String response = "Nice! I've marked this task as done:";
Expand All @@ -77,6 +85,7 @@ public String done(Task t) {
* Notifies the user that the specified task has been tagged.
*
* @param t The specified task that was marked done.
* @return Returns a response to the user that the specified task has been tagged.
*/
public String tag(Task t, Tag tag) {
String response = "Nice! I've tagged this task with " + tag + ":";
Expand All @@ -90,6 +99,7 @@ public String tag(Task t, Tag tag) {
*
* @param t The specified task that was deleted.
* @param size The number of tasks in the TaskList.
* @return Returns a response to the user.
*/
public String delete(Task t, int size) {
String response = "Noted. I've removed this task:";
Expand All @@ -104,6 +114,7 @@ public String delete(Task t, int size) {
*
* @param t The specified task that was added.
* @param size The number of tasks in the TaskList.
* @return Returns a response to the user.
*/
public String add(Task t, int size) {
String response = "Got it. I've added this task:";
Expand All @@ -116,6 +127,7 @@ public String add(Task t, int size) {
* Displays the tasks in the user's TaskList that match the input string.
*
* @param tasks The list of Tasks that contains the input string.
* @return Returns the tasks in the user's TaskList that match the input string.
*/
public String find(ArrayList<Task> tasks) {
if (tasks.size() == 0) {
Expand All @@ -131,9 +143,10 @@ public String find(ArrayList<Task> tasks) {
}

/**
* Displays the tasks in the user's TaskList that match the input string.
* Displays the tasks in the user's TaskList that match the input tag.
*
* @param tasks The list of Tasks that contains the input string.
* @param tasks The list of Tasks that contains the input tag.
* @return Returns the tasks in the user's TaskList that match the input tag.
*/
public String findTag(ArrayList<Task> tasks) {
if (tasks.size() == 0) {
Expand Down Expand Up @@ -169,6 +182,14 @@ public void initializeDukeUI(TaskList tasks) {
}
}

/**
* Notifies the user if the specified tag of the specified task was removed.
*
* @param t The specified task.
* @param isTagRemoved If the tag is removed or not
* @param tagRemoved The tag that was removed (if any)
* @return Returns a response to the user.
*/
public String removeTag(Task t, boolean isTagRemoved, String tagRemoved) {
if (!isTagRemoved) {
return "The specified task does not have the specified tag: " + tagRemoved;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/duke/DeadlineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ void recordString() {
Deadline readBook = new Deadline("read book", "2020-01-01");
Deadline notReadBook = new Deadline("not read book", "2020-01-01");
readBook.setDone();
assertEquals("[D][✓] read book (by: Jan 01 2020)", readBook.recordString());
assertEquals("[D][✘] not read book (by: Jan 01 2020)", notReadBook.recordString());
assertEquals("[D][✓] read book (by: Jan 01 2020)", readBook.formattedDateString());
assertEquals("[D][✘] not read book (by: Jan 01 2020)", notReadBook.formattedDateString());
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/duke/EventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ void recordString() {
Event readBook = new Event("read book", "2020-01-01");
Event notReadBook = new Event("not read book", "2020-01-01");
readBook.setDone();
assertEquals("[E][✓] read book (at: Jan 01 2020)", readBook.recordString());
assertEquals("[E][✘] not read book (at: Jan 01 2020)", notReadBook.recordString());
assertEquals("[E][✓] read book (at: Jan 01 2020)", readBook.formattedDateString());
assertEquals("[E][✘] not read book (at: Jan 01 2020)", notReadBook.formattedDateString());
}

@Test
Expand Down

0 comments on commit b8c91d1

Please sign in to comment.