@nicleejy 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 ๐
Aspect: Naming boolean variables/methods
No easy-to-detect issues ๐
Aspect: Brace Style
No easy-to-detect issues ๐
Aspect: Package Name Style
No easy-to-detect issues ๐
Aspect: Class Name Style
No easy-to-detect issues ๐
Aspect: Dead Code
Example from src/main/java/data/TaskManager.java
lines 127-127
:
// eventsList.forEach(event -> System.out.println(event.toString()));
Example from src/main/java/data/TaskManager.java
lines 175-175
:
// filteredFreeTimeBlocks.forEach(freeTimeBlock -> System.out.println(freeTimeBlock.toString()));
Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from src/main/java/data/TaskFileReaderWriter.java
lines 101-139
:
public boolean updateTaskFile(TaskManager taskManager) {
File taskFile = new File(DIRECTORY_NAME + File.separator + FILE_NAME);
String taskString = null;
String details;
boolean isCompleted;
try (FileWriter fileWriter = new FileWriter(taskFile)) {
for (Task task : taskManager.getTasks()) {
if (task instanceof Deadline) {
Deadline deadlineTask = (Deadline) task;
details = deadlineTask.getDetails();
String deadline = deadlineTask.getDeadline();
isCompleted = deadlineTask.isCompleted();
taskString = "Deadline|" + isCompleted + "|" + details + "|" + deadline;
} else if (task instanceof Event) {
Event eventTask = (Event) task;
details = eventTask.getDetails();
String start = eventTask.getStartString();
String end = eventTask.getEndString();
isCompleted = eventTask.isCompleted();
taskString = "Event|" + isCompleted + "|" + details + "|" + start + "|" + end;
} else if (task instanceof ToDo) {
ToDo toDoTask = (ToDo) task;
details = toDoTask.getDetails();
isCompleted = toDoTask.isCompleted();
taskString = "To-Do|" + isCompleted + "|" + details;
}
assert taskString != null;
fileWriter.write(taskString + System.getProperty("line.separator"));
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
Example from src/main/java/data/TaskManager.java
lines 125-178
:
public ArrayList<FreeTimeBlock> getFreeTimes(int desiredFreeTime) {
ArrayList<Event> eventsList = getEventsAfterNow();
// eventsList.forEach(event -> System.out.println(event.toString()));
ArrayList<FreeTimeBlock> freeTimeBlocks = new ArrayList<>();
LocalDateTime dateTime = LocalDateTime.of(2023, 2, 10, 9, 30);
if (
(eventsList.size() > 0) &&
(eventsList.get(0)
.getStartTime()
.compareTo(dateTime) > 0)) {
freeTimeBlocks.add(new FreeTimeBlock(null, eventsList.get(0).getStartTime()));
}
if (eventsList.size() < 2) {
if (eventsList.isEmpty()) {
freeTimeBlocks.add(new FreeTimeBlock(null, null));
freeTimeBlocks.forEach(freeTimeBlock -> System.out.println(freeTimeBlock.toString()));
return freeTimeBlocks;
}
Event event = eventsList.get(0);
freeTimeBlocks.add(new FreeTimeBlock(event.getEndTime(), null));
freeTimeBlocks.forEach(freeTimeBlock -> System.out.println(freeTimeBlock.toString()));
return freeTimeBlocks;
}
LocalDateTime freeBlockStart = eventsList.get(0).getEndTime();
assert freeBlockStart != null;
LocalDateTime freeBlockEnd;
for (Event event: eventsList.subList(1, eventsList.size())) {
if (freeBlockStart.compareTo(event.getStartTime()) < 0) {
freeBlockEnd = event.getStartTime();
freeTimeBlocks.add(new FreeTimeBlock(freeBlockStart, freeBlockEnd));
}
if (event.getEndTime().compareTo(freeBlockStart) > 0) {
freeBlockStart = event.getEndTime();
}
}
freeTimeBlocks.add(new FreeTimeBlock(freeBlockStart, null));
ArrayList<FreeTimeBlock> filteredFreeTimeBlocks = freeTimeBlocks.stream()
.filter((freeTimeBlock -> freeTimeBlock.isValidSlot(desiredFreeTime)))
.collect(Collectors.toCollection(ArrayList::new));
// filteredFreeTimeBlocks.forEach(freeTimeBlock -> System.out.println(freeTimeBlock.toString()));
return filteredFreeTimeBlocks;
}
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 ๐
Aspect: Header Comments
Example from src/main/java/data/TaskManager.java
lines 33-38
:
/**
* Used to mark a task as complete.
*
* @param index the index of the task to mark as complete
* @throws DukeInvalidCommandException if the task is not found
*/
Example from src/main/java/data/TaskManager.java
lines 49-54
:
/**
* Used to mark a task incomplete.
*
* @param index the index of the task to mark as complete
* @throws DukeInvalidCommandException if the task is not found
*/
Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.
Aspect: Recent Git Commit Message (Subject Only)
No easy-to-detect issues ๐
Aspect: Binary files in repo
No easy-to-detect issues ๐
โน๏ธ 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 [email protected]
if you want to follow up on this post.