diff --git a/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java b/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java index abd49bd..4f9384d 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/taskList/TaskListModel.java @@ -62,27 +62,53 @@ public class TaskListModel { /** * Method to remove all Tasks for a specific Crop * @param cropId The crop which is removed + * @throws IOException If the database cannot be accessed */ public void removeTasksForCrop(long cropId) throws IOException { taskDatabase.removeTasksForCrop(cropId); } + /** + * Method to remove a Task from Database + * @param task the Task to remove + * @throws IOException If the database cannot be accessed + */ public void removeTask(Task task) throws IOException { taskDatabase.removeTask(task); } + /** + * Method to get all Tasks + * @return List of all Tasks + * @throws IOException If the database cannot be accessed + */ public List getTaskList() throws IOException { return getFilteredTaskList(LocalDate.MIN, LocalDate.MAX); } + /** + * Method to get all Tasks which are today or in future + * @return List of Tasks + * @throws IOException If the database cannot be accessed + */ public List getFutureTasks() throws IOException { return getFilteredTaskList(LocalDate.now(), LocalDate.MAX); } + /** + * Method to get all Tasks which are today or in past + * @return List of Tasks + * @throws IOException If the database cannot be accessed + */ public List getPastTasks() throws IOException { return getFilteredTaskList(LocalDate.MIN, LocalDate.now()); } + /** + * Method to get an Array of 7 Tasklists for the next 7 days. Index 0 is Tasklist for Today. + * @return Array with length 7 (List[]) + * @throws IOException If the database cannot be accessed + */ public List[] getTasksUpcomingWeek() throws IOException { List[] listArray = new List[7]; for(int i = 0; i < 7; i++) { @@ -92,10 +118,23 @@ public class TaskListModel { return listArray; } + /** + * Method to get Tasklist filtered by date. + * @param start the start date for the filter + * @param end the end date for the filter + * @return List of Tasks matched by the filter + * @throws IOException If the database cannot be accessed + */ public List getFilteredTaskList(LocalDate start, LocalDate end) throws IOException { return getSortedTaskList(taskDatabase.getTaskList(start, end), sortByStartDate); } + /** + * Method to sort a Tasklist by a given Comparator + * @param taskList The Tasklist to sort + * @param comparator the comparator to sort + * @return a sorted coppy of the given Tasklist + */ private List getSortedTaskList(List taskList, Comparator comparator) { return taskList.stream().sorted(comparator).collect(Collectors.toList()); }