-
Notifications
You must be signed in to change notification settings - Fork 129
Jonas Finborud Nyman #119
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
Open
jonasmelonas
wants to merge
4
commits into
boolean-uk:main
Choose a base branch
from
jonasmelonas:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Jonas Finborud Nyman #119
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| public class Task { | ||
| String taskName; | ||
| boolean isCompeted; | ||
|
|
||
| public Task(String taskName, boolean isCompeted) { | ||
| this.taskName = taskName; | ||
| this.isCompeted = isCompeted; | ||
| } | ||
|
|
||
| public String getTaskName() { | ||
| return this.taskName; | ||
| } | ||
|
|
||
| public boolean getIsCompleted() { | ||
| return this.isCompeted; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,78 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
|
|
||
| public class TodoList { | ||
| ArrayList<Task> tasks = new ArrayList<>(); | ||
|
|
||
| public boolean addTask(Task task) { | ||
| return tasks.add(task); | ||
| } | ||
|
|
||
| public void printTasks() { | ||
| System.out.println("Current tasks:"); | ||
| for(Task task : this.tasks) { | ||
| System.out.println(task.taskName + " : " + task.isCompeted); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| public boolean changeStatus(Task task) { | ||
| if(!tasks.contains(task)) return false; | ||
| task.isCompeted = !task.isCompeted; | ||
| return true; | ||
| } | ||
|
|
||
| public ArrayList<Task> getCompletedTasks() { | ||
| ArrayList<Task> completedTasks = new ArrayList<>(); | ||
| for(Task task : this.tasks) { | ||
| if(task.isCompeted) completedTasks.add(task); | ||
| } | ||
| return completedTasks; | ||
| } | ||
|
|
||
| public ArrayList<Task> getIncompleteTasks() { | ||
| ArrayList<Task> incompleteTasks = new ArrayList<>(); | ||
| for(Task task : this.tasks) { | ||
| if(!task.isCompeted) incompleteTasks.add(task); | ||
| } | ||
| return incompleteTasks; | ||
| } | ||
|
|
||
| public Task getTask(String taskName) { | ||
| for(Task task : this.tasks) { | ||
| if(task.taskName.equals(taskName)) return task; | ||
| } return null; | ||
| } | ||
|
|
||
| public boolean removeTask(String taskName) { | ||
| for(Task task : this.tasks) { | ||
| if(task.taskName.equals(taskName)) { | ||
| this.tasks.remove(task); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public void printTasksAscending() { | ||
| ArrayList<Task> sortedTasks = new ArrayList<>(this.tasks); | ||
| sortedTasks.sort(((o1, o2) -> o1.getTaskName().compareTo(o2.getTaskName()))); | ||
| System.out.println("All tasks (descending):"); | ||
| for(Task task : sortedTasks) { | ||
| System.out.println(task.taskName + " : " + task.isCompeted); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| public void printTasksDescending() { | ||
| ArrayList<Task> sortedTasks = new ArrayList<>(this.tasks); | ||
| sortedTasks.sort(((o2, o1) -> o1.getTaskName().compareTo(o2.getTaskName()))); | ||
| System.out.println("All tasks (descending):"); | ||
| for(Task task : sortedTasks) { | ||
| System.out.println(task.taskName + " : " + task.isCompeted); | ||
| } | ||
| System.out.println(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Java ToDo List | ||
|
|
||
| | Classes | Members | Methods | Scenarios | Outputs | | ||
| |----------|-----------------------|--------------------------------------|------------------------------------------------|---------------------------------| | ||
| | Task | String taskName | String getTaskName() | Returns name | this.taskName | | ||
| | | boolean isCompleted | boolean getIsCompleted() | Returns isCompleted | this.isCompleted | | ||
| | | | | | | | ||
| | | | | | | | ||
| | | | | | | | ||
| | | | | | | | ||
| | | | | | | | ||
| | TodoList | ArrayList<Task> tasks | boolean addTask(Task task) | Successfully adds task at the end of tasks | true | | ||
| | | | | Is unable to add the task | false | | ||
| | | | void printTasks() | prints the list of tasks to the terminal | | | ||
| | | | boolean changeStatus(Task task) | The task exists in tasks and is updated | true | | ||
| | | | | The task does not exist and can't be updated | false | | ||
| | | | ArrayList<Task> getCompletedTasks() | Filters complete tasks in a new list | ArrayList<Task> completeTasks | | ||
| | | | ArrayList<Task> getIncompleteTasks() | Filters incomplete tasks in a new list | ArrayList<Task> incompleteTasks | | ||
| | | | Task getTask(String taskName) | Task exists and the user is informed | task | | ||
| | | | | Task doesn't exist, and the user is informed | null | | ||
| | | | boolean removeTask(String taskName) | Task exists, and is successfully deleted | true | | ||
| | | | | Task doesn't exists, and thus can't be deleted | false | | ||
| | | | void printTasksAscending() | prints tasks in ascending order | | | ||
| | | | void printTasksDescending() | prints tasks in descending order | | | ||
| | | | | | | | ||
| | | | | | | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.booleanuk.extension; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public class Task { | ||
| String taskName; | ||
| boolean isCompeted; | ||
| UUID id = UUID.randomUUID(); | ||
|
|
||
| public Task(String taskName, boolean isCompeted) { | ||
| this.taskName = taskName; | ||
| this.isCompeted = isCompeted; | ||
| } | ||
|
|
||
| public String getTaskName() { | ||
| return this.taskName; | ||
| } | ||
|
|
||
| public boolean getIsCompleted() { | ||
| return this.isCompeted; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package com.booleanuk.extension; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.UUID; | ||
|
|
||
| public class TodoList { | ||
| ArrayList<Task> tasks = new ArrayList<>(); | ||
|
|
||
| public boolean addTask(Task task) { | ||
| return tasks.add(task); | ||
| } | ||
|
|
||
| public void printTasks() { | ||
| System.out.println("Current tasks:"); | ||
| for(Task task : this.tasks) { | ||
| System.out.println(task.taskName + " : " + task.isCompeted); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| public boolean changeStatus(Task task) { | ||
| if(!tasks.contains(task)) return false; | ||
| task.isCompeted = !task.isCompeted; | ||
| return true; | ||
| } | ||
|
|
||
| public ArrayList<Task> getCompletedTasks() { | ||
| ArrayList<Task> completedTasks = new ArrayList<>(); | ||
| for(Task task : this.tasks) { | ||
| if(task.isCompeted) completedTasks.add(task); | ||
| } | ||
| return completedTasks; | ||
| } | ||
|
|
||
| public ArrayList<Task> getIncompleteTasks() { | ||
| ArrayList<Task> incompleteTasks = new ArrayList<>(); | ||
| for(Task task : this.tasks) { | ||
| if(!task.isCompeted) incompleteTasks.add(task); | ||
| } | ||
| return incompleteTasks; | ||
| } | ||
|
|
||
| public Task getTask(String taskName) { | ||
| for(Task task : this.tasks) { | ||
| if(task.taskName.equals(taskName)) return task; | ||
| } return null; | ||
| } | ||
|
|
||
|
|
||
| public boolean removeTask(String taskName) { | ||
| for(Task task : this.tasks) { | ||
| if(task.taskName.equals(taskName)) { | ||
| this.tasks.remove(task); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public void printTasksAscending() { | ||
| ArrayList<Task> sortedTasks = new ArrayList<>(this.tasks); | ||
| sortedTasks.sort(((o1, o2) -> o1.getTaskName().compareTo(o2.getTaskName()))); | ||
| System.out.println("All tasks (descending):"); | ||
| for(Task task : sortedTasks) { | ||
| System.out.println(task.taskName + " : " + task.isCompeted); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| public void printTasksDescending() { | ||
| ArrayList<Task> sortedTasks = new ArrayList<>(this.tasks); | ||
| sortedTasks.sort(((o2, o1) -> o1.getTaskName().compareTo(o2.getTaskName()))); | ||
| System.out.println("All tasks (descending):"); | ||
| for(Task task : sortedTasks) { | ||
| System.out.println(task.taskName + " : " + task.isCompeted); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| public Task getTaskByID(UUID id) { | ||
| for(Task task : this.tasks) { | ||
| if(task.id == id) return task; | ||
| } return null; | ||
| } | ||
|
|
||
| public boolean updateTaskNameByID(UUID id, String newTaskName) { | ||
| for(Task task : this.tasks) { | ||
| if(task.id == id) { | ||
| task.taskName = newTaskName; // should have a setter-function | ||
| return true; | ||
| } | ||
| } return false; | ||
| } | ||
|
|
||
| public boolean updateTaskStatusByID(UUID id, boolean status) { | ||
| for(Task task : this.tasks) { | ||
| if(task.id == id) { | ||
| task.isCompeted = status; // should have a setter-function | ||
| return true; | ||
| } | ||
| } return false; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Java ToDo List | ||
|
|
||
| | Classes | Members | Methods | Scenarios | Outputs | | ||
| |----------|-----------------------|----------------------------------------------------------------|------------------------------------------------|---------------------------------| | ||
| | Task | String taskName | String getTaskName() | Returns name | this.taskName | | ||
| | | boolean isCompleted | boolean getIsCompleted() | Returns isCompleted | this.isCompleted | | ||
| | | UUID id | | | | | ||
| | | | | | | | ||
| | | | | | | | ||
| | | | | | | | ||
| | | | | | | | ||
| | TodoList | ArrayList<Task> tasks | boolean addTask(Task task) | Successfully adds task at the end of tasks | true | | ||
| | | | | Is unable to add the task | false | | ||
| | | | void printTasks() | prints the list of tasks to the terminal | | | ||
| | | | boolean changeStatus(Task task) | The task exists in tasks and is updated | true | | ||
| | | | | The task does not exist and can't be updated | false | | ||
| | | | ArrayList<Task> getCompletedTasks() | Filters complete tasks in a new list | ArrayList<Task> completeTasks | | ||
| | | | ArrayList<Task> getIncompleteTasks() | Filters incomplete tasks in a new list | ArrayList<Task> incompleteTasks | | ||
| | | | Task getTask(String taskName) | Task exists and the user is informed | task | | ||
| | | | | Task doesn't exist, and the user is informed | null | | ||
| | | | boolean removeTask(String taskName) | Task exists, and is successfully deleted | true | | ||
| | | | | Task doesn't exists, and thus can't be deleted | false | | ||
| | | | void printTasksAscending() | prints tasks in ascending order | | | ||
| | | | void printTasksDescending() | prints tasks in descending order | | | ||
| | | | public Task getTaskByID(UUID id) | Task is found and returned | true | | ||
| | | | | Task is not found | false | | ||
| | | | public boolean updateTaskNameByID(UUID id, String newTaskName) | Task is found and name is updated | true | | ||
| | | | | Task is not found | false | | ||
| | | | public boolean updateTaskStatusByID(UUID id, boolean status) | Task is found and status is updated | true | | ||
| | | | | Task is not found | false | | ||
| | | | | | | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class TaskTest { | ||
|
|
||
| @Test | ||
| public void getCorrectTaskNameTest() { | ||
| Task task = new Task("laundry", false); | ||
| Assertions.assertEquals("laundry", task.getTaskName()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getIncorrectTaskNameTest() { | ||
| Task task = new Task("laundry", false); | ||
| Assertions.assertNotEquals("shower", task.getTaskName()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getCorrectCompletedTest() { | ||
| Task task = new Task("laundry", false); | ||
| Assertions.assertEquals(false, task.getIsCompleted()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getIncorrectCompletedTest() { | ||
| Task task = new Task("laundry", false); | ||
| Assertions.assertNotEquals(true, task.getIsCompleted()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
String concatenation in a loop is not very efficient, as strings are immutable, so a new instance is created each iteration. Consder using stringbuilder instead