com.oopitis.weather
Class GeoLocation

java.lang.Object
  extended by com.oopitis.weather.GeoLocation
Direct Known Subclasses:
OwmLocation

public class GeoLocation
extends java.lang.Object

An object of this class represents either a specific geographical location or locations that share the same attributes. Objects of this class or its subclasses appear in the queries in WeatherService as well as in WeatherReport objects. How these objects are created and interpreted may be specific to the service that provides them. Without extending, this class can be instantiated with a latitude and a longitude in signed degrees.

All get methods in this class can return null if the requested information is not applicable or available, but at least one of them should return a non-null object.


Nested Class Summary
static class GeoLocation.Coordinates
          Geographical coordinates for a location.
 
Constructor Summary
  GeoLocation(float latitude, float longitude)
          Constructs a GeoLocation with geographical coordinates.
protected GeoLocation(java.lang.String id, java.lang.String city, java.lang.String region, java.lang.String zipCode, java.util.Locale locale, GeoLocation.Coordinates coordinates)
          Constructs a GeoLocation with one or more associated attributes.
 
Method Summary
static java.lang.String formatCoordinate(float f)
          Formats a coordinate.
 java.lang.String getCity()
          Returns the name of the city that contains this location.
 GeoLocation.Coordinates getCoordinates()
          Returns the geographical coordinates of this location.
 java.lang.String getId()
          Returns the service-specific ID of this location.
 java.util.Locale getLocale()
          Returns the locale of this location.
 java.lang.String getRegion()
          Returns the name of the county or state that contains this location.
 java.lang.String getZipCode()
          Returns the zip code of this location.
static GeoLocation.Coordinates newCoordinates(float latitude, float longitude)
          Creates a new Coordinates object.
 java.lang.String toString()
          Returns a string representation of this location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeoLocation

protected GeoLocation(java.lang.String id,
                      java.lang.String city,
                      java.lang.String region,
                      java.lang.String zipCode,
                      java.util.Locale locale,
                      GeoLocation.Coordinates coordinates)
Constructs a GeoLocation with one or more associated attributes. All arguments are optional, but at least one of them must not be null.

Parameters:
id - the service-specific ID that identifies the location
city - the name of the city that contains this location
region - the region that contains the city; for example, a county or state
zipCode - the zip code of the location
locale - the locale of the location. When provided, most likely only the country code of the locale is in use.
coordinates - the geographical coordinates of the location
Throws:
java.lang.NullPointerException - if all arguments are null

GeoLocation

public GeoLocation(float latitude,
                   float longitude)
Constructs a GeoLocation with geographical coordinates.

Parameters:
latitude - the latitude
longitude - the longitude
Throws:
java.lang.IllegalArgumentException - if the latitude or longitude is out of range
Method Detail

newCoordinates

public static GeoLocation.Coordinates newCoordinates(float latitude,
                                                     float longitude)
Creates a new Coordinates object.

Parameters:
latitude - the latitude
longitude - the longitude
Returns:
the new Coordinates object
Throws:
java.lang.IllegalArgumentException - if the latitude or longitude is out of range

getId

public java.lang.String getId()
Returns the service-specific ID of this location.

Returns:
the service-specific ID of this location; null if unavailable

getCity

public java.lang.String getCity()
Returns the name of the city that contains this location.

Returns:
the name of the city that contains this location; null if unavailable

getRegion

public java.lang.String getRegion()
Returns the name of the county or state that contains this location.

Returns:
the name of the region that contains this location; null if unavailable

getZipCode

public java.lang.String getZipCode()
Returns the zip code of this location.

Returns:
the zip code of this location; null if unavailable

getLocale

public java.util.Locale getLocale()
Returns the locale of this location.

Returns:
the locale of this location; null if unavailable

getCoordinates

public GeoLocation.Coordinates getCoordinates()
Returns the geographical coordinates of this location.

Returns:
the geographical coordinates of this location; null if unavailable

formatCoordinate

public static java.lang.String formatCoordinate(float f)
Formats a coordinate. The formatter is DecimalFormat with pattern "###.######".

Parameters:
f - the latitude or longitude
Returns:
the formatted coordinate

toString

public java.lang.String toString()
Returns a string representation of this location. The format is "[id] city, region zipCode, countryCode (countryName) @(latitude,longitude)".

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