Place

public abstract class Place extends Location implements Listable, Serializable

A Place is a Location with more information. While a Location 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, and Country. 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 as NOWHERE. 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.

id

public long id

The ID to be used by a database to identify this object. It is set using Place.getDatabaseId(). See that method’s documentation for more information. Crucially it is NOT guaranteed to be unique.

latLng

public Point latLng

Latitude and longitude

population

public long population

The population of the described area. This is for display under the “people” icon when areas are listed.

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 using Place.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 to Location.Location(JSONObject). See its documentation for details on its requirements. Place.id is initialized using Place.getDatabaseId(). Precondition: The JSON must be validly formatted, with examples in org.codethechange.culturemesh.API

Parameters:
  • json – JSON object to extract initializing information from
Throws:
  • JSONException – May be thrown for invalidly formatted JSON object

Place

public Place()

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

Methods

abbreviateForListing

public static String abbreviateForListing(String toAbbreviate)

Abbreviate the provided string by truncating it enough so that, after adding Listable.ellipses, the string is Listable.MAX_CHARS characters long. If the string is already shorter than Listable.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 this Place. May return Place.NOWHERE.

Returns:Name of the City if one is available, or Place.NOWHERE otherwise.

getCountryName

public String getCountryName()

Attempt to get the name of the Country for this Place. May return Place.NOWHERE.

Returns:Name of the Country if one is available, or Place.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

public abstract String getFullName()

Subclasses are required to provide a method to generate their full, unambiguous name. For example, New York, New York, United States of America.

Returns:Full, unambiguous name of place

getLatLng

public Point getLatLng()

Get the coordinates of the location

Returns:Latitude and longitude of the location

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 of Place.getFullName() and adding Listable.ellipses such that the total length is a no longer than Listable.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 this Place. May return Place.NOWHERE.

Returns:Name of the Region if one is available, or Place.NOWHERE otherwise.

getShortName

public abstract String getShortName()

In the interest of space, we also want the abbreviated version of the location (just the city name for example)

Returns:Name of location suitable for header bar.

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, ...]