[YFshadaow] ip#80
Conversation
| @@ -5,11 +5,12 @@ | |||
| public class CommandHandler { | |||
|
|
|||
| private final XiaoAiBot bot; | |||
| case "todo": { | ||
| Todo todo; | ||
| try { | ||
| todo = Todo.parseTodo(args); | ||
| } catch (Exception e) { | ||
| bot.sendMessage("Error parsing task"); | ||
| e.printStackTrace(); | ||
| break; | ||
| } |
| case "deadline": { | ||
| Deadline deadline; | ||
| try { | ||
| deadline = Deadline.parseDeadline(args); | ||
| } catch (Exception e) { | ||
| bot.sendMessage("Error parsing task"); | ||
| e.printStackTrace(); | ||
| break; | ||
| } | ||
| bot.getTasks().add(deadline); | ||
| bot.sendMessageWithoutSplit("Got it. I've added this task:"); | ||
| bot.sendMessageWithoutSplit(deadline.toStringWithIsDone()); | ||
| bot.sendMessage("Now you have " + bot.getTasks().size() + " tasks in the list."); | ||
| break; | ||
| } | ||
| case "event": { | ||
| Event event; | ||
| try { | ||
| event = Event.parseEvent(args); | ||
| } catch (Exception e) { | ||
| bot.sendMessage("Error parsing task"); | ||
| e.printStackTrace(); | ||
| break; | ||
| } | ||
| bot.getTasks().add(event); | ||
| bot.sendMessageWithoutSplit("Got it. I've added this task:"); | ||
| bot.sendMessageWithoutSplit(event.toStringWithIsDone()); | ||
| bot.sendMessage("Now you have " + bot.getTasks().size() + " tasks in the list."); | ||
| break; |
There was a problem hiding this comment.
Good use of switch-case statements!
|
|
||
| private String by; | ||
|
|
||
| public Deadline(String name, String by) { |
| this.bot = bot; | ||
| } | ||
|
|
||
| public void handleCommand(String command) { |
There was a problem hiding this comment.
Very clear naming of the methods. Makes it readable and easy to understand.
| case "todo": { | ||
| Todo todo; | ||
| try { | ||
| todo = Todo.parseTodo(args); |
There was a problem hiding this comment.
Is it better to handle the exception more gracefully rather than printing the stack trace and breaking the switch block? For example, could we log the error and send a user-friendly message instead?
| bot.sendMessage("No command detected!"); | ||
| return; | ||
| } | ||
| String[] args = new String[splitCommand.length - 1]; |
There was a problem hiding this comment.
Could it be clearer to use Arrays.copyOfRange() here? It might make the code more readable.
| break; | ||
| } | ||
| bot.sendMessageWithoutSplit("OK, I've marked this task as not done yet:"); | ||
| bot.sendMessage(bot.getTasks().get(index - 1).toStringWithIsDone()); |
There was a problem hiding this comment.
Would it be more efficient to store the result of bot.getTasks().get(index - 1) in a variable before sending it as a message? This way, we wouldn't need to retrieve it twice.
There was a problem hiding this comment.
Usually I do that for variables that are used three times or more. For variables that are used twice I might just leave it as that.
| @@ -0,0 +1,132 @@ | |||
| package cn.yfshadaow.cs2113.ip; | |||
There was a problem hiding this comment.
Hi Zhengdao! Hope your health got better over the holidays!
maanyos
left a comment
There was a problem hiding this comment.
Good adherence with coding standards and use of exceptions.
| public String getBy() { | ||
| return by; | ||
| } | ||
|
|
||
| public void setBy(String by) { | ||
| this.by = by; | ||
| } | ||
|
|
||
| private String by; |
There was a problem hiding this comment.
easier to read f you declare first and use later
|
|
||
| private boolean shouldQuit = false; | ||
|
|
||
| private void initialize() { |
Add find command: Allow user search for tasks using keywords
Add javadoc
No description provided.