Moved null-check to loading method

This commit is contained in:
David Guler 2022-10-24 12:32:28 +02:00
parent 2c61cd3393
commit 0d24bcc2ad
1 changed files with 4 additions and 7 deletions

View File

@ -46,9 +46,6 @@ public class JsonPlantDatabase implements PlantDatabase {
*/
@Override
public List<Plant> getPlantList(HardinessZone zone) throws IOException, HardinessZoneNotSetException {
if (zone == null) {
throw new HardinessZoneNotSetException();
}
if (plantMap.isEmpty() || zone != currentZone) {
loadPlantList(zone);
}
@ -60,9 +57,6 @@ public class JsonPlantDatabase implements PlantDatabase {
*/
@Override
public Optional<Plant> getPlantById(long id) throws HardinessZoneNotSetException, IOException {
if (currentZone == null) {
throw new HardinessZoneNotSetException();
}
if (plantMap.isEmpty()) {
loadPlantList(currentZone);
}
@ -75,7 +69,10 @@ public class JsonPlantDatabase implements PlantDatabase {
* @param zone The {@link HardinessZone} for which data is to be loaded
* @throws IOException If the database cannot be accessed
*/
private void loadPlantList(HardinessZone zone) throws IOException {
private void loadPlantList(HardinessZone zone) throws IOException, HardinessZoneNotSetException {
if (zone == null) {
throw new HardinessZoneNotSetException();
}
if (dataSource != null) {
currentZone = zone;
ObjectMapper mapper = new ObjectMapper();