implemented Methods

removeTasksForCrop and getTaskForCrop
in JsonTaskDatabase
This commit is contained in:
schrom01
2022-10-31 16:23:49 +01:00
parent 0e4e207581
commit 5bfebdc92c
4 changed files with 59 additions and 9 deletions
@@ -52,14 +52,29 @@ public class JsonTaskDatabase implements TaskDatabase{
return taskMap.values().stream().filter(task -> task.isInTimePeriode(start, end)).toList();
}
/**
* Method get all Tasks for a specific Crop
* @param cropId the cropId
* @return List of Tasks for given Crop
*/
@Override
public List<Task> getTaskForCrop(Crop crop) {
return null; //TODO implement
public List<Task> getTaskForCrop(long cropId) throws IOException {
if(taskMap.isEmpty()) {
loadTaskListFromFile();
}
return taskMap.values().stream().filter(task -> task.getCropId() == cropId).toList();
}
/**
* Method remove all Tasks for a specific Crop
* @param cropId the crop
*/
@Override
public void removeTasksForCrop(Crop crop) {
// TODO implement
public void removeTasksForCrop(long cropId) throws IOException {
if(taskMap.isEmpty()) {
loadTaskListFromFile();
}
taskMap.values().removeIf(task -> task.getCropId() == cropId);
}
/**
@@ -25,9 +25,20 @@ public interface TaskDatabase {
*/
List<Task> getTaskList(LocalDate start, LocalDate end) throws IOException;
List<Task> getTaskForCrop(Crop crop); //TODO Javadoc
/**
* Method get all Tasks for a specific Crop
* @param cropId the cropId
* @return List of Tasks for given Crop
* @throws IOException If the database cannot be accessed
*/
List<Task> getTaskForCrop(long cropId) throws IOException;
void removeTasksForCrop(Crop crop); // TODO Javadoc
/**
* Method remove all Tasks for a specific Crop
* @param cropId the cropId
* @throws IOException If the database cannot be accessed
*/
void removeTasksForCrop(long cropId) throws IOException;
/**
* Saves the {@link Task} in the Cache.