Moved null-check to loading method
This commit is contained in:
parent
2c61cd3393
commit
0d24bcc2ad
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue