X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2Fweather%2FWeatherResults.java;fp=tim%2Fprune%2Ffunction%2Fweather%2FWeatherResults.java;h=83c5ca0dfeb0828cfe9f0666d3e6768bca780cbe;hb=326f489e36aa7f235bc19409a57bf4955cd50f24;hp=0000000000000000000000000000000000000000;hpb=8c8868ae29b3252f02e094c02307384cf61ba667;p=GpsPrune.git diff --git a/tim/prune/function/weather/WeatherResults.java b/tim/prune/function/weather/WeatherResults.java new file mode 100644 index 0000000..83c5ca0 --- /dev/null +++ b/tim/prune/function/weather/WeatherResults.java @@ -0,0 +1,133 @@ +package tim.prune.function.weather; + +import java.util.ArrayList; + + +/** + * Model for results of weather forecast from openweathermap.org + */ +public class WeatherResults +{ + /** List of forecasts */ + private ArrayList _forecastList = new ArrayList(); + /** Flag whether the units are metric (Celsius) or not (Fahrenheit) */ + private boolean _tempsCelsius = true; + /** Location name */ + private String _locationName = null; + /** Last update timestamp */ + private String _updateTime = null; + /** Sunrise and sunset times as HH:MM */ + private String _sunriseTime = null, _sunsetTime = null; + + + /** + * Add a single forecast to this model (for the current weather) + * @param inResults current results + */ + public void setForecast(SingleForecast inResults) + { + _forecastList.clear(); + if (inResults != null) { + _forecastList.add(inResults); + } + } + + /** + * Add a list of forecasts to this model + * @param inList list of forecasts to add + */ + public void setForecasts(ArrayList inList) + { + _forecastList.clear(); + if (inList != null && inList.size() > 0) { + _forecastList.addAll(inList); + } + } + + /** @return the number of forecasts */ + public int getNumForecasts() + { + return _forecastList.size(); + } + + /** + * @param inIndex index of forecast starting from 0 + * @return the specified forecast + */ + public SingleForecast getForecast(int inIndex) + { + if (inIndex < 0 || inIndex >= getNumForecasts()) { + return null; + } + return _forecastList.get(inIndex); + } + + /** + * Clear the list of forecasts + */ + public void clear() + { + _forecastList.clear(); + _sunriseTime = _sunsetTime = null; + _updateTime = null; + } + + /** + * @param inCelsius true for celsius, false for fahrenheit + */ + public void setTempsCelsius(boolean inCelsius) + { + _tempsCelsius = inCelsius; + } + + /** @return true if this forecast uses Celsius */ + public boolean isCelsius() { + return _tempsCelsius; + } + + /** + * Set the sunrise and sunset times (only from current weather, not from forecast) + * @param inRiseTime sunrise time as YYYY-MM-DDThh:mm:ss + * @param inSetTime sunset time as YYYY-MM-DDThh:mm:ss + */ + public void setSunriseSunsetTimes(String inRiseTime, String inSetTime) + { + _sunriseTime = _sunsetTime = null; + if (inRiseTime != null && inRiseTime.length() == 19 + && inSetTime != null && inSetTime.length() == 19) + { + _sunriseTime = inRiseTime.substring(11, 16); + _sunsetTime = inSetTime.substring(11, 16); + } + } + + /** @return sunrise time as HH:MM */ + public String getSunriseTime() { + return _sunriseTime; + } + /** @return sunset time as HH:MM */ + public String getSunsetTime() { + return _sunsetTime; + } + + /** @param inName location name */ + public void setLocationName(String inName) { + _locationName = inName; + } + + /** @return location name */ + public String getLocationName() { + return _locationName; + } + + /** @param inTime timestamp of forecast */ + public void setUpdateTime(String inTime) { + _updateTime = inTime; + } + + /** @return timestamp of last update */ + public String getUpdateTime() + { + return _updateTime; + } +}