99 lines
3.4 KiB
Java
99 lines
3.4 KiB
Java
package hhn.temp.project;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
public class AssignmentManager {
|
|
private Map<Integer, Worker> workerMap;
|
|
private Map<Integer, Task> taskMap;
|
|
private int workerIdCounter;
|
|
private int taskIdCounter;
|
|
private UserCommands userInterface;
|
|
|
|
public AssignmentManager() {
|
|
workerMap = new HashMap<>();
|
|
taskMap = new HashMap<>();
|
|
workerIdCounter = 1000;
|
|
taskIdCounter = 0;
|
|
userInterface = new UserCommands(this);
|
|
}
|
|
public Map<Integer, Task> getTaskMap() {
|
|
return taskMap;
|
|
}
|
|
public Map<Integer, Worker> getWorkerMap() {return workerMap;}
|
|
|
|
public int createWorker(String name) {
|
|
Worker worker = new Worker(name, ++workerIdCounter);
|
|
workerMap.put(workerIdCounter, worker);
|
|
return workerIdCounter;
|
|
}
|
|
public void removeWorker(int workerId) {
|
|
if (!workerMap.containsKey(workerId)) {
|
|
throw new IllegalArgumentException("WorkerId must exist in order to remove it");
|
|
}
|
|
workerMap.remove(workerId);
|
|
}
|
|
public int addTask(int workerId, String name, String description) {
|
|
if (!workerMap.containsKey(workerId) || name == null || description == null) {
|
|
throw new IllegalArgumentException("WorkerId must exist and name or description can't be null");
|
|
}
|
|
Task task = new Task(++taskIdCounter, workerId, name, description);
|
|
taskMap.put(taskIdCounter, task);
|
|
return taskIdCounter;
|
|
}
|
|
public Task getTask(int taskId) {
|
|
if (!taskMap.containsKey(taskId)) {
|
|
throw new IllegalArgumentException("Task Id does not exist");
|
|
}
|
|
return taskMap.get(taskId);
|
|
}
|
|
public Worker getWorker(int workerId) {
|
|
if (!workerMap.containsKey(workerId)) {
|
|
throw new IllegalArgumentException("Worker Id does not exist");
|
|
}
|
|
return workerMap.get(workerId);
|
|
}
|
|
public void editTask(int workerId, int taskId, String name, String description) {
|
|
if (!workerMap.containsKey(workerId) || !taskMap.containsKey(taskId)) {
|
|
throw new IllegalArgumentException("Task Id or Worker Id does not exist");
|
|
}
|
|
Task task = taskMap.get(taskId);
|
|
task.setName(name);
|
|
task.setDescription(description);
|
|
}
|
|
public void removeTask(int taskId) {
|
|
if (!taskMap.containsKey(taskId)) {
|
|
throw new IllegalArgumentException("Task Id does not exist");
|
|
}
|
|
taskMap.remove(taskId);
|
|
}
|
|
public void finishTask(int workerId, int taskId) {
|
|
if (!workerMap.containsKey(workerId) || !taskMap.containsKey(taskId)) {
|
|
throw new IllegalArgumentException("Task Id or Worker Id does not exist");
|
|
}
|
|
Task task = taskMap.get(taskId);
|
|
task.setTaskState(TaskState.FINISHED);
|
|
}
|
|
public void unfinishTask(int workerId, int taskId) {
|
|
if (!workerMap.containsKey(workerId) || !taskMap.containsKey(taskId)) {
|
|
throw new IllegalArgumentException("Task Id or Worker Id does not exist");
|
|
}
|
|
Task task = taskMap.get(taskId);
|
|
task.setTaskState(TaskState.IN_PROGRESS);
|
|
}
|
|
public UserCommands getUserCommands() {
|
|
return userInterface;
|
|
}
|
|
|
|
public void startCLI() {
|
|
userInterface.start();
|
|
}
|
|
|
|
public void stopCLI() {
|
|
userInterface.stop();
|
|
}
|
|
|
|
}
|