1 package tim.prune.function.weather;
3 import java.util.ArrayList;
7 * Model for results of weather forecast from openweathermap.org
9 public class WeatherResults
11 /** List of forecasts */
12 private ArrayList<SingleForecast> _forecastList = new ArrayList<SingleForecast>();
13 /** Flag whether the units are metric (Celsius) or not (Fahrenheit) */
14 private boolean _tempsCelsius = true;
16 private String _locationName = null;
17 /** Last update timestamp */
18 private String _updateTime = null;
19 /** Sunrise and sunset times as HH:MM */
20 private String _sunriseTime = null, _sunsetTime = null;
24 * Add a single forecast to this model (for the current weather)
25 * @param inResults current results
27 public void setForecast(SingleForecast inResults)
29 _forecastList.clear();
30 if (inResults != null) {
31 _forecastList.add(inResults);
36 * Add a list of forecasts to this model
37 * @param inList list of forecasts to add
39 public void setForecasts(ArrayList<SingleForecast> inList)
41 _forecastList.clear();
42 if (inList != null && inList.size() > 0) {
43 _forecastList.addAll(inList);
47 /** @return the number of forecasts */
48 public int getNumForecasts()
50 return _forecastList.size();
54 * @param inIndex index of forecast starting from 0
55 * @return the specified forecast
57 public SingleForecast getForecast(int inIndex)
59 if (inIndex < 0 || inIndex >= getNumForecasts()) {
62 return _forecastList.get(inIndex);
66 * Clear the list of forecasts
70 _forecastList.clear();
71 _sunriseTime = _sunsetTime = null;
76 * @param inCelsius true for celsius, false for fahrenheit
78 public void setTempsCelsius(boolean inCelsius)
80 _tempsCelsius = inCelsius;
83 /** @return true if this forecast uses Celsius */
84 public boolean isCelsius() {
89 * Set the sunrise and sunset times (only from current weather, not from forecast)
90 * @param inRiseTime sunrise time as YYYY-MM-DDThh:mm:ss
91 * @param inSetTime sunset time as YYYY-MM-DDThh:mm:ss
93 public void setSunriseSunsetTimes(String inRiseTime, String inSetTime)
95 _sunriseTime = _sunsetTime = null;
96 if (inRiseTime != null && inRiseTime.length() == 19
97 && inSetTime != null && inSetTime.length() == 19)
99 _sunriseTime = inRiseTime.substring(11, 16);
100 _sunsetTime = inSetTime.substring(11, 16);
104 /** @return sunrise time as HH:MM */
105 public String getSunriseTime() {
108 /** @return sunset time as HH:MM */
109 public String getSunsetTime() {
113 /** @param inName location name */
114 public void setLocationName(String inName) {
115 _locationName = inName;
118 /** @return location name */
119 public String getLocationName() {
120 return _locationName;
123 /** @param inTime timestamp of forecast */
124 public void setUpdateTime(String inTime) {
125 _updateTime = inTime;
128 /** @return timestamp of last update */
129 public String getUpdateTime()