Place¶
-
public abstract class
Place
extends Location implements Listable, Serializable¶ A
Place
is aLocation
with more information. While aLocation
stores only city, region, and country IDs,Place
also stores the areas position (latitude and longitude), population, and feature code.Place
is 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
NOWHERE
constant 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.id
is 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.id
is initialized usingPlace.getDatabaseId()
. Precondition: The JSON must be validly formatted, with examples inorg.codethechange.culturemesh.API
Parameters: - 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_CHARS
characters 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
City
for thisPlace
. May returnPlace.NOWHERE
.Returns: Name of the City
if one is available, orPlace.NOWHERE
otherwise.
getCountryName¶
-
public String
getCountryName
()¶ Attempt to get the name of the
Country
for thisPlace
. May returnPlace.NOWHERE
.Returns: Name of the Country
if one is available, orPlace.NOWHERE
otherwise.
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.ellipses
such that the total length is a no longer thanListable.MAX_CHARS
Returns: 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
Region
for thisPlace
. May returnPlace.NOWHERE
.Returns: Name of the Region
if one is available, orPlace.NOWHERE
otherwise.