From 0d24bcc2adb58723f367a16dacdf12cfe7bfd73c Mon Sep 17 00:00:00 2001 From: David Guler Date: Mon, 24 Oct 2022 12:32:28 +0200 Subject: [PATCH] Moved null-check to loading method --- .../zhaw/gartenverwaltung/io/JsonPlantDatabase.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonPlantDatabase.java b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonPlantDatabase.java index 4ae2435..5591acd 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/io/JsonPlantDatabase.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/JsonPlantDatabase.java @@ -46,9 +46,6 @@ public class JsonPlantDatabase implements PlantDatabase { */ @Override public List 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 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();