Skip to content

Commit

Permalink
Merge branch 'branch-Level-9'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/duke/task/Task.java
#	src/main/java/duke/task/TaskList.java
  • Loading branch information
jun-ha0 committed Aug 29, 2019
2 parents 3e92d08 + e922fff commit 3a853a0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/duke/common/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Message {
public static final String MESSAGE_ADDED = "Got it. I've added this task:";
public static final String MESSAGE_DELETED = "Noted. I've removed this task:";
public static final String MESSAGE_MARK_DONE = "Nice! I've marked this task as done:";
public static final String MESSAGE_SHOW_TASK_LIST = "Here are the tasks in your list:";
public static final String MESSAGE_SHOW_TASK_LIST = "Here are the%1$s tasks in your list:";
public static final String MESSAGE_SHOW_TASK_SIZE = "Now you have %1$s tasks in the list.";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "I'm sorry, but I don't know what that means :-(";
public static final String MESSAGE_INVALID_TODO_FORMAT = "The description of a todo cannot be empty.";
Expand All @@ -19,6 +19,7 @@ public class Message {
public static final String MESSAGE_INVALID_EVENT_FORMAT =
"Events must have /at and cannot be empty. E.g. event project meeting /at 2/12/2019 1800";
public static final String MESSAGE_INVALID_TASK_INDEX = "Invalid task number. Task numbers follow 1-based indexing.";
public static final String MESSAGE_INVALID_KEYWORD_FORMAT = "Invalid keyword. Specify keyword to search for tasks.";
public static final String MESSAGE_ERROR_MISSING_STORAGE_FILE = "%1$sMissing storage file: %2$s";
public static final String MESSAGE_ERROR_CREATING_STORAGE_FILE = "Unable to create new file %1$s. %2$s";
public static final String MESSAGE_STORAGE_FILE_CREATED = "%1$sCreated new empty storage file: %2$s";
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public static Command parse(String inputLine) throws DukeException {
return new AddCommand(createEventFrom(inputLine));
case "delete":
return new DeleteCommand(getIndexFrom(inputLine));
case "find":
return new FindCommand(getKeywordFrom(inputLine));
default:
throw new DukeException(Message.MESSAGE_INVALID_COMMAND_FORMAT);
}
Expand Down Expand Up @@ -97,4 +99,12 @@ private static Event createEventFrom(String inputLine) throws DukeException {
throw new DukeException((Message.MESSAGE_INVALID_DATE_FORMAT));
}
}

private static String getKeywordFrom(String inputLine) throws DukeException {
String keyword = inputLine.substring("find".length()).strip();
if (keyword.isEmpty()) {
throw new DukeException(Message.MESSAGE_INVALID_KEYWORD_FORMAT);
}
return keyword;
}
}
7 changes: 7 additions & 0 deletions src/main/java/duke/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public Task(String taskName) {
this.isDone = false;
}

/**
* @return the name of this task.
*/
public String getTaskName() {
return this.taskName;
}

/**
* Sets this task to the given done status.
*
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/duke/task/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public TaskList() {
*
* @param tasks list of tasks.
*/

public TaskList(List<Task> tasks) {
this.tasks = tasks;
}
Expand Down Expand Up @@ -76,6 +75,20 @@ public List<String> getTaskNames() {
return taskNames;
}

/**
* @param keyword keyword that is used for finding tasks.
* @return a list of task names and descriptions of tasks that contain this <code>keyword</code>.
*/
public List<String> getTaskNamesIfMatch(String keyword) {
List<String> taskNamesThatMatch = new ArrayList<>();
for (int i = 0; i < tasks.size(); i++) {
if (tasks.get(i).getTaskName().contains(keyword)) {
taskNamesThatMatch.add((i + 1) + ". " + tasks.get(i));
}
}
return taskNamesThatMatch;
}

/**
* @return a list of simplified summaries of all tasks in the list.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/ui/UserInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void showDeletion(Task task) {
* @param taskNames names of the tasks.
*/
public void showTaskList(List<String> taskNames) {
showToUser(Message.MESSAGE_SHOW_TASK_LIST);
showToUser(String.format(Message.MESSAGE_SHOW_TASK_LIST, " matching"));
for (String taskName : taskNames) {
showToUser(taskName);
}
Expand Down

0 comments on commit 3a853a0

Please sign in to comment.