Class GeoRegion
- java.lang.Object
-
- org.sellcom.geotemporal.geography.GeoRegion
-
public class GeoRegion extends Object
Representation of a specific geographical or political region.Structure of a GeoRegion
Every region is defined by a country code and up to five codes of administrative units at different subdivision levels. The overall region code is composed of the individual codes separated by a comma.Regions are strictly hierarchical, however the administrative units at some subdivision levels may be skipped. This situation can be found in Germany, for instance, where the subdivision level of "governmental districts" (orig. "Regierungsbezirke") is defined only in some of the "federal states" (orig. "Bundesländer").
Predefined GeoRegions
Region codes defined by this library can be found in theStandardGeoRegionsclass and its inner classes. Custom-defined region codes shall be compatible with these codes.Default GeoRegion
Similarly toLocale, this class defines a default region. The default region is set at class loading time from the"user.georegion"system property. If the property is not defined or if its value is empty, a qualified guess of the default region is made from the default locale. If the qualified guess fails, aGeoRegionExceptionis thrown. The default region can be changed at any time using thesetDefault(GeoRegion)method.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description GeoRegion(String countryCode)Creates a region for the given country code.GeoRegion(String countryCode, String level1SubdivisionCode)Creates a region for the given country code and the codes at the 1st subdivision level.GeoRegion(String countryCode, String level1SubdivisionCode, String level2SubdivisionCode)Creates a region for the given country code and the codes at the 1st and 2nd subdivision levels.GeoRegion(String countryCode, String level1SubdivisionCode, String level2SubdivisionCode, String level3SubdivisionCode)Creates a region for the given country code and the codes at the 1st to 3rd subdivision levels.GeoRegion(String countryCode, String level1SubdivisionCode, String level2SubdivisionCode, String level3SubdivisionCode, String level4SubdivisionCode)Creates a region for the given country code and the codes at the 1st to 4th subdivision levels.GeoRegion(String countryCode, String level1SubdivisionCode, String level2SubdivisionCode, String level3SubdivisionCode, String level4SubdivisionCode, String level5SubdivisionCode)Creates a region for the given country code and the codes at the 1st to 5th subdivision levels.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GeoRegionatLevel(int level)Returns this region limited to the given administrative level.booleanequals(Object other)StringgetCode()Return the overall code of this region.StringgetCountryCode()Return the country code of this region.static GeoRegiongetDefault()Returns the default region.GeoRegiongetParent()Returns the immediate parent of this region.inthashCode()static GeoRegionparse(String code)Returns a region corresponding to the given code.static voidsetDefault(GeoRegion region)Sets the default region.StringtoString()
-
-
-
Field Detail
-
ROOT
public static final GeoRegion ROOT
The root region.- Since:
- 1.0
-
-
Constructor Detail
-
GeoRegion
public GeoRegion(String countryCode)
Creates a region for the given country code.- Throws:
IllegalArgumentException- ifcountryCodeisnull- Since:
- 1.0
-
GeoRegion
public GeoRegion(String countryCode, String level1SubdivisionCode)
Creates a region for the given country code and the codes at the 1st subdivision level.- Throws:
IllegalArgumentException- ifcountryCodeisnullIllegalArgumentException- iflevel1SubdivisionCodeisnull- Since:
- 1.0
-
GeoRegion
public GeoRegion(String countryCode, String level1SubdivisionCode, String level2SubdivisionCode)
Creates a region for the given country code and the codes at the 1st and 2nd subdivision levels.- Throws:
IllegalArgumentException- ifcountryCodeisnullIllegalArgumentException- iflevel1SubdivisionCodeisnullIllegalArgumentException- iflevel2SubdivisionCodeisnull- Since:
- 1.0
-
GeoRegion
public GeoRegion(String countryCode, String level1SubdivisionCode, String level2SubdivisionCode, String level3SubdivisionCode)
Creates a region for the given country code and the codes at the 1st to 3rd subdivision levels.- Throws:
IllegalArgumentException- ifcountryCodeisnullIllegalArgumentException- iflevel1SubdivisionCodeisnullIllegalArgumentException- iflevel2SubdivisionCodeisnullIllegalArgumentException- iflevel3SubdivisionCodeisnull- Since:
- 1.0
-
GeoRegion
public GeoRegion(String countryCode, String level1SubdivisionCode, String level2SubdivisionCode, String level3SubdivisionCode, String level4SubdivisionCode)
Creates a region for the given country code and the codes at the 1st to 4th subdivision levels.- Throws:
IllegalArgumentException- ifcountryCodeisnullIllegalArgumentException- iflevel1SubdivisionCodeisnullIllegalArgumentException- iflevel2SubdivisionCodeisnullIllegalArgumentException- iflevel3SubdivisionCodeisnullIllegalArgumentException- iflevel4SubdivisionCodeisnull- Since:
- 1.0
-
GeoRegion
public GeoRegion(String countryCode, String level1SubdivisionCode, String level2SubdivisionCode, String level3SubdivisionCode, String level4SubdivisionCode, String level5SubdivisionCode)
Creates a region for the given country code and the codes at the 1st to 5th subdivision levels.- Throws:
IllegalArgumentException- ifcountryCodeisnullIllegalArgumentException- iflevel1SubdivisionCodeisnullIllegalArgumentException- iflevel2SubdivisionCodeisnullIllegalArgumentException- iflevel3SubdivisionCodeisnullIllegalArgumentException- iflevel4SubdivisionCodeisnullIllegalArgumentException- iflevel5SubdivisionCodeisnull- Since:
- 1.0
-
-
Method Detail
-
atLevel
public GeoRegion atLevel(int level)
Returns this region limited to the given administrative level.- Throws:
IllegalArgumentException- iflevelis negativeIllegalArgumentException- iflevelis greater than 5- Since:
- 1.0
-
getCode
public String getCode()
Return the overall code of this region.- Since:
- 1.0
-
getCountryCode
public String getCountryCode()
Return the country code of this region.- Since:
- 1.0
-
getDefault
public static GeoRegion getDefault()
Returns the default region.- Since:
- 1.0
-
getParent
public GeoRegion getParent()
Returns the immediate parent of this region.- Since:
- 1.0
-
parse
public static GeoRegion parse(String code)
Returns a region corresponding to the given code.- Throws:
IllegalArgumentException- ifcodeisnullGeoRegionParseException- if the region code cannot be parsed- Since:
- 1.0
-
setDefault
public static void setDefault(GeoRegion region)
Sets the default region.- Since:
- 1.0
-
-