1 package tim.prune.function.weather;
4 * Class to hold a set of (up to six) weather results,
5 * so that they don't have to be downloaded again
9 /** Array of six results */
10 private WeatherResults[] _results = new WeatherResults[6];
11 /** Location id for which these results apply */
12 private String _locationId = null;
15 * Clear the array, forget all results
19 for (int i=0; i<6; i++) {
25 * Get the specified weather results, if available
26 * @param inLocationId location id
27 * @param inCurrent true to get the current weather
28 * @param inDaily true to get the daily forecast
29 * @param inHourly true to get the three-hourly forecast
30 * @param inCelsius true to get celsius
31 * @return weather results, or null if not available
33 public WeatherResults getWeather(String inLocationId,
34 boolean inCurrent, boolean inDaily, boolean inHourly, boolean inCelsius)
37 if (inLocationId == null || _locationId == null || !inLocationId.equals(_locationId)) {
40 // check forecast type
41 final int numTypesGiven = (inCurrent ? 1 : 0) + (inDaily ? 1 : 0) + (inHourly ? 1 : 0);
42 if (numTypesGiven != 1) {
43 System.err.println("getWeather, numtypesgiven = " + numTypesGiven);
44 return null; // can't ask for more or less than one type
46 // Pull out from array
47 final int index = (inCurrent ? 0 : (inDaily ? 2 : 4)) + (inCelsius ? 1 : 0);
48 return _results[index];
52 * Store the given weather results
53 * @param inResults results object
54 * @param inLocationId location id
55 * @param inCurrent true if this is the current weather
56 * @param inDaily true if this is the daily forecast
57 * @param inHourly true if this is the three-hourly forecast
58 * @param inCelsius true if numbers are celsius
60 public void setWeather(WeatherResults inResults, String inLocationId,
61 boolean inCurrent, boolean inDaily, boolean inHourly, boolean inCelsius)
64 if (inLocationId == null || inLocationId.equals("")) {
67 if (_locationId == null || !inLocationId.equals(_locationId))
69 // coordinates have changed
71 _locationId = inLocationId;
73 // check forecast type
74 final int numTypesGiven = (inCurrent ? 1 : 0) + (inDaily ? 1 : 0) + (inHourly ? 1 : 0);
75 if (numTypesGiven != 1) {
76 System.err.println("setWeather, numtypesgiven = " + numTypesGiven);
77 return; // can't set more or less than one type
80 final int index = (inCurrent ? 0 : (inDaily ? 2 : 4)) + (inCelsius ? 1 : 0);
81 _results[index] = inResults;