com.oopitis.weather
Class WeatherReport

java.lang.Object
  extended by com.oopitis.weather.WeatherReport
All Implemented Interfaces:
WeatherPropertyMap

public class WeatherReport
extends java.lang.Object
implements WeatherPropertyMap

A group of weather data associated with a time and a location. This class is fundamentally a wrapper of the data access interface WeatherPropertyMap. Every WeatherReport object belongs to a feature that outlines the data in it. A time and a location are always associated with a weather report. The interpretation of the time and location depends on the feature. For example, the time in a report from WeatherService.CONDITIONS_HOUR indicates the hour of a day while the time in a WeatherService.ALERT report generally means the expiration date.

Weather reports are created by weather services as the result of queries. While this class does not provide any iteration methods, it is possible to discover all the data a weather report contains through the Feature object. Here is an example:

 Map<WeatherProperty, Object> data = 
   report.get(report.getFeature().getProperties(service));
 
 for (Iterator<WeatherProperty> it = data.keySet().iterator();
     it.hasNext();) {
   WeatherProperty p = it.next();
   Object rawData = data.get(p);
   String display = p.format(rawData);
 }
 
Note that the example above examines the data a report may have, not the data it must have. Unless documented otherwise by a provider, the availability of data is not guaranteed even though the property that represents it is listed by the feature.

Implementation note: The type of the location object in this class is not made generic because the location object in general is the same as the one used in the query, although this is not required. A weather service should clearly document the conditions if users are expected to cast the location object to a subtype. For example, different subclasses of GeoLocation may be used in reports from different features.

See Also:
Feature.getProperties(WeatherService), WeatherProperty.format(Object)

Constructor Summary
protected WeatherReport(Feature feature, java.util.Date time, GeoLocation location)
          Creates a weather report without data.
  WeatherReport(Feature feature, java.util.Date time, GeoLocation location, WeatherPropertyMap map)
          Creates a weather report.
 
Method Summary
<T> T
get(WeatherProperty<T> property)
          Gets the data represented by a weather property.
 java.util.Map<WeatherProperty,java.lang.Object> get(WeatherPropertySet set)
          Gets the data for a set of weather properties.
 Feature getFeature()
          Returns the feature to which this report belongs
 GeoLocation getLocation()
          Returns the location associated with this report.
<T> T
getStandardDeviation(WeatherProperty<T> property)
          Gets the variability of the data from which a property value is calculated.
 java.util.Date getTime()
          Returns the time associated with this report.
 java.lang.String toString()
          Returns a string representation of this report.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WeatherReport

public WeatherReport(Feature feature,
                     java.util.Date time,
                     GeoLocation location,
                     WeatherPropertyMap map)
Creates a weather report.

Parameters:
feature - the feature to which this report belongs
time - the time associated with this report
location - the location associated with this report
map - the weather data
Throws:
java.lang.NullPointerException - if any of the arguments is null

WeatherReport

protected WeatherReport(Feature feature,
                        java.util.Date time,
                        GeoLocation location)
Creates a weather report without data. Subclasses must override the methods defined in WeatherPropertyMap to return data. By default all data access methods return null.

Parameters:
feature - the feature to which this report belongs
time - the time associated with this report
location - the location associated with this report
Throws:
java.lang.NullPointerException - if any of the arguments is null
See Also:
WeatherPropertyMap
Method Detail

getFeature

public final Feature getFeature()
Returns the feature to which this report belongs

Returns:
the feature to which this report belongs

getTime

public final java.util.Date getTime()
Returns the time associated with this report. Depending on the feature, the time may be the beginning of a period (such as the beginning of a day) or the end of a period (such as the date and time when a weather alert expires).

Returns:
the time associated with this report

getLocation

public final GeoLocation getLocation()
Returns the location associated with this report.

Returns:
the location associated with this report

get

public <T> T get(WeatherProperty<T> property)
Description copied from interface: WeatherPropertyMap
Gets the data represented by a weather property.

Specified by:
get in interface WeatherPropertyMap
Type Parameters:
T - the type of the data
Parameters:
property - the property for which the data is to be returned
Returns:
the data represented by the weather property; null if no data is available or if the given property is not supported

getStandardDeviation

public <T> T getStandardDeviation(WeatherProperty<T> property)
Description copied from interface: WeatherPropertyMap
Gets the variability of the data from which a property value is calculated. If the value returned by get(WeatherProperty) is the average of all data collected, then the value returned by this method shows how much variation or dispersion exists from the average. Smaller variation implies higher confidence statistically.

Implementation note: While this method in general is only applicable to numeric property values, the standard deviation does not have to be an instance of java.lang.Number. The return object however must have the same type as that of the property value. When the comparison between the standard deviation (returned by this method) and the mean (returned by get(WeatherProperty)) is not obvious, a helper method may be provided to illustrate the confidence level in other ways such as the coefficient of variation in percentages.

Specified by:
getStandardDeviation in interface WeatherPropertyMap
Type Parameters:
T - the data type of the property value
Parameters:
property - the property for which the data variability is to be returned
Returns:
the variability of the data from which the property value is calculated; null if such information is unavailable or the given property is not supported
See Also:
WeatherPropertyMap.get(WeatherProperty)

get

public java.util.Map<WeatherProperty,java.lang.Object> get(WeatherPropertySet set)
Gets the data for a set of weather properties. Only the non-null values are returned; in other words, the returned map never contains null values. The keys of the returned map are in the same order as that of the property set, but the map may not contain all properties from the set.

Parameters:
set - the weather property set
Returns:
the data for a set of weather properties; an empty map if the given set is null

toString

public java.lang.String toString()
Returns a string representation of this report. The format is "time (feature) location".

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this report