diff --git a/src/main/java/edu/unl/cse/soft160/json_connections/connector/OpenWeatherConnector.java b/src/main/java/edu/unl/cse/soft160/json_connections/connector/OpenWeatherConnector.java index f0b3d47e1045cf6a86bac8e0d857b08c8f0ed606..7bedc47696eff19a0af4c538b577592d4f1f0189 100644 --- a/src/main/java/edu/unl/cse/soft160/json_connections/connector/OpenWeatherConnector.java +++ b/src/main/java/edu/unl/cse/soft160/json_connections/connector/OpenWeatherConnector.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.NoSuchElementException; import java.util.Set; /** @@ -372,10 +373,10 @@ public class OpenWeatherConnector { * * @param listName the key to access the list * @param timestamp the timestamp of the list entry - * @return the object of interest, or null if the list or the timestamp are not - * present + * @return the object of interest, or null if the list is not present + * @throws NoSuchElementException if the timestamp is not present in the list */ - private JSONObject getListEntry(String listName, Date timestamp) { + private JSONObject getListEntry(String listName, Date timestamp) throws NoSuchElementException { JSONObject listEntry = null; if (data.containsKey(listName)) { JSONArray list = (JSONArray) data.get(listName); @@ -384,6 +385,9 @@ public class OpenWeatherConnector { listEntry = (JSONObject) entry; } } + if (listEntry == null) { + throw new NoSuchElementException("The requested data is not available for " + timestamp + "."); + } } return listEntry; }