City

public class City extends Place

A City is a specific kind of Place that stores the ID and name of a city. It can also store the names and IDs of the city’s country and region, but this is not mandatory. If any geographical descriptor (e.g. city, region, or country) is not specified, its name will be stored as Place.NOWHERE, but this constant should not be used by clients. Note that the city descriptor is mandatory.

Fields

cityName

public String cityName

Name of city

countryName

public String countryName

Name of country.

regionName

public String regionName

Name of region

Constructors

City

public City(long cityId, long regionId, long countryId, String cityName, String regionName, String countryName, Point latLng, long population, String featureCode)

Initialize instance fields and instance fields of superclasses based on provided arguments For creating cities that have city, region, and country all specified.

Parameters:
  • cityId – ID of city
  • regionId – ID of city’s region
  • countryId – ID of country’s region
  • cityName – Name of city
  • regionName – Name of region city lies within
  • countryName – Name of country city lies within
  • latLng – Latitude and longitude coordinates of city
  • population – Population of the city
  • featureCode – Feature code of the city

City

public City(long cityId, long regionId, String cityName, String regionName, Point latLng, long population, String featureCode)

Initialize instance fields and instance fields of superclasses based on provided arguments. For creating cities that have no country descriptor, but do have specified regions.

Parameters:
  • cityId – ID of city
  • regionId – ID of city’s region
  • cityName – Name of city
  • regionName – Name of region city lies within
  • latLng – Latitude and longitude coordinates of city
  • population – Population of the city
  • featureCode – Feature code of the city

City

public City(long cityId, String cityName, Point latLng, long population, String featureCode)

Initialize instance fields and instance fields of superclasses based on provided arguments For creating cities that have no region nor country descriptor

Parameters:
  • cityId – ID of city
  • cityName – Name of city
  • latLng – Latitude and longitude coordinates of city
  • population – Population of the city
  • featureCode – Feature code of the city

City

public City(JSONObject json)

Initialize instance fields and those of superclass based on provided JSON This class extracts the following fields, if they are present: country_name and region_name. It requires that the key name exist, as its value will be used as the City’s name

Parameters:
  • json – JSON object describing the city to create
Throws:
  • JSONException – May be thrown in response to an invalidly formatted JSON object

City

public City()

Empty constructor for database use only. This should never be called by our code.

Methods

getFullName

public String getFullName()

Get a name for the city that lists all available geographic descriptor names. For example, Washington, D.C. would be expressed as Washington, D.C., United States, while San Francisco would be expressed as San Francisco, California, United States.

Returns:Name of city that includes all available geographic descriptors

getName

public String getName()

Get the name of the city

Returns:City name

getShortName

public String getShortName()

Now display just city name.

newOnlyMissingRegion

public static City newOnlyMissingRegion(long cityId, long countryId, String cityName, String countryName, Point latLng, long population, String featureCode)

Return City object with fields initialized with provided parameters For creating cities that are only missing the region descriptor This unusual pseudo-constructor is required to avoid ambiguity between constructors

Parameters:
  • cityId – ID of city
  • countryId – ID of country’s region
  • cityName – Name of city
  • countryName – Name of country city lies within
  • latLng – Latitude and longitude coordinates of city
  • population – Population of the city
  • featureCode – Feature code of the city
Returns:

City object that has been initialized

toString

public String toString()

Represent the object as a string suitable for debugging, but not for display to user.

Returns:String representation of the form Class[var=value, var=value, var=value, ...]