AssignmentManager.java
package hhn.temp.project;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AssignmentManager {
Map<Integer, Worker> workerMap;
Map<Integer, Task> taskMap;
int workerIdCounter;
int taskIdCounter;
public AssignmentManager() {
workerMap = new HashMap<>();
taskMap = new HashMap<>();
int workerIdCounter = 1000;
int taskIdCounter = 0;
}
public int createWorker(String name) {
Worker worker = new Worker(name, ++workerIdCounter);
workerMap.put(workerIdCounter, worker);
return workerIdCounter;
}
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, this);
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 Map<Integer, Task> getTaskMap() {
return taskMap;
}
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);
}
}