-
Notifications
You must be signed in to change notification settings - Fork 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
[Tay Jun Yang] iP #500
base: master
Are you sure you want to change the base?
[Tay Jun Yang] iP #500
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall lgtm! Just note the few nits, and perhaps it could be better to reduce copy-pasting of certain code blocks, and abstract them or use as default from abstract class that it is inheriting from.
new Duke("data", "tasks.txt").run(); | ||
} | ||
|
||
public void run() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add headers comments for public methods.
|
||
import java.io.IOException; | ||
|
||
public class Duke { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add header comment for the class.
Noticed that there is no JavaDocs added throughout. Perhaps it would be good practice to have them, as documentation to improve readability of your code.
if ((commandType.equals("bye") || commandType.equals("list")) && !commandInfo.equals("")) { | ||
throw new DukeException("INVALID COMMAND. Please try again!"); | ||
} | ||
} else { // for "bye" and "list" commands |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments should be indented relative to their position in the code.
return command; | ||
} | ||
|
||
private int getTaskNumFromCommand(String commandInfo) throws DukeException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps a shorter name would be better e.g. getTaskNum.
} | ||
} | ||
|
||
private String getTaskDescriptionFromToDoCommand(String commandInfo) throws DukeException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above, method names could be shorter and more concise, and if they are specific to a command, perhaps it could be a better design to have them in the respective command classes.
This applies to other method names as well.
if (deadlineTaskDetails.length == 2) { | ||
if (deadlineTaskDetails[0].trim().length() > 0) { | ||
if (deadlineTaskDetails[1].trim().startsWith("by")) { | ||
String beforeDateTime = deadlineTaskDetails[1].trim(); | ||
String[] beforeDateTimeParts = beforeDateTime.split("\\s+", 2); | ||
|
||
if (beforeDateTimeParts.length == 2) { | ||
return commandInfo; | ||
} else { | ||
throw new DukeException("INCOMPLETE COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The date/time of a deadline cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "[Note: Enter /by before specifying the date/time]"); | ||
} | ||
} else { | ||
throw new DukeException("WRONG COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "Enter /by before specifying the date!"); | ||
} | ||
} else { | ||
if (deadlineTaskDetails[1].trim().startsWith("by")) { | ||
String beforeDateTime = deadlineTaskDetails[1].trim(); | ||
String[] beforeDateTimeParts = beforeDateTime.split("\\s+", 2); | ||
|
||
if (beforeDateTimeParts.length == 2) { | ||
throw new DukeException("INCOMPLETE COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The description of a deadline cannot be empty!"); | ||
} else { | ||
throw new DukeException("INCOMPLETE COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The description of a deadline cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "The date/time of a deadline cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "[Note: Enter /by before specifying the date/time]"); | ||
} | ||
} else { | ||
throw new DukeException("INCOMPLETE & WRONG COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The description of a deadline cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "Enter /by before specifying the date/time!"); | ||
} | ||
} | ||
} else { | ||
throw new DukeException("INCOMPLETE COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The date/time of a deadline cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "[Note: Enter /by before specifying the date/time]"); | ||
} | ||
} else { | ||
throw new DukeException("INCOMPLETE COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The description and date/time of a deadline cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "[Note: Enter /by before specifying the date/time]"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid deep nesting, especially if you need more than 3 levels of indentation. In particular, avoid arrowhead style code.
if (commandInfo.trim().length() > 0) { | ||
String[] eventTaskDetails = commandInfo.split("/", 2); | ||
|
||
if (eventTaskDetails.length == 2) { | ||
if (eventTaskDetails[0].trim().length() > 0) { | ||
if (eventTaskDetails[1].trim().startsWith("at")) { | ||
String startEndDateTime = eventTaskDetails[1].trim(); | ||
String[] startEndDateTimeParts = startEndDateTime.split("\\s+", 2); | ||
|
||
if (startEndDateTimeParts.length == 2) { | ||
return commandInfo; | ||
} else { | ||
throw new DukeException("INCOMPLETE COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The date/time of an event cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "[Note: Enter /at before specifying the date/time]"); | ||
} | ||
} else { | ||
throw new DukeException("WRONG COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "Enter /at before specifying the date!"); | ||
} | ||
} else { | ||
if (eventTaskDetails[1].trim().startsWith("at")) { | ||
String startEndDateTime = eventTaskDetails[1].trim(); | ||
String[] startEndDateTimeParts = startEndDateTime.split("\\s+", 2); | ||
|
||
if (startEndDateTimeParts.length == 2) { | ||
throw new DukeException("INCOMPLETE COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The description of an event cannot be empty!"); | ||
} else { | ||
throw new DukeException("INCOMPLETE COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The description of an event cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "The date/time of an event cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "[Note: Enter /at before specifying the date/time]"); | ||
} | ||
} else { | ||
throw new DukeException("INCOMPLETE & WRONG COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The description of an event cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "Enter /at before specifying the date/time!"); | ||
} | ||
} | ||
} else { | ||
throw new DukeException("INCOMPLETE COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The date/time of an event cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "[Note: Enter /at before specifying the date/time]"); | ||
} | ||
} else { | ||
throw new DukeException("INCOMPLETE COMMAND" | ||
+ System.lineSeparator() + "\t" | ||
+ "The description and date/time of an event cannot be empty!" | ||
+ System.lineSeparator() + "\t" | ||
+ "[Note: Enter /at before specifying the date/time]"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as comment above, avoid deep nesting.
if (!timeInput.equals("")) { | ||
try { | ||
int timeInputInInt = Integer.parseInt(timeInput); | ||
|
||
if ((timeInputInInt < 0 || timeInputInInt > 2359)) { | ||
isTimeInputProper = false; | ||
time = null; | ||
} else { | ||
if (timeInput.length() != 4) { | ||
isTimeInputProper = false; | ||
time = null; | ||
} else { | ||
int hour = timeInputInInt / 100; | ||
int min = timeInputInInt - (hour * 100); | ||
|
||
String timeInputInTimeFormat = ""; | ||
|
||
if (hour < 10) { | ||
timeInputInTimeFormat += "0" + hour; | ||
} else { | ||
timeInputInTimeFormat += hour; | ||
} | ||
|
||
if (min < 10) { | ||
timeInputInTimeFormat += ":" + "0" + min; | ||
} else { | ||
timeInputInTimeFormat += ":" + min; | ||
} | ||
|
||
DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_LOCAL_TIME; | ||
time = LocalTime.parse(timeInputInTimeFormat, timeFormatter); | ||
} | ||
} | ||
} catch (Exception e) { | ||
time = null; | ||
} | ||
} else { | ||
time = null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, try to avoid deep nesting.
EVENT("event", "E"); | ||
|
||
private final String label; | ||
private final String abbr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps better name could be letter
or spelled in full abbreviation
No description provided.