Skip to content

Commit

Permalink
Merge branch 'branch-A-CodingStandard'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/duke/Duke.java
#	src/main/java/duke/parser/Parser.java
#	src/main/java/duke/storage/Storage.java
  • Loading branch information
jun-ha0 committed Aug 29, 2019
2 parents 3a853a0 + 6667260 commit 5a5d4f8
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void run() {
/**
* Main entry point of the application.
*/
public static void main (String[] args){
public static void main(String[] args) {
new Duke(DEFAULT_STORAGE_FILEPATH).run();
}
}
1 change: 0 additions & 1 deletion src/main/java/duke/command/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class ExitCommand extends Command {
* @param taskList list of tasks.
* @param ui user interface displaying program exiting.
* @param storage local storage of data.
* @throws DukeException
*/
@Override
public void execute(TaskList taskList, UserInterface ui, Storage storage) throws DukeException {
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/duke/command/FindCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package duke.command;

import duke.DukeException;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.UserInterface;

/**
* Finds all tasks in the task list that matches given keyword.
*/
public class FindCommand extends Command {

private String keyword;

/**
* Creates a command to find tasks that matches this keyword.
*
* @param keyword keyword that is used to find tasks.
*/
public FindCommand(String keyword) {
this.keyword = keyword;
}

/**
* Executes finding of matching tasks on user interface.
*
* @param taskList list of tasks.
* @param ui user interface displaying all tasks that matches this keyword.
* @param storage local storage of data.
* @throws DukeException
*/
@Override
public void execute(TaskList taskList, UserInterface ui, Storage storage) throws DukeException {
ui.showTaskList(taskList.getTaskNamesIfMatch(this.keyword));
}
}
1 change: 0 additions & 1 deletion src/main/java/duke/common/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/**
* Contains messages displayed to user.
*/

public class Message {

public static final String MESSAGE_WELCOME = "Hello! I'm Duke\n%1$sWhat can I do for you?\n%2$s";
Expand Down
44 changes: 25 additions & 19 deletions src/main/java/duke/parser/Parser.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package duke.parser;

import duke.DukeException;
import duke.command.*;
import duke.command.AddCommand;
import duke.command.Command;
import duke.command.DeleteCommand;
import duke.command.DoneCommand;
import duke.command.ExitCommand;
import duke.command.FindCommand;
import duke.command.ListCommand;
import duke.common.Message;
import duke.task.Deadline;
import duke.task.Event;
Expand All @@ -25,24 +31,24 @@ public class Parser {
public static Command parse(String inputLine) throws DukeException {
String command = getCommandFrom(inputLine);
switch (command) {
case "bye":
return new ExitCommand();
case "list":
return new ListCommand();
case "done":
return new DoneCommand(getIndexFrom(inputLine));
case "todo":
return new AddCommand(createTodoFrom(inputLine));
case "deadline":
return new AddCommand(createDeadlineFrom(inputLine));
case "event":
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);
case "bye":
return new ExitCommand();
case "list":
return new ListCommand();
case "done":
return new DoneCommand(getIndexFrom(inputLine));
case "todo":
return new AddCommand(createTodoFrom(inputLine));
case "deadline":
return new AddCommand(createDeadlineFrom(inputLine));
case "event":
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
37 changes: 20 additions & 17 deletions src/main/java/duke/storage/Storage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package duke.storage;

import static duke.common.Message.*;

import duke.DukeException;
import duke.task.Deadline;
import duke.task.Event;
Expand All @@ -19,6 +17,11 @@
import java.util.List;
import java.util.Scanner;

import static duke.common.Message.MESSAGE_ERROR_CREATING_STORAGE_FILE;
import static duke.common.Message.MESSAGE_ERROR_MISSING_STORAGE_FILE;
import static duke.common.Message.MESSAGE_ERROR_READING_FROM_FILE;
import static duke.common.Message.MESSAGE_STORAGE_FILE_CREATED;

/**
* Represents local storage of data from Duke application.
*/
Expand Down Expand Up @@ -90,21 +93,21 @@ private Task createTaskFrom(String storageLine) throws DukeException {
String doneStatus = taskPart[1].strip();
String description = taskPart[2].strip();
switch (typeOfTask) {
case "T":
task = new Todo(description);
break;
case "D":
LocalDateTime by = LocalDateTime.parse(taskPart[3].strip(),
DateTimeFormatter.ofPattern("d/M/yyyy HHmm"));
task = new Deadline(description, by);
break;
case "E":
LocalDateTime at = LocalDateTime.parse(taskPart[3].strip(),
DateTimeFormatter.ofPattern("d/M/yyyy HHmm"));
task = new Event(description, at);
break;
default:
throw new DukeException(MESSAGE_ERROR_READING_FROM_FILE);
case "T":
task = new Todo(description);
break;
case "D":
LocalDateTime by = LocalDateTime.parse(taskPart[3].strip(),
DateTimeFormatter.ofPattern("d/M/yyyy HHmm"));
task = new Deadline(description, by);
break;
case "E":
LocalDateTime at = LocalDateTime.parse(taskPart[3].strip(),
DateTimeFormatter.ofPattern("d/M/yyyy HHmm"));
task = new Event(description, at);
break;
default:
throw new DukeException(MESSAGE_ERROR_READING_FROM_FILE);
}
task.setDone(doneStatus.equals("1"));
} catch (ArrayIndexOutOfBoundsException e) {
Expand Down

0 comments on commit 5a5d4f8

Please sign in to comment.