Skip to content

[Tay Jun Yang] iP#500

Open
dannytayjy wants to merge 18 commits into
nus-cs2103-AY2122S1:masterfrom
dannytayjy:master
Open

[Tay Jun Yang] iP#500
dannytayjy wants to merge 18 commits into
nus-cs2103-AY2122S1:masterfrom
dannytayjy:master

Conversation

@dannytayjy

Copy link
Copy Markdown

No description provided.

@leeroy999 leeroy999 left a comment

Copy link
Copy Markdown

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() {

Copy link
Copy Markdown

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 {

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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 {

Copy link
Copy Markdown

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 {

Copy link
Copy Markdown

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.

Comment on lines +101 to +161
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]");
}
}

Copy link
Copy Markdown

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.

Comment on lines +164 to +226
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]");
}

Copy link
Copy Markdown

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.

Comment on lines +52 to +90
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;
}

Copy link
Copy Markdown

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;

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants