Package org.opensextant.data
Class Country
- java.lang.Object
-
- org.opensextant.data.GeoBase
-
- org.opensextant.data.Place
-
- org.opensextant.data.Country
-
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Country.TZ
-
Field Summary
Fields Modifier and Type Field Description java.lang.String
CC_FIPS
FIPS 10-4 2-character country codejava.lang.String
CC_ISO2
ISO 2-character country codejava.lang.String
CC_ISO3
ISO 3-character country codeboolean
isTerritory
-
Fields inherited from class org.opensextant.data.Place
admin1, admin1Name, admin2, admin2Name, adminName, country, country_id, method, name_type
-
-
Constructor Summary
Constructors Constructor Description Country(java.lang.String iso2, java.lang.String nm)
A country abstraction that uses ISO 2-alpha as an ID, and any name given as the Place.name
-
Method Summary
Modifier and Type Method Description void
addAlias(java.lang.String nm)
Country is also known as some list of aliasesvoid
addLanguage(java.lang.String langid)
When adding languages, please add the primary language FIRST.void
addRegion(java.lang.String regionid)
Country is also known as some list of aliasesvoid
addTerritory(Country terr)
void
addTimezone(java.lang.String label, double utcOffset)
Add a timezone and its offset.void
addTimezone(Country.TZ tz)
Refactor -- use JodaTime and the TZDB more formally.boolean
containsDSTOffset(double offset)
boolean
containsTimezone(java.lang.String tz)
boolean
containsUTCOffset(double offset)
Test if this Country contains the UTC offset.java.util.Set<java.lang.String>
getAliases()
java.util.Map<java.lang.String,java.lang.Double>
getAllTimezones()
A full list/map of all timezone labels mapped to UTC offsets present in this country.java.util.Collection<java.lang.String>
getLanguages()
java.lang.String
getNamenorm()
Return name normalized, e.g., lowercase, w/out diacritics.java.lang.String
getPrimaryLanguage()
Certain island nations, areas, and territories that have ISO country codes may not have a language.java.util.Set<java.lang.String>
getRegions()
java.util.Collection<Country>
getTerritories()
List the territories for this country.java.util.Map<java.lang.String,Country.TZ>
getTZDatabase()
Return the full list of TZ.boolean
hasTerritories()
boolean
hasUniqueName()
boolean
isPrimaryLanguage(java.lang.String langid)
boolean
isSpoken(java.lang.String langid)
boolean
ownsTerritory(java.lang.String n)
Territory ownership is defined only by the data fed to this API; We do not make any political statements here.void
setUniqueName(boolean b)
java.lang.String
toString()
Generic label -- anything more sophisticated needs attention E.g.-
Methods inherited from class org.opensextant.data.Place
compareTo, copyTo, defaultHierarchicalPath, getAdmin1, getAdmin1Name, getAdmin1PostalCode, getAdmin2, getAdmin2Name, getAdminName, getConfidence, getCountry, getCountryCode, getFeatureClass, getFeatureCode, getFeatureDesignation, getHierarchicalPath, getId_bias, getInstanceId, getMethod, getName_bias, getName_type, getNDNamenorm, getPlaceID, getPlaceName, getPlacePostalCode, getPopulation, getPrecision, getSource, isAbbreviation, isAdmin1, isAdministrative, isASCIIName, isCode, isCoordinate, isCountry, isName, isNationalCapital, isPlace, isPopulated, isSame, isShortName, isSpot, isUpperAdmin, isUppercaseName, sameBoundary, setAdmin1, setAdmin1Name, setAdmin1PostalCode, setAdmin2, setAdmin2Name, setAdminName, setConfidence, setCountry, setCountryCode, setFeatureClass, setFeatureCode, setHierarchicalPath, setId_bias, setInstanceId, setMethod, setName_bias, setName_type, setPlaceID, setPlaceName, setPlacePostalCode, setPopulation, setPrecision, setSource
-
Methods inherited from class org.opensextant.data.GeoBase
getGeohash, getKey, getLatitude, getLongitude, getName, hasCoordinate, setGeohash, setKey, setLatitude, setLatLon, setLongitude, setName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.opensextant.data.Geocoding
hasCoordinate
-
Methods inherited from interface org.opensextant.data.LatLon
getLatitude, getLongitude, setLatitude, setLongitude
-
-
-
-
Method Detail
-
getNamenorm
public java.lang.String getNamenorm()
Return name normalized, e.g., lowercase, w/out diacritics. 's, etc.- Overrides:
getNamenorm
in classGeoBase
-
addAlias
public void addAlias(java.lang.String nm)
Country is also known as some list of aliases- Parameters:
nm
- Country name/alias
-
getAliases
public java.util.Set<java.lang.String> getAliases()
- Returns:
- set of aliases
-
addTimezone
public void addTimezone(java.lang.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 labelutcOffset
- 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(java.lang.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(java.lang.String regionid)
Country is also known as some list of aliases- Parameters:
regionid
- Region identifier or name.
-
getRegions
public java.util.Set<java.lang.String> getRegions()
- Returns:
- set of regions in which this country belongs.
-
setUniqueName
public void setUniqueName(boolean b)
-
hasUniqueName
public boolean hasUniqueName()
-
toString
public java.lang.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
-
addLanguage
public void addLanguage(java.lang.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(java.lang.String langid)
- Parameters:
langid
- language ID- Returns:
- if language (identified by ID l) is spoken
-
getPrimaryLanguage
public java.lang.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(java.lang.String langid)
- Parameters:
langid
- lang ID string- Returns:
- true if language given matches primary language
-
getLanguages
public java.util.Collection<java.lang.String> getLanguages()
- Returns:
- collection of language IDs -- some may be unknown langIDs.
-
getAllTimezones
public java.util.Map<java.lang.String,java.lang.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 java.util.Map<java.lang.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(java.lang.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 java.util.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
-
-