Place¶
-
public abstract class
Placeextends Location implements Listable, Serializable¶ A
Placeis aLocationwith more information. While aLocationstores only city, region, and country IDs,Placealso stores the areas position (latitude and longitude), population, and feature code.Placeis abstract, and some examples of its subclasses are:City,Region, andCountry. Created by Drew Gregory on 2/23/18. This is the superclass for cities, regions, and countries.
Fields¶
NOWHERE¶
-
protected static final String
NOWHERE¶ The
NOWHEREconstant is used internally by this hierarchy as the name of a location’s city, region, or country when that geographic identifier is not specified. For example, Washington D.C. has no state (i.e. region), so its region might be stored asNOWHERE. This should never be used by clients. Instead, creating such places should be done through provided constructors or methods.
featureCode¶
-
public String
featureCode¶ Feature code, which is a string describing the type of place represented (e.g. a capital, a religiously important area, an abandoned populated area). See http://www.geonames.org/export/codes.html for more examples.
Constructors¶
Place¶
-
public
Place(long countryId, long regionId, long cityId, Point latLng, long population, String featureCode)¶ Initialize instance fields with provided parameters. Also calls
Location.Location(long,long,long)with the provided IDs Postcondition:Place.idis initialized usingPlace.getDatabaseId()Parameters: - countryId – ID of country
- regionId – ID of region
- cityId – ID of city
- latLng – Coordinates (latitude and longitude) of location
- population – Population of location
- featureCode – Feature code of location
Place¶
-
public
Place(JSONObject json)¶ Initializes ID instance fields using the provided JSON object The following keys must be present and are used to fill the relevant instance fields:
latitude,longitude,population,feature_code. In addition, the JSON object is passed toLocation.Location(JSONObject). See its documentation for details on its requirements.Place.idis initialized usingPlace.getDatabaseId(). Precondition: The JSON must be validly formatted, with examples inorg.codethechange.culturemesh.APIParameters: - json – JSON object to extract initializing information from
Throws: - JSONException – May be thrown for invalidly formatted JSON object
Methods¶
abbreviateForListing¶
-
public static String
abbreviateForListing(String toAbbreviate)¶ Abbreviate the provided string by truncating it enough so that, after adding
Listable.ellipses, the string isListable.MAX_CHARScharacters long. If the string is already shorter thanListable.MAX_CHARS, it is returned unchanged.Parameters: - toAbbreviate – String whose abbreviated form will be returned
Returns: Abbreviated form of the string. Has a maximum length of
Listable.MAX_CHARS
getCityName¶
-
public String
getCityName()¶ Attempt to get the name of the
Cityfor thisPlace. May returnPlace.NOWHERE.Returns: Name of the Cityif one is available, orPlace.NOWHEREotherwise.
getCountryName¶
-
public String
getCountryName()¶ Attempt to get the name of the
Countryfor thisPlace. May returnPlace.NOWHERE.Returns: Name of the Countryif one is available, orPlace.NOWHEREotherwise.
getFeatureCode¶
-
public String
getFeatureCode()¶ Get the feature code describing the location. See http://www.geonames.org/export/codes.html for examples.
Returns: Location’s feature code
getFullName¶
getLatLng¶
getListableName¶
-
public String
getListableName()¶ Get a name suitable for display in listings of places, as required to implement
Listable. This name is created by abbreviating the output ofPlace.getFullName()and addingListable.ellipsessuch that the total length is a no longer thanListable.MAX_CHARSReturns: Name of Location suitable for display in UI lists. Has a maximum length of Listable.MAX_CHARS.
getNumUsers¶
-
public long
getNumUsers()¶ Get the number of users (population) to display in conjunction with the location
Returns: Population of the location
getPopulation¶
-
public long
getPopulation()¶ Get the population of the location
Returns: Location’s population
getRegionName¶
-
public String
getRegionName()¶ Attempt to get the name of the
Regionfor thisPlace. May returnPlace.NOWHERE.Returns: Name of the Regionif one is available, orPlace.NOWHEREotherwise.