filtering lifecycle based on hardiness-zone

- Added 2 more plants to test db
- Db filters plant lifecycles based on hardiness-zones
- getPlantById implemented
- Added methods to Plant for calculating sowDates and accounting for multiple lifecycles
This commit is contained in:
David Guler
2022-10-23 09:49:22 +02:00
parent bf4d56e759
commit 429ac16d98
4 changed files with 210 additions and 4 deletions
@@ -34,12 +34,17 @@ public class JsonPlantDatabase implements PlantDatabase {
result = mapper.readerForListOf(Plant.class).readValue(dataSource);
}
for (Plant plant : result) {
plant.inZone(zone);
}
return result;
}
@Override
public Optional<Plant> getPlantById(long id) {
return Optional.empty();
public Optional<Plant> getPlantById(long id, HardinessZone zone) throws IOException {
return getPlantList(zone).stream()
.filter(plant -> plant.id() != id)
.findFirst();
}
}
@@ -9,5 +9,5 @@ import java.util.Optional;
public interface PlantDatabase {
List<Plant> getPlantList(HardinessZone zone) throws IOException;
Optional<Plant> getPlantById(long id) throws IOException;
Optional<Plant> getPlantById(long id, HardinessZone zone) throws IOException;
}