This repository was archived by the owner on Feb 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTaskManager.java
More file actions
123 lines (107 loc) · 2.75 KB
/
Copy pathTaskManager.java
File metadata and controls
123 lines (107 loc) · 2.75 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main.framework;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Sphiinx on 4/20/2016.
*/
public class TaskManager {
/**
* The master task list for the program.
*/
private List<Task> task_list = new ArrayList<>();
/**
* The master status for the program.
*/
private static String status;
/**
* The master boolean for stopping the task manager.
*/
private static boolean stop_task_manager;
/**
* Loops through all of the tasks in the task list until it finds an valid task that it can execute.
*
* @param sleep The sleep delay in milliseconds after executing a task.
*/
public void loop(int sleep) {
while (!stop_task_manager) {
Task task = getValidTask();
if (task != null) {
status = task.toString();
task.execute();
}
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
/**
* Adds all of the given tasks to the task list.
*
* @param tasks The tasks to be added to the task list.
*/
public void addTask(Task... tasks) {
for (Task task : tasks) {
if (!task_list.contains(task))
task_list.add(task);
}
}
/**
* Removed the specified task from the task list.
*
* @param task The specified task to be removed from the task list.
*/
public void removeTask(Task task) {
if (task_list.contains(task))
task_list.remove(task);
}
/**
* Clears all of the tasks in the task list.
*/
public void clearTasks() {
task_list.clear();
}
/**
* Gets the count of all the tasks in the task list.
*
* @return A int count of all the tasks in the task list.
*/
public int getTaskCount() {
return task_list.size();
}
/**
* Filters through all of the tasks in the task list returning a valid task.
*
* @return A validated task.
*/
private Task getValidTask() {
for (Task task : task_list) {
if (task.validate())
return task;
}
return null;
}
/**
* Gets the current status.
*
* @return The current status.
*/
public String getStatus() {
return status;
}
/**
* Stops the task manager.
*/
public static void stopTaskManager() {
stop_task_manager = true;
}
/**
* Sets the status of the program.
*
* @param status The string of text to set the status.
*/
public static void setStatus(String status) {
TaskManager.status = status;
}
}