added new Methods to filter List by Crop ID
This commit is contained in:
parent
38288f8561
commit
b7d08944a6
|
@ -12,6 +12,7 @@ import java.time.LocalDate;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TaskListModel {
|
||||
|
@ -78,6 +79,10 @@ public class TaskListModel {
|
|||
taskDatabase.removeTask(task);
|
||||
}
|
||||
|
||||
private List<Task> filterListByCrop(List<Task> taskList, Long cropId) {
|
||||
return taskList.stream().filter(task -> task.getCropId() == cropId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get all Tasks
|
||||
* @return List of all Tasks
|
||||
|
@ -87,6 +92,15 @@ public class TaskListModel {
|
|||
return getFilteredTaskList(LocalDate.MIN, LocalDate.MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get all Tasks for specific Crop
|
||||
* @return List of all Tasks for with given CropID
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<Task> getTaskListForCrop(Long cropId) throws IOException {
|
||||
return filterListByCrop(getTaskList(), cropId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get all Tasks which are today or in future
|
||||
* @return List of Tasks
|
||||
|
@ -96,6 +110,15 @@ public class TaskListModel {
|
|||
return getFilteredTaskList(LocalDate.now(), LocalDate.MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get all Tasks which are today or in future for specific Crop
|
||||
* @return List of Tasks with given crop ID
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<Task> getFutureTasksForCrop(Long cropId) throws IOException {
|
||||
return filterListByCrop(getFutureTasks(), cropId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get all Tasks which are today or in past
|
||||
* @return List of Tasks
|
||||
|
@ -105,6 +128,15 @@ public class TaskListModel {
|
|||
return getFilteredTaskList(LocalDate.MIN, LocalDate.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get all Tasks which are today or in past for specifc crop
|
||||
* @return List of Tasks with given grop id
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<Task> getPastTasksForCrop(Long cropId) throws IOException {
|
||||
return filterListByCrop(getPastTasks(), cropId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get an List of 7 Tasklists for the next 7 days. Index 0 is Tasklist for Today.
|
||||
* @return List with length 7 (List<List<Task>>)
|
||||
|
@ -119,6 +151,20 @@ public class TaskListModel {
|
|||
return dayTaskList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get an List of 7 Tasklists for the next 7 days. (Filtered Index 0 is Tasklist for Today.
|
||||
* @return List with length 7 (List<List<Task>>)
|
||||
* @throws IOException If the database cannot be accessed
|
||||
*/
|
||||
public List<List<Task>> getTasksUpcomingWeekForCrop(Long cropId) throws IOException {
|
||||
List<List<Task>> dayTaskList = new ArrayList<>();
|
||||
for(int i = 0; i < 7; i++) {
|
||||
LocalDate date = LocalDate.now().plusDays(i);
|
||||
dayTaskList.add(filterListByCrop(taskDatabase.getTaskList(date, date), cropId));
|
||||
}
|
||||
return dayTaskList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get Tasklist filtered by date.
|
||||
* @param start the start date for the filter
|
||||
|
|
Loading…
Reference in New Issue