Class Country

All Implemented Interfaces:
Geocoding, LatLon

public class Country extends Place
Country metadata provided on this class includes:
  • ISO-3166 country code 2-char and 3-char forms, aligned with US standard FIPS 10-4 codes
  • Country aliases: nick names, variant names, abbreviations
  • Affiliated territories
  • Timezone and UTC offset for temporal calculations
  • Primary and Secondary languages
Author:
Marc C. Ubaldino, MITRE, ubaldino at mitre dot org
  • Field Details

    • CC_ISO2

      public String CC_ISO2
      ISO 2-character country code
    • CC_ISO3

      public String CC_ISO3
      ISO 3-character country code
    • CC_FIPS

      public String CC_FIPS
      FIPS 10-4 2-character country code
    • isTerritory

      public boolean isTerritory
  • Constructor Details

    • Country

      public Country(String iso2, String nm)
      A country abstraction that uses ISO 2-alpha as an ID, and any name given as the Place.name
      Parameters:
      iso2 - ISO 2-alpha code for this country
      nm - Country name
  • Method Details

    • getNamenorm

      public String getNamenorm()
      Return name normalized, e.g., lowercase, w/out diacritics. 's, etc.
      Overrides:
      getNamenorm in class GeoBase
    • addAlias

      public void addAlias(String nm)
      Country is also known as some list of aliases
      Parameters:
      nm - Country name/alias
    • getAliases

      public Set<String> getAliases()
      Returns:
      set of aliases
    • addTimezone

      public void addTimezone(String label, double utcOffset)
      Add a timezone and its offset. TZ labels vary, so variant labels are tracked as well. uppercase, lowercase
      Parameters:
      label - TZ label
      utcOffset - floating point UTC offset in decimal hours. e.g., 7.5, -3.0 = (GMT-0300), etc.
    • addTimezone

      public void addTimezone(Country.TZ tz)
      Refactor -- use JodaTime and the TZDB more formally. For now, tzdb tracks the timezone metadata.
      Parameters:
      tz - - Country.TZ object
    • containsTimezone

      public boolean containsTimezone(String tz)
      Parameters:
      tz - any reasonable TZ label. Case-insensitive.
      Returns:
      true if Country has this TZ
    • containsUTCOffset

      public boolean containsUTCOffset(double offset)
      Test if this Country contains the UTC offset. Make sure you never pass a default of 0 (GMT+0) in, unless you really mean GMT0. No validation on your offset parameter is done.
      Parameters:
      offset - UTC offset in hours. Valid values are -12.0 to 12.0
      Returns:
      true if this Country contains the UTC offset.
    • containsDSTOffset

      public boolean containsDSTOffset(double offset)
    • addRegion

      public void addRegion(String regionid)
      Country is also known as some list of aliases
      Parameters:
      regionid - Region identifier or name.
    • getRegions

      public Set<String> getRegions()
      Returns:
      set of regions in which this country belongs.
    • setUniqueName

      public void setUniqueName(boolean b)
    • hasUniqueName

      public boolean hasUniqueName()
    • toString

      public String toString()
      Description copied from class: GeoBase
      Generic label -- anything more sophisticated needs attention E.g. to use Key + Name or just Key for a label would be very specific
      Overrides:
      toString in class Place
      Returns:
      string repr of the location
    • addLanguage

      public void addLanguage(String langid)
      When adding languages, please add the primary language FIRST. Languages may be langID or langID+locale. TODO: add separate attributes for locales.
      Parameters:
      langid - language
    • isSpoken

      public boolean isSpoken(String langid)
      Parameters:
      langid - language ID
      Returns:
      if language (identified by ID l) is spoken
    • getPrimaryLanguage

      public String getPrimaryLanguage()
      Certain island nations, areas, and territories that have ISO country codes may not have a language.
      Returns:
      first language in languages list (per addLanguage()); null if no languages present.
    • isPrimaryLanguage

      public boolean isPrimaryLanguage(String langid)
      Parameters:
      langid - lang ID string
      Returns:
      true if language given matches primary language
    • getLanguages

      public Collection<String> getLanguages()
      Returns:
      collection of language IDs -- some may be unknown langIDs.
    • getAllTimezones

      public Map<String,Double> getAllTimezones()
      A full list/map of all timezone labels mapped to UTC offsets present in this country. Reference: geonames.org timezone table has timezones.txt; See our GeonamesUtility for how data is populated here on Country object.
      Returns:
      map of TZ labels to UTC offsets.
    • getTZDatabase

      public Map<String,Country.TZ> getTZDatabase()
      Return the full list of TZ.
      Returns:
      full list of TZ as hashmap
    • hasTerritories

      public boolean hasTerritories()
    • addTerritory

      public void addTerritory(Country terr)
    • ownsTerritory

      public boolean ownsTerritory(String n)
      Territory ownership is defined only by the data fed to this API; We do not make any political statements here. You can change the underlying flat file data country-names-xxxx.csv anyway you want.
      Parameters:
      n - name of country or territory
      Returns:
      true if this country owns the named territory.
    • getTerritories

      public Collection<Country> getTerritories()
      List the territories for this country. Returns an empty list if no territories associated.
      Returns:
      list of Territories, that are Country objects flagged with isTerritory = true