com.oopitis.weather.fio
Class FioData<T>

java.lang.Object
  extended by com.oopitis.weather.URLDataSource<T>
      extended by com.oopitis.weather.fio.FioData<T>
Type Parameters:
T - the type of the parsed JSON data from forecast.io

public abstract class FioData<T>
extends URLDataSource<T>

Helper class for retrieving data from forecast.io. This class is kept abstract to allow the use of a different JSON parser.


Nested Class Summary
static class FioData.BlockType
          The data block types.
static interface FioData.DataBlock
          This is roughly a Data Block object described by forecast.io.
static interface FioData.DataPoint
          Data access interface that accepts a forecast.io property name or a WeatherProperty object.
static interface FioData.Response
          The full forecast.io response.
 
Nested classes/interfaces inherited from class com.oopitis.weather.URLDataSource
URLDataSource.FetchException
 
Field Summary
protected  java.lang.String baseUrl
          The base URL, which is "https://api.forecast.io/forecast/<licenseKey>/".
 
Fields inherited from class com.oopitis.weather.URLDataSource
licenseKey
 
Constructor Summary
protected FioData(java.lang.String apiKey, java.net.Proxy proxy)
          Constructs a data source with an API key.
 
Method Summary
 WeatherPropertySet getApplicableProperties(Feature f)
          Returns the set of applicable properties for a feature.
protected  java.lang.String getFioPropertyName(WeatherProperty p)
          Gets the corresponding forecast.io property name for a weather property.
abstract  FioData.Response getResponse(GeoLocation location, java.util.Date beginTime, java.util.Set<Feature> features)
          Returns the parsed, organized data ready for report creation.
protected  java.lang.String getUrl(GeoLocation.Coordinates c, java.util.Date beginTime, java.util.Set<Feature> features)
          Constructs a URL based on a location, time and set of features.
protected abstract  T parse(java.io.BufferedReader reader)
          Parses the data from a reader and returns the parsed data.
 
Methods inherited from class com.oopitis.weather.URLDataSource
fetch, setProxy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

baseUrl

protected final java.lang.String baseUrl
The base URL, which is "https://api.forecast.io/forecast/<licenseKey>/".

Constructor Detail

FioData

protected FioData(java.lang.String apiKey,
                  java.net.Proxy proxy)
Constructs a data source with an API key.

Parameters:
apiKey - the required API key
proxy - the proxy; null if a direct connection should be used
Throws:
java.lang.NullPointerException - if the given API key is null
Method Detail

parse

protected abstract T parse(java.io.BufferedReader reader)
Description copied from class: URLDataSource
Parses the data from a reader and returns the parsed data.

Specified by:
parse in class URLDataSource<T>
Parameters:
reader - the reader that supplies the raw data
Returns:
the parsed data
See Also:
URLDataSource.fetch(String)

getUrl

protected java.lang.String getUrl(GeoLocation.Coordinates c,
                                  java.util.Date beginTime,
                                  java.util.Set<Feature> features)
Constructs a URL based on a location, time and set of features. The value of parameter units is always si.

Parameters:
c - the coordinates of the location
beginTime - the begin time; null if the begin time is the current time. Note that if the begin time is null, no time is included in the query.
features - the set of features; null if all features should be included
Returns:
the URL

getFioPropertyName

protected java.lang.String getFioPropertyName(WeatherProperty p)
Gets the corresponding forecast.io property name for a weather property.

Parameters:
p - the weather property
Returns:
the corresponding forecast.io property name; null if no corresponding property is found

getApplicableProperties

public WeatherPropertySet getApplicableProperties(Feature f)
Returns the set of applicable properties for a feature.

Parameters:
f - the feature
Returns:
the set of applicable properties

getResponse

public abstract FioData.Response getResponse(GeoLocation location,
                                             java.util.Date beginTime,
                                             java.util.Set<Feature> features)
Returns the parsed, organized data ready for report creation.

Parameters:
location - the location
beginTime - the begin time;null if the time portion of the request URL is not needed
features - the set of features
Returns:
the data
See Also:
getUrl(com.oopitis.weather.GeoLocation.Coordinates, java.util.Date, java.util.Set)