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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user