]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/weather/WeatherResults.java
Version 16, February 2014
[GpsPrune.git] / tim / prune / function / weather / WeatherResults.java
1 package tim.prune.function.weather;
2
3 import java.util.ArrayList;
4
5
6 /**
7  * Model for results of weather forecast from openweathermap.org
8  */
9 public class WeatherResults
10 {
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;
15         /** Location name */
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;
21
22
23         /**
24          * Add a single forecast to this model (for the current weather)
25          * @param inResults current results
26          */
27         public void setForecast(SingleForecast inResults)
28         {
29                 _forecastList.clear();
30                 if (inResults != null) {
31                         _forecastList.add(inResults);
32                 }
33         }
34
35         /**
36          * Add a list of forecasts to this model
37          * @param inList list of forecasts to add
38          */
39         public void setForecasts(ArrayList<SingleForecast> inList)
40         {
41                 _forecastList.clear();
42                 if (inList != null && inList.size() > 0) {
43                         _forecastList.addAll(inList);
44                 }
45         }
46
47         /** @return the number of forecasts */
48         public int getNumForecasts()
49         {
50                 return _forecastList.size();
51         }
52
53         /**
54          * @param inIndex index of forecast starting from 0
55          * @return the specified forecast
56          */
57         public SingleForecast getForecast(int inIndex)
58         {
59                 if (inIndex < 0 || inIndex >= getNumForecasts()) {
60                         return null;
61                 }
62                 return _forecastList.get(inIndex);
63         }
64
65         /**
66          * Clear the list of forecasts
67          */
68         public void clear()
69         {
70                 _forecastList.clear();
71                 _sunriseTime = _sunsetTime = null;
72                 _updateTime = null;
73         }
74
75         /**
76          * @param inCelsius true for celsius, false for fahrenheit
77          */
78         public void setTempsCelsius(boolean inCelsius)
79         {
80                 _tempsCelsius = inCelsius;
81         }
82
83         /** @return true if this forecast uses Celsius */
84         public boolean isCelsius() {
85                 return _tempsCelsius;
86         }
87
88         /**
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
92          */
93         public void setSunriseSunsetTimes(String inRiseTime, String inSetTime)
94         {
95                 _sunriseTime = _sunsetTime = null;
96                 if (inRiseTime != null && inRiseTime.length() == 19
97                         && inSetTime != null && inSetTime.length() == 19)
98                 {
99                         _sunriseTime = inRiseTime.substring(11, 16);
100                         _sunsetTime  = inSetTime.substring(11, 16);
101                 }
102         }
103
104         /** @return sunrise time as HH:MM */
105         public String getSunriseTime() {
106                 return _sunriseTime;
107         }
108         /** @return sunset time as HH:MM */
109         public String getSunsetTime() {
110                 return _sunsetTime;
111         }
112
113         /** @param inName location name */
114         public void setLocationName(String inName) {
115                 _locationName = inName;
116         }
117
118         /** @return location name */
119         public String getLocationName() {
120                 return _locationName;
121         }
122
123         /** @param inTime timestamp of forecast */
124         public void setUpdateTime(String inTime) {
125                 _updateTime = inTime;
126         }
127
128         /** @return timestamp of last update */
129         public String getUpdateTime()
130         {
131                 return _updateTime;
132         }
133 }