#27 gardenplanmodel bugfixed cropid
This commit is contained in:
parent
d45b8e116e
commit
2361afd537
|
@ -12,9 +12,9 @@ import ch.zhaw.gartenverwaltung.types.Task;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,6 +24,7 @@ public class Gardenplanmodel {
|
||||||
private GardenPlan gardenPlan;
|
private GardenPlan gardenPlan;
|
||||||
private List<Crop> cropList;
|
private List<Crop> cropList;
|
||||||
private TaskListModel taskListModel;
|
private TaskListModel taskListModel;
|
||||||
|
private Object IllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of Gardenplan model
|
* Constructor of Gardenplan model
|
||||||
|
@ -63,9 +64,8 @@ public class Gardenplanmodel {
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public void removeCrop(Crop crop) throws IOException {
|
public void removeCrop(Crop crop) throws IOException {
|
||||||
|
|
||||||
gardenPlan.removeCrop(crop);
|
gardenPlan.removeCrop(crop);
|
||||||
taskListModel.removeTasksForCrop(crop);
|
taskListModel.removeTasksForCrop(crop.getCropId().orElseThrow(IllegalArgumentException::new));
|
||||||
cropList = gardenPlan.getCrops();
|
cropList = gardenPlan.getCrops();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -159,5 +159,8 @@ public class JsonTaskDatabase implements TaskDatabase{
|
||||||
(res, task) -> res.put(task.getId(), task),
|
(res, task) -> res.put(task.getId(), task),
|
||||||
(existing, replacement) -> {});
|
(existing, replacement) -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Long maxId = taskMap.isEmpty() ? 0L : Collections.max(taskMap.keySet());
|
||||||
|
idProvider = new IdProvider(maxId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,11 @@ public class Task {
|
||||||
* default constructor
|
* default constructor
|
||||||
* (used by Json deserializer)
|
* (used by Json deserializer)
|
||||||
*/
|
*/
|
||||||
public Task(long cropId){
|
public Task(){
|
||||||
name= "";
|
name= "";
|
||||||
description= "";
|
description= "";
|
||||||
startDate = LocalDate.now();
|
startDate = LocalDate.now();
|
||||||
this.cropId = cropId;
|
// this.cropId = cropId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task(String name, String description, LocalDate startDate, long cropId) {
|
public Task(String name, String description, LocalDate startDate, long cropId) {
|
||||||
|
|
Loading…
Reference in New Issue