package lk.ac.pdn.ceit.tasks; import java.util.ArrayList; import java.util.List; import lk.ac.pdn.ceit.tasks.entities.Task; public class InMemoryTaskManager implements TaskManager { private List tasks = new ArrayList<>(); private int lastId = 0; @Override public Task createNewTask(String title, String description) { lastId++; Task task = new Task(lastId, title, description); // Add to the internally maintained task list tasks.add(task); return task; } @Override public Task findById(int id) { for (Task task : tasks) { if (task.getId() == id) { return task; } } return null; } @Override public void updateTask(Task task) { // Find the internal position of the task in the tasks list int index = 0; for(; index < tasks.size(); index++) { if (tasks.get(index).getId() == task.getId()) { break; } } // Replace the task object (related to that internal position) tasks.set(index, task); } }