@stevenlimhw We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.
IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.
Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)
private void updateEndDateTime(String endDateTime) {
StringBuilder year = new StringBuilder();
StringBuilder month = new StringBuilder();
StringBuilder day = new StringBuilder();
StringBuilder time = new StringBuilder();
Calendar currentlyAnalyzing = Calendar.DAY;
for (int i = 0; i < endDateTime.length(); i++) {
if (endDateTime.charAt(i) == '/' && currentlyAnalyzing.equals(Calendar.DAY)) {
currentlyAnalyzing = Calendar.MONTH;
continue;
} else if (endDateTime.charAt(i) == '/' && currentlyAnalyzing.equals(Calendar.MONTH)) {
currentlyAnalyzing = Calendar.YEAR;
continue;
} else if (endDateTime.charAt(i) == ' ' && currentlyAnalyzing.equals(Calendar.YEAR)) {
currentlyAnalyzing = Calendar.TIME;
continue;
}
if (currentlyAnalyzing.equals(Calendar.DAY)) {
day.append(endDateTime.charAt(i));
} else if (currentlyAnalyzing.equals(Calendar.MONTH)) {
month.append(endDateTime.charAt(i));
} else if (currentlyAnalyzing.equals(Calendar.YEAR)) {
year.append(endDateTime.charAt(i));
} else {
time.append(endDateTime.charAt(i));
}
}
int y = Integer.parseInt(year.toString()); // year
int m = Integer.parseInt(month.toString()); // month
int d = Integer.parseInt(day.toString()); // day
LocalDate endDate = LocalDate.of(y, m, d);
LocalTime endTime = LocalTime.of(0, 0);
if (currentlyAnalyzing.equals(Calendar.TIME)) {
int hour = Integer.parseInt(time.toString().substring(0, 2));
int minute = Integer.parseInt(time.toString().substring(3, 5));
endTime = LocalTime.parse(LocalTime.of(hour, minute).toString(), DateTimeFormatter.ofPattern("HH:mm"));
}
this.endDate = endDate;
// value of endTime defaults to 00:00 if no time is indicated
this.endTime = endTime;
}
public String parseCommand(List<Task> tasks, String textInput) {
try {
// Scan input from the user
String[] inputs = textInput.split(" ");
String command = inputs[0];
if (textInput.equals(Command.BYE.name().toLowerCase())) {
Duke.saveDuke();
System.exit(0);
} else if (textInput.equals(Command.LIST.name().toLowerCase())) {
return Ui.showTasks(tasks);
} else if (command.equals(Command.MARK.name().toLowerCase())) {
// inputs[1] is the index number of the task to be marked
if (inputs.length < 2) {
throw new InvalidTaskIndexException();
}
return ui.markTaskAsDone(Integer.parseInt(inputs[1]), tasks);
} else if (command.equals(Command.UNMARK.name().toLowerCase())) {
// inputs[1] is the index number of the task to be unmarked
if (inputs.length < 2) {
throw new InvalidTaskIndexException();
}
return ui.markTaskAsNotDone(Integer.parseInt(inputs[1]), tasks);
} else if (command.equals(Command.TODO.name().toLowerCase())) {
return taskList.addTodo(inputs);
} else if (command.equals(Command.DEADLINE.name().toLowerCase())) {
return taskList.addDeadline(inputs);
} else if (command.equals(Command.EVENT.name().toLowerCase())) {
return taskList.addEvent(inputs);
} else if (command.equals(Command.DELETE.name().toLowerCase())) {
// inputs[1] is the index number of the task to be marked
if (inputs.length < 2) {
throw new InvalidTaskIndexException();
}
return taskList.deleteTask(Integer.parseInt(inputs[1]));
} else if (command.equals(Command.FIND.name().toLowerCase())) {
// inputs[1] is the keyword (do not accept keywords)
return taskList.findTasks(inputs[1]);
} else if (command.equals(Command.SORT.name().toLowerCase())) {
return taskList.sortByName();
}
else {
// when none of the commands match
throw new UnknownCommandException();
}
} catch (EmptyNameException | UnknownCommandException
| NoTasksException | InvalidTaskIndexException | IOException e) {
return e.getMessage();
}
return "Quack! I can't parse your message!";
}
Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.
Aspect: Class size
No easy-to-detect issues :+1:
Aspect: Header Comments
No easy-to-detect issues :+1:
Aspect: Recent Git Commit Message (Subject Only)
No easy-to-detect issues :+1:
Aspect: Binary files in repo
No easy-to-detect issues :+1:
:information_source: The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact cs2103@comp.nus.edu.sg if you want to follow up on this post.
@stevenlimhw We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.
IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.
Aspect: Tab Usage
No easy-to-detect issues :+1:
Aspect: Naming boolean variables/methods
Example from
src/main/java/utils/TaskList.java
lines54-54
:Example from
src/main/java/utils/TaskList.java
lines92-92
:Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)
Aspect: Brace Style
Example from
src/main/java/utils/Parser.java
lines69-70
:Suggestion: As specified by the coding standard, use egyptian style braces.
Aspect: Package Name Style
No easy-to-detect issues :+1:
Aspect: Class Name Style
No easy-to-detect issues :+1:
Aspect: Dead Code
No easy-to-detect issues :+1:
Aspect: Method Length
Example from
src/main/java/objects/Deadline.java
lines37-82
:Example from
src/main/java/utils/Parser.java
lines29-79
:Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.
Aspect: Class size
No easy-to-detect issues :+1:
Aspect: Header Comments
No easy-to-detect issues :+1:
Aspect: Recent Git Commit Message (Subject Only)
No easy-to-detect issues :+1:
Aspect: Binary files in repo
No easy-to-detect issues :+1:
:information_source: The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact
cs2103@comp.nus.edu.sg
if you want to follow up on this post.