This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskService.java
102 lines (92 loc) · 2.31 KB
/
TaskService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package services;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Eric Slutz
*
* SNHU CS-320
* Project 1
*
*/
public class TaskService {
private final List<Task> tasks;
/**
* Default constructor for TaskService that initializes a new list of tasks.
*/
public TaskService() {
this.tasks = new ArrayList<Task>();
}
/**
* Getter for the list of tasks.
*
* @return list of tasks
*/
public List<Task> getTasks() {
return tasks;
}
/**
* Method to add a new task to the list of tasks.
*
* @param newTask task to be added to the tasks list
* @return true for task added, false for task already exists
*/
public boolean addTask(final Task newTask) {
boolean taskExists = false;
for(Task task : tasks) {
if (newTask.getTaskId() == task.getTaskId()) {
taskExists = true;
}
}
// If task doesn't exist, add it to the tasks list.
if (!taskExists) {
this.tasks.add(newTask);
// Return true for adding task to list.
return true;
} else {
// Task already exists, return false for adding the task.
return false;
}
}
/**
* Method to delete a task from the list with the matching id.
*
* @param id value to match to existing ids
* @return true for task found and deleted, false if not found
*/
public boolean deleteContact(final String id) {
return this.tasks.removeIf(task -> (task.getTaskId() == id));
}
/**
* Method to update the name of a task from the list with the matching id.
*
* @param id value to match to existing ids
* @return true for task found and updated, false if not found
*/
public boolean updateName(final String id, final String firstName) {
boolean updateComplete = false;
for(Task task : tasks) {
if (task.getTaskId() == id) {
task.setName(firstName);
updateComplete = true;
}
}
return updateComplete;
}
/**
* Method to update the description of a task from the list with the matching id.
*
* @param id value to match to existing ids
* @return true for task found and updated, false if not found
*/
public boolean updateDescription(final String id, final String description) {
boolean updateComplete = false;
for(Task task : tasks) {
if (task.getTaskId() == id) {
task.setDescription(description);
updateComplete = true;
}
}
return updateComplete;
}
}