|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.oopitis.weather.WeatherService<L,Q,R>
L - the type of the location objects for queriesQ - the type of the query hintsR - the type of the weather reportspublic abstract class WeatherService<L extends GeoLocation,Q extends QueryHint,R extends WeatherReport>
A service that reports weather conditions for a location based on a query
hint. A weather service supports a list of features. Each feature is
a group of weather data that share the same semantics. Such
information is represented by a list of weather properties. In other
words, a feature is always associated with a list of weather properties.
Common features
are defined in this class such as CONDITIONS and
CONDITIONS_DAY, which represent the current weather
conditions and daily weather conditions respectively. This class also
defines common properties such as TempCelsius or
SunsetTime.
To obtain weather information, an instance of this class is required. This
class is a common interface for different data sources to provide weather
information without the users understanding the proprietary protocols.
At the same time, each provider can extend the interfaces
and classes in this package or define new features and properties to support
provider-specific operations. For example, service providers may extend
GeoLocation to allow users to describe a location in a way that is
more suitable for their database.
The simplest form of data query returns reports from basic features a service provides:
Other variances allow users to indicate properties of interest or features to include:List<? extends WeatherReport> reports = service.query(location);
// Get reports where sunset time is applicable.
List<? extends WeatherReport> reports = service.query(location,
WeatherService.SunsetTime);
// Get reports that contain precipitation related properties as well as
// reports from ALERT feature.
List<? extends WeatherReport> reports = service.query(location,
WeatherService.Precipitation, WeatherService.ALERT);
// Get hourly weather reports.
List<? extends WeatherReport> reports = service.query(location,
WeatherService.CONDITIONS_HOUR);
More sophisticated queries require the use of a QueryHint object:
Once a list of reports is obtained, users can examine the time, feature and location of each report and determine which reports are truly relevant. Utility methods are provided to further refine the result:QueryHint h = service.newQueryHint(); h.include(WeatherService.HumidityPercent); h.exclude(WeatherService.CONDITIONS_MINUTE); // Get reports that contain humidity data but not minute-by-minute reports // even though minute-by-minute reports also contain humidity data. List<? extends WeatherReport> reports = service.query(location, h);
List<Feature> features = WeatherService.listFeatures(reports);
if (features.contains(WeatherService.CONDITIONS_HOUR)) {
reports = WeatherService.subList(reports, WeatherService.CONDITIONS_HOUR);
reports1 = WeatherService.subList(reports, tonight9pm, tomorrow11am);
reports2 = WeatherService.subList(reports, tomorrow3pm, null);
}
Finally, to get data from a report and display it, a weather property is used
as a key to retrieve data and as a formatter to format data:
for (WeatherReport r: reports) {
Float t = r.get(WeatherService.TempMaxCelsius);
Date d = r.get(WeatherService.TempMaxTime);
System.out.printf("%s %s at %s\n", WeatherService.TempMaxCelsius,
WeatherService.TempMaxCelsius.format(t),
WeatherService.TempMaxTime.format(d));
}
Notice how weather properties are typed and type casting is not required.
In fact, a compilation error will occur if the data is assigned to the wrong
type. The data however can be assigned to an Object reference.
This is the case when a property set is used to retrieve data:
for (WeatherReport r: reports) {
Map<WeatherProperty, Object> windData = r.get(WeatherService.Wind);
for (Iterator<WeatherProperty> it = windData.keySet().iterator();
it.hasNext();) {
WeatherProperty p = it.next();
Object data = windData.get(p);
}
}
A service also provides basic presentation of the weather reports:
In this case, the reports cannot be assigned to an upper bounded wildcard becauseList<WeatherReport> reports = service.query(location); service.print(System.out, reports);
print can only handle the type of reports the service
supports.
While generally it is the best to consult documentation about which
information an instance of this class can provide, it is possible to discover
the features a service supports by calling getSupportedFeatures()
and the properties associated with a feature by calling
getApplicableProperties(Feature). All Feature and
WeatherProperty objects have constant names, which are
fully qualified names of the Java identifiers they are assigned to.
| Field Summary | |
|---|---|
static WeatherPropertySet |
Alert
Weather alert related properties. |
static Feature |
ALERT
A feature that provides weather alerts. |
static WeatherProperty<java.lang.String> |
AlertDescription
The description of a weather alert. |
static WeatherProperty<java.lang.String> |
AlertTitle
The title of a weather alert. |
static WeatherPropertySet |
Astronomy
Astronomy related properties. |
static WeatherProperty<java.lang.Float> |
CloudCoverPercent
Cloud cover in percentages. |
static Feature |
CONDITIONS
A feature that provides reports for weather conditions at a given time. |
static Feature |
CONDITIONS_DAY
A feature that provides day-by-day weather reports. |
static Feature |
CONDITIONS_HOUR
A feature that provides hour-by-hour weather reports. |
static Feature |
CONDITIONS_MINUTE
A feature that provides minute-by-minute weather reports. |
static WeatherProperty<java.lang.Float> |
DewPointCelsius
Dew point in degrees Celsius. |
static WeatherProperty<java.lang.Float> |
HumidityPercent
Humidity in percentages. |
static WeatherProperty<java.lang.Float> |
OzoneColumnarDensityDU
Ozone columnar density in Dobson units. |
static WeatherProperty<java.lang.Float> |
PrecipAccumCentimeter
The accumulated precipitation over a given period of time in centimeters. |
static WeatherProperty<PrecipitationForm> |
PrecipForm
The form of precipitation. |
static WeatherPropertySet |
Precipitation
Precipitation related properties. |
static WeatherProperty<java.lang.Float> |
PrecipMaxMillimeterPerHour
The maximum precipitation in a given period of time in millimeters of liquid water per hour. |
static WeatherProperty<java.util.Date> |
PrecipMaxTime
The time when the maximum precipitation occurs. |
static WeatherProperty<java.lang.Float> |
PrecipMillimeterPerHour
The precipitation in millimeters of liquid water per hour. |
static WeatherProperty<java.lang.Float> |
PrecipProbabilityPercent
The probability of precipitation. |
static WeatherProperty<java.lang.Float> |
PressureHectopascal
Atmospheric pressure in hectopascal. |
static WeatherProperty<java.util.Date> |
SunriseTime
The time of sunrise. |
static WeatherProperty<java.util.Date> |
SunsetTime
The time of sunset. |
static WeatherProperty<java.lang.Float> |
TempCelsius
The temperature at a given time in degrees Celsius. |
static WeatherPropertySet |
Temperature
Temperature related properties. |
static WeatherProperty<java.lang.Float> |
TempMaxCelsius
The maximum temperature in a given period of time in degrees Celsius. |
static WeatherProperty<java.util.Date> |
TempMaxTime
The time when the maximum temperature occurs. |
static WeatherProperty<java.lang.Float> |
TempMinCelsius
The minimum temperature in a given period of time in degrees Celsius. |
static WeatherProperty<java.util.Date> |
TempMinTime
The time when the minimum temperature occurs. |
static WeatherProperty<java.lang.Float> |
UltravioletIndex
Ultraviolet index. |
static WeatherProperty<java.lang.Float> |
VisibilityKilometer
Visibility in kilometers. |
static WeatherPropertySet |
Wind
Wind related properties. |
static WeatherProperty<java.lang.Float> |
WindDirectionDegree
The direction from which the wind originates in degrees, with true north in zero degree and moving clockwise. |
static WeatherProperty<java.lang.Float> |
WindMeterPerSecond
The wind speed in meters per second. |
| Constructor Summary | |
|---|---|
protected |
WeatherService()
Constructs a weather service. |
| Method Summary | ||
|---|---|---|
protected java.util.Set<Feature> |
getApplicableFeatures(Q hint)
Derives the set of relevant features from a query hint. |
|
abstract WeatherPropertySet |
getApplicableProperties(Feature f)
Gets the set of properties applicable to a feature. |
|
abstract java.util.Set<Feature> |
getBasicFeatures()
Returns the set of features for which the weather reports are created when the query hint does not exist or does not specify properties of interest or features to include. |
|
abstract java.util.Set<Feature> |
getSupportedFeatures()
Gets all features this service supports. |
|
static java.util.List<Feature> |
listFeatures(java.util.List<? extends WeatherReport> list)
Lists all features referenced by a list of weather reports. |
|
abstract Q |
newQueryHint()
Creates a new query hint. |
|
void |
print(java.io.PrintStream out,
java.util.List<R> reports)
Prints a list of weather reports to a print stream. |
|
java.util.List<R> |
query(L location)
Queries the data source for a location about the weather information from the basic features this service provides. |
|
abstract java.util.List<R> |
query(L location,
java.util.Date beginDate,
Q hint)
Queries the data source about the weather in a location from a specific date onward. |
|
java.util.List<R> |
query(L location,
Feature f,
Feature... ff)
Queries the data source for a location about the weather information from a list of features. |
|
java.util.List<R> |
query(L location,
Q hint)
Queries the data source about the weather in a location. |
|
java.util.List<R> |
query(L location,
Queryable q,
Feature f,
Feature... ff)
Queries the data source for a location about the weather information that includes the given queryable and list of features. |
|
java.util.List<R> |
query(L location,
Queryable q,
Queryable... others)
Queries the data source for a location about the weather information that includes a list of queryables. |
|
static
|
subList(java.util.List<T> list,
java.util.Date beginDate,
java.util.Date endDate)
Extracts the list of weather reports between two dates. |
|
static
|
subList(java.util.List<T> list,
Feature f)
Extracts the list of weather reports that belong to a feature. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final WeatherProperty<java.lang.String> AlertTitle
public static final WeatherProperty<java.lang.String> AlertDescription
public static final WeatherProperty<java.util.Date> SunriseTime
public static final WeatherProperty<java.util.Date> SunsetTime
public static final WeatherProperty<java.lang.Float> TempCelsius
public static final WeatherProperty<java.lang.Float> TempMinCelsius
public static final WeatherProperty<java.util.Date> TempMinTime
public static final WeatherProperty<java.lang.Float> TempMaxCelsius
public static final WeatherProperty<java.util.Date> TempMaxTime
public static final WeatherProperty<java.lang.Float> HumidityPercent
public static final WeatherProperty<java.lang.Float> DewPointCelsius
public static final WeatherProperty<PrecipitationForm> PrecipForm
PrecipitationFormpublic static final WeatherProperty<java.lang.Float> PrecipMillimeterPerHour
public static final WeatherProperty<java.lang.Float> PrecipProbabilityPercent
public static final WeatherProperty<java.lang.Float> PrecipMaxMillimeterPerHour
public static final WeatherProperty<java.util.Date> PrecipMaxTime
public static final WeatherProperty<java.lang.Float> PrecipAccumCentimeter
public static final WeatherProperty<java.lang.Float> WindMeterPerSecond
public static final WeatherProperty<java.lang.Float> WindDirectionDegree
public static final WeatherProperty<java.lang.Float> CloudCoverPercent
public static final WeatherProperty<java.lang.Float> VisibilityKilometer
public static final WeatherProperty<java.lang.Float> PressureHectopascal
public static final WeatherProperty<java.lang.Float> UltravioletIndex
public static final WeatherProperty<java.lang.Float> OzoneColumnarDensityDU
public static final WeatherPropertySet Alert
public static final WeatherPropertySet Astronomy
public static final WeatherPropertySet Precipitation
public static final WeatherPropertySet Temperature
public static final WeatherPropertySet Wind
public static final Feature CONDITIONS
public static final Feature CONDITIONS_MINUTE
public static final Feature CONDITIONS_HOUR
public static final Feature CONDITIONS_DAY
public static final Feature ALERT
| Constructor Detail |
|---|
protected WeatherService()
| Method Detail |
|---|
public static <T extends WeatherReport> java.util.List<T> subList(java.util.List<T> list,
Feature f)
T - the type of the weather reportslist - the list of the weather reportsf - the feature
java.lang.NullPointerException - if the given list of reports is null
public static <T extends WeatherReport> java.util.List<T> subList(java.util.List<T> list,
java.util.Date beginDate,
java.util.Date endDate)
T - the type of weather reportslist - the list of weather reportsbeginDate - the begin date (inclusive); null if the
begin date is the earliest time of the reportsendDate - the end date (inclusive); null if the
end date is the latest time of the reports
java.lang.NullPointerException - if the given list is nullpublic static java.util.List<Feature> listFeatures(java.util.List<? extends WeatherReport> list)
list - the list of weather reports
java.lang.NullPointerException - if the given list is nullpublic java.util.List<R> query(L location)
location - the location
java.lang.NullPointerException - if the given location is null
public java.util.List<R> query(L location,
Queryable q,
Queryable... others)
location - the locationq - the first queryableothers - other queryables
java.lang.NullPointerException - if the given location is null
java.lang.IllegalArgumentException - if any given queryable is null
public java.util.List<R> query(L location,
Queryable q,
Feature f,
Feature... ff)
location - the locationq - a queryable, which is usually a weather property or a weather
property setf - the first featureff - other features
java.lang.NullPointerException - if the given location is null
java.lang.IllegalArgumentException - if any of the given features is null
public java.util.List<R> query(L location,
Feature f,
Feature... ff)
location - the locationf - the first featureff - the other features
java.lang.NullPointerException - if the given location is null
java.lang.IllegalArgumentException - if any given feature is null
public java.util.List<R> query(L location,
Q hint)
this.query(location, null, hint).
location - the locationhint - the query hint; null if the data from the basic
features should be returned
java.lang.NullPointerException - if the given location is null
public void print(java.io.PrintStream out,
java.util.List<R> reports)
out - the print streamreports - the list of weather reports
java.lang.NullPointerException - if the given print stream or list of
weather reports is nullprotected java.util.Set<Feature> getApplicableFeatures(Q hint)
QueryHint. When no features can be
inferred, the set of features from getBasicFeatures is
returned, except the features that are explicitly excluded.
hint - the query hint; null if unavailable
QueryHint,
getBasicFeatures()
public abstract java.util.List<R> query(L location,
java.util.Date beginDate,
Q hint)
location - the locationbeginDate - the first date of the reporting period;
null if the report should start from the
current date. This argument is mostly used to retrieve
historical data. Since weather forecast cannot extend
indefinitely, giving a future date far from now is
impractical.
To get forecast data for a future date, pass
null for this argument, include appropriate
features such as CONDITIONS_DAY, and use
subList(List, Date, Date) to
filter the reports. A service provider may ignore this
argument if it cannot provide historical data.hint - the query hint; null if the data from the basic
features should be returned
java.lang.NullPointerException - if the given location is nullpublic abstract Q newQueryHint()
public abstract java.util.Set<Feature> getSupportedFeatures()
public abstract java.util.Set<Feature> getBasicFeatures()
public abstract WeatherPropertySet getApplicableProperties(Feature f)
f - the feature
UnsupportedFeatureException - if the given feature is not
supportedFeature.getProperties(WeatherService)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||