-
Notifications
You must be signed in to change notification settings - Fork 129
Thomas Kristiansen #122
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
Thomaskri0801
wants to merge
12
commits into
boolean-uk:main
Choose a base branch
from
Thomaskri0801: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
Thomas Kristiansen #122
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ee6c28f
First take on domain module
Thomaskri0801 567ec74
made test for changing status
Thomaskri0801 f210b2f
Implemented test for adding task
Thomaskri0801 304d81c
Implemented test for incomplete tasks
Thomaskri0801 cda46bb
method and test for view completed tasks
Thomaskri0801 b08c5ff
Implemented test for remove method
Thomaskri0801 3d58b9b
Test and method for remove task
Thomaskri0801 504b8b1
Test and method for alphabetical asc
Thomaskri0801 8070e3e
Test for alphabetical desc
Thomaskri0801 e5e576c
Implemented method for alphabetical desc
Thomaskri0801 ca61490
Implemented extensions and test for extensions
Thomaskri0801 9d798bf
Changed variables to private
Thomaskri0801 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,22 @@ | ||
| # TODO list | ||
|
|
||
| | Members | Methods | Scenario | Outputs | | ||
| |------------------------|------------------------|-------------------------|--------------------------------------| | ||
| | Arraylist\<Task> tasks | add(Task task) | Task is already in list | False | | ||
| | | | Task is not in the list | True | | ||
| | | viewTask() | | Display the list | | ||
| | | viewCompletedTasks() | | Display the completed tasks | | ||
| | | viewIncompletedTasks() | | Display the incompleted tasks | | ||
| | | search(Task task) | Task does not exist | Print it was not found | | ||
| | | | Task exist | Print it was found | | ||
| | | removeTask(Task task) | Task does not exist | Print it was not found | | ||
| | | | Task does exist | Task removed | | ||
| | | viewAlphabeticAsc() | | Display list alphabetical ascending | | ||
| | | viewAplhabeticDesc() | | Display list alphabetical descending | | ||
|
|
||
| # Task | ||
|
|
||
| | Members | Methods | Scenario | Outputs | | ||
| |------------------|------------------------------|----------|------------------------| | ||
| | boolean complete | changeStatus(boolean status) | True | complete becomes True | | ||
| | String name | | False | complete becomes 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,27 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| public class Task { | ||
| private String name; | ||
| private boolean complete; | ||
|
|
||
| public Task(String name) { | ||
| this.name = name; | ||
| this.complete = false; | ||
| } | ||
|
|
||
| public boolean isComplete() { | ||
| return complete; | ||
| } | ||
|
|
||
| public void setComplete(boolean complete) { | ||
| this.complete = complete; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void changeStatus(boolean status) { | ||
| complete = status; | ||
| } | ||
| } |
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,74 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Comparator; | ||
|
|
||
| public class TodoList { | ||
| private ArrayList<Task> tasks = new ArrayList<>(); | ||
|
|
||
| public boolean add(Task task) { | ||
| if(tasks.contains(task)) { | ||
| return false; | ||
| } else { | ||
| tasks.add(task); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| public ArrayList<Task> viewTasks() { | ||
| return tasks; | ||
| } | ||
|
|
||
| public ArrayList<Task> viewIncompleteTasks() { | ||
| ArrayList<Task> result = new ArrayList<>(); | ||
| for (int i = 0; i < tasks.size(); i++) { | ||
| if(!tasks.get(i).isComplete()) { | ||
| result.add(tasks.get(i)); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public ArrayList<Task> viewCompleteTasks() { | ||
| ArrayList<Task> result = new ArrayList<>(); | ||
| for (int i = 0; i < tasks.size(); i++) { | ||
| if(tasks.get(i).isComplete()) { | ||
| result.add(tasks.get(i)); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public Task search(Task task) { | ||
| if(tasks.contains(task)) { | ||
| return task; | ||
| } | ||
| System.out.println("The task was not found!"); | ||
| return null; | ||
| } | ||
|
|
||
| public void remove (Task task) { | ||
| if(tasks.contains(task)) { | ||
| tasks.remove(task); | ||
| } | ||
| } | ||
|
|
||
| public ArrayList<String> viewAlphabeticalAsc() { | ||
| ArrayList<String> result = new ArrayList<>(); | ||
| for (int i = 0; i < tasks.size(); i++) { | ||
| result.add(tasks.get(i).getName()); | ||
| } | ||
| result.sort(null); | ||
| return result; | ||
| } | ||
|
|
||
| public ArrayList<String> viewAlphabeticalDesc() { | ||
| ArrayList<String> result = new ArrayList<>(); | ||
| for (int i = 0; i < tasks.size(); i++) { | ||
| result.add(tasks.get(i).getName()); | ||
| } | ||
| result.sort(Comparator.reverseOrder()); | ||
| return result; | ||
| } | ||
| } | ||
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,42 @@ | ||
| package com.booleanuk.extension; | ||
|
|
||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.UUID; | ||
|
|
||
| public class TaskExtension { | ||
| private String name; | ||
| private boolean complete; | ||
| private String id; | ||
| private String date; | ||
|
|
||
| public TaskExtension(String name) { | ||
| this.name = name; | ||
| this.complete = false; | ||
| this.id = UUID.randomUUID().toString(); | ||
| this.date = java.time.ZonedDateTime.now().format(DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm")); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public boolean isComplete() { | ||
| return complete; | ||
| } | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public String getDate() { | ||
| return date; | ||
| } | ||
|
|
||
| public void changeStatus(boolean status) { | ||
| complete = status; | ||
| } | ||
|
|
||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/booleanuk/extension/TodoListExtensions.java
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,44 @@ | ||
| package com.booleanuk.extension; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
||
| public class TodoListExtensions { | ||
| private HashMap<String, TaskExtension> todoList; | ||
|
|
||
| public TodoListExtensions() { | ||
| this.todoList = new HashMap<>(); | ||
| } | ||
|
|
||
| public HashMap<String, TaskExtension> getTodoList() { | ||
| return todoList; | ||
| } | ||
|
|
||
| public String add(TaskExtension task) { | ||
| if(todoList.containsKey(task.getId())) { | ||
| return task.getId(); | ||
| } else { | ||
| todoList.put(task.getId(), task); | ||
| return task.getId(); | ||
| } | ||
| } | ||
|
|
||
| public boolean changeName(String id, String name) { | ||
| if (todoList.containsKey(id)) { | ||
| todoList.get(id).setName(name); | ||
| return true; | ||
| } else { | ||
| System.out.println("Task is not in the todo list!"); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| public boolean changeStatus(String id, boolean status) { | ||
| if (todoList.containsKey(id)) { | ||
| todoList.get(id).changeStatus(status); | ||
| return true; | ||
| } else { | ||
| System.out.println("Task is not in the todo list!"); | ||
| 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,17 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class TaskTest { | ||
|
|
||
| @Test | ||
| public void statusChanged() { | ||
| Task task = new Task("Take out the garbage"); | ||
| task.changeStatus(true); | ||
| Assertions.assertTrue(task.isComplete()); | ||
|
|
||
| task.changeStatus(false); | ||
| Assertions.assertFalse(task.isComplete()); | ||
| } | ||
| } |
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
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.
You could just sort the original list and return it here, rather than copying lists