David Bylund - #147
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds new Todo list/domain implementations for both the core and extension packages, along with JUnit tests to validate list operations (add, status changes, filtering, search, delete, ordering, and extension-only ID/date features).
Changes:
- Introduces
Task+TodoListincom.booleanuk.coreand corresponding tests. - Introduces
ExTask+ExTodoListincom.booleanuk.extensionand corresponding tests, including ID-based operations and date/time formatting. - Expands existing
TodoListTestwith additional behavioral tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/booleanuk/core/TodoList.java | Implements core todo list operations (add, status, filtering, search, delete, ordering). |
| src/main/java/com/booleanuk/core/pojo/Task.java | Adds the core task POJO used by TodoList. |
| src/main/java/com/booleanuk/extension/ExTodoList.java | Implements extension todo list operations, including ID and date/time features. |
| src/main/java/com/booleanuk/extension/ExTask.java | Adds the extension task model with ID and creation timestamp. |
| src/test/java/com/booleanuk/core/TodoListTest.java | Adds tests for core todo list behaviors. |
| src/test/java/com/booleanuk/core/pojo/TaskTest.java | Adds tests for the core task model. |
| src/test/java/com/booleanuk/extension/ExTodoListTest.java | Adds tests for extension todo list behaviors (including ID/date/time). |
| src/test/java/com/booleanuk/extension/ExTaskTest.java | Adds tests for the extension task model. |
Suppressed comments (6)
src/main/java/com/booleanuk/extension/ExTodoList.java:32
- String comparison uses
==(reference equality) instead of value equality, so status changes can silently fail depending on how the String was constructed.
public void changeStatus(String task, boolean status){
for(ExTask t : this.tdList){
if(task == t.getTask())
t.setComplet(status);
}
src/main/java/com/booleanuk/extension/ExTodoList.java:70
- String comparison uses
==(reference equality) and the list is mutated during a foreach loop. Switching to an index-based loop avoids iteration/modification pitfalls and ensures value-based matching.
public void delete(String task){
int i = 0;
for(ExTask t: this.tdList){
if(t.getTask() == task){
this.tdList.remove(i);
break;
}
i++;
}
}
src/main/java/com/booleanuk/extension/ExTodoList.java:79
- Building the result with
+=in a loop is O(n²) andtmpListaliasestdList, so calling this method also reorders the underlying list. Using a copied list and StringBuilder avoids both issues.
public String orderAscend(){
String tmpStr = "";
List<ExTask> tmpList = this.tdList;
tmpList.sort(Comparator.comparing(ExTask::getTask, String.CASE_INSENSITIVE_ORDER));
for (ExTask t : tmpList){
tmpStr += t.getTask() + "\n";
}
return tmpStr.trim();
src/main/java/com/booleanuk/extension/ExTodoList.java:89
- Building the result with
+=in a loop is O(n²) andtmpListaliasestdList, so calling this method also reorders the underlying list. Using a copied list and StringBuilder avoids both issues.
public String orderDescend(){
String tmpStr = "";
List<ExTask> tmpList = this.tdList;
tmpList.sort(Comparator.comparing(ExTask::getTask, String.CASE_INSENSITIVE_ORDER).reversed());
for (ExTask t : tmpList){
tmpStr += t.getTask() + "\n";
}
return tmpStr.trim();
src/main/java/com/booleanuk/core/TodoList.java:68
- String comparison uses
==(reference equality) and the list is mutated during a foreach loop. Switching to an index-based loop avoids iteration/modification pitfalls and ensures value-based matching.
public void delete(String task){
int i = 0;
for(Task t: this.tdList){
if(t.getTask() == task){
this.tdList.remove(i);
break;
}
i++;
}
}
src/main/java/com/booleanuk/core/TodoList.java:87
- Building the result with
+=in a loop is O(n²) andtmpListaliasestdList, so calling this method also reorders the underlying list. Using a copied list and StringBuilder avoids both issues.
public String orderDescend(){
String tmpStr = "";
List<Task> tmpList = this.tdList;
tmpList.sort(Comparator.comparing(Task::getTask, String.CASE_INSENSITIVE_ORDER).reversed());
for (Task t : tmpList){
tmpStr += t.getTask() + "\n";
}
return tmpStr.trim();
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| public void add(ExTask task){ | ||
| task.id = incrementID; | ||
| this.tdList.add(task); | ||
| } |
| public String dateTime(){ | ||
| DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | ||
| String tmp = ""; | ||
| for(ExTask t : tdList){ | ||
| String tmpStr = t.getDate().format(formatter); | ||
| tmp += t.getTask() + " " + tmpStr + "\n"; | ||
| } | ||
| return tmp.trim(); | ||
| } |
| public void changeStatus(String task, boolean status){ | ||
| for(Task t : this.tdList){ | ||
| if(task == t.getTask()) | ||
| t.setComplet(status); | ||
| } |
| public String orderAscend(){ | ||
| String tmpStr = ""; | ||
| List<Task> tmpList = this.tdList; | ||
| tmpList.sort(Comparator.comparing(Task::getTask, String.CASE_INSENSITIVE_ORDER)); | ||
| for (Task t : tmpList){ | ||
| tmpStr += t.getTask() + "\n"; | ||
| } | ||
| return tmpStr.trim(); | ||
| } |
| DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | ||
|
|
||
| String expected = "Fix nvim config " + | ||
| LocalDateTime.now().format(formatter) + "\nClean house " + LocalDateTime.now().format(formatter); | ||
|
|
||
| Assertions.assertEquals(expected, tdList.dateTime()); |
| private String task; | ||
| private boolean complet; | ||
| protected int id; |
| private String task; | ||
| private boolean complet; | ||
|
|
No description provided.