Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
| Class | Members | Method | Scenario | Output | Tested? |
|----------|------------------------|----------------------------------------------|---------------------|------------|---------|
| TodoList | List<Task> tasks | add(String description) | | Void | Yes |
| | | getTasks() | | List<Task> | Yes |
| | | getCompleteTasks() | | List<Task> | Yes |
| | | getIncompleteTasks() | | List<Task> | Yes |
| | | search(String search) | Task exists | True | Yes |
| | | | Task does not exist | False | |
| | | remove(String description) | Task exists | True | Yes |
| | | | Task doesnt exist | False | |
| | | getAlphAsc() | | List<Task> | Yes |
| | | getAlphDesc() | | List<Task> | Yes |
| | | | | | |
| | | getById(String id) | Task exists | Task | Yes |
| | | | Task does not exist | null | |
| | | updateDescription(String id, String newDesc) | Task exists | True | Yes |
| | | | Task does not exist | False | |
| | | changeStatus(String id) | Task exists | True | Yes |
| | | | Task does not exist | False | |
| Task | boolean completed | | | | |
| | String description | | | | |
| | String ID | completeTask( ) | Task was incomplete | True | Yes |
| | LocalDate creationDate | | Task was complete | False | Yes |
| | | incompleteTask() | Task was complete | True | Yes |
| | | | Task was incomplete | False | Yes |
| | | getCreationDate() | | LocalDate | |
35 changes: 35 additions & 0 deletions src/main/java/com/booleanuk/core/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.booleanuk.core;

public class Task {
private String description;
private boolean completeStatus;

public Task(String description){
this.completeStatus = false;
this.description = description;
}

public String getDescription(){
return this.description;
}

public boolean getCompleteStatus(){
return this.completeStatus;
}

public boolean completeTask(){
if (this.completeStatus){
return false;
}
this.completeStatus = true;
return true;
}

public boolean incompleteTask(){
if (!this.completeStatus){
return false;
}
this.completeStatus = false;
return true;
}
}
72 changes: 72 additions & 0 deletions src/main/java/com/booleanuk/core/TodoList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,77 @@
package com.booleanuk.core;

import java.util.ArrayList;
import java.util.List;

public class TodoList {
private List<Task> tasks;

public TodoList(){
tasks = new ArrayList<>();
}

public void add(String desc){
Task newTask = new Task(desc);
tasks.add(newTask);
}

public List<Task> getTasks(){
return this.tasks;
}

public List<Task> getCompleteTasks(){
List<Task> completeTasks = new ArrayList<>();

for(Task task : this.tasks){
if(task.getCompleteStatus()){
completeTasks.add(task);
}
}
return completeTasks;
}

public List<Task> getIncompleteTasks(){
List<Task> completeTasks = new ArrayList<>();

for(Task task : this.tasks){
if(!task.getCompleteStatus()){
completeTasks.add(task);
}
}
return completeTasks;
}

public boolean search(String desc){
for(Task task : this.tasks){
if(task.getDescription().equals(desc)){
return true;
}
}
return false;
}

public boolean remove(String desc){
for (int i = 0; i < this.tasks.size(); i++){
if(desc.equals(this.tasks.get(i).getDescription())){
this.tasks.remove(i);
return true;
}
}
return false;
}

public List<Task> getAlphAsc(){
List<Task> returnVal = new ArrayList<>(List.copyOf(this.tasks));

returnVal.sort((a, b) -> {return a.getDescription().compareTo(b.getDescription());});
return returnVal;
}

public List<Task> getAlphDesc(){
List<Task> returnVal = new ArrayList<>(List.copyOf(this.tasks));

returnVal.sort((a, b) -> {return b.getDescription().compareTo(a.getDescription());});
return returnVal;
}

}
60 changes: 60 additions & 0 deletions src/main/java/com/booleanuk/extension/TaskExt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.booleanuk.extension;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.UUID;

public class TaskExt {
private String description;
private boolean completeStatus;
private String id;
private LocalDateTime creationTime;

public TaskExt(String description){
this.completeStatus = false;
this.description = description;
this.id = UUID.randomUUID().toString();
this.creationTime = LocalDateTime.now();
}

public String getDescription(){
return this.description;
}

public boolean getCompleteStatus(){
return this.completeStatus;
}

public boolean completeTask(){
if (this.completeStatus){
return false;
}
this.completeStatus = true;
return true;
}

public boolean incompleteTask(){
if (!this.completeStatus){
return false;
}
this.completeStatus = false;
return true;
}

public String getId(){
return this.id;
}

public void setDescription(String newDesc){
this.description = newDesc;
}

public void setCompleteStatus(boolean status){
this.completeStatus = status;
}

public LocalDateTime getCreationTime(){
return this.creationTime;

}
}
108 changes: 108 additions & 0 deletions src/main/java/com/booleanuk/extension/TodoListExt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.booleanuk.extension;

import com.booleanuk.extension.TaskExt;

import java.util.ArrayList;
import java.util.List;

public class TodoListExt {
private List<TaskExt> tasks;

public TodoListExt(){
tasks = new ArrayList<>();
}

public void add(String desc){
TaskExt newTask = new TaskExt(desc);
tasks.add(newTask);
}

public List<TaskExt> getTasks(){
return this.tasks;
}

public List<TaskExt> getCompleteTasks(){
List<TaskExt> completeTasks = new ArrayList<>();

for(TaskExt task : this.tasks){
if(task.getCompleteStatus()){
completeTasks.add(task);
}
}
return completeTasks;
}

public List<TaskExt> getIncompleteTasks(){
List<TaskExt> completeTasks = new ArrayList<>();

for(TaskExt task : this.tasks){
if(!task.getCompleteStatus()){
completeTasks.add(task);
}
}
return completeTasks;
}

public boolean search(String desc){
for(TaskExt task : this.tasks){
if(task.getDescription().equals(desc)){
return true;
}
}
return false;
}

public boolean remove(String desc){
for (int i = 0; i < this.tasks.size(); i++){
if(desc.equals(this.tasks.get(i).getDescription())){
this.tasks.remove(i);
return true;
}
}
return false;
}

public List<TaskExt> getAlphAsc(){
List<TaskExt> returnVal = new ArrayList<>(List.copyOf(this.tasks));

returnVal.sort((a, b) -> {return a.getDescription().compareTo(b.getDescription());});
return returnVal;
}

public List<TaskExt> getAlphDesc(){
List<TaskExt> returnVal = new ArrayList<>(List.copyOf(this.tasks));

returnVal.sort((a, b) -> {return b.getDescription().compareTo(a.getDescription());});
return returnVal;
}

public TaskExt getById(String id){
for(TaskExt task : this.tasks){
if(id.equals(task.getId())){
return task;
}
}
return null;
}

public boolean updateDescription(String id, String newDesc){
for(TaskExt task : this.tasks){
if(task.getId().equals(id)){
task.setDescription(newDesc);
return true;
}
}
return false;
}

public boolean changeStatus(String id){
for(TaskExt task : this.tasks){
if(task.getId().equals(id)){
task.setCompleteStatus(!task.getCompleteStatus());
return true;
}
}
return false;
}

}
35 changes: 35 additions & 0 deletions src/test/java/com/booleanuk/core/TaskTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

public class TaskTest {

@Test
public void testCompleteIncompleteTask(){
TodoList todo = new TodoList();

todo.add("Test");

Task task = todo.getTasks().get(0);
boolean taskCompleted = task.getCompleteStatus();

Assertions.assertFalse(taskCompleted);

Assertions.assertTrue(task.completeTask());

taskCompleted = task.getCompleteStatus();
Assertions.assertTrue(taskCompleted);

Assertions.assertFalse(task.completeTask());

Assertions.assertTrue(task.incompleteTask());

Assertions.assertFalse(task.getCompleteStatus());

Assertions.assertFalse(task.incompleteTask());
}
}
Loading
Loading