Package to support subdivision (provinces/states/region) of countries defined in ISO 3166-2.
It can be used in conjuction with i18n-regions-countries package for defining all the countries. i18n-regions-subdivisions applies this to Region objects.
This is forked from https://github.com/tobias-/i18n-subdivisions which doesn’t seem to be maintained. I changed the coordinates and package and I am maintaining it myself now.
The author is well aware that there are bound to be problems in the data set. If nothing else, the data changes over time, so please submit issues when something is wrong (preferably with a verifiably link to the correct data).
While the information on what kind of subdivision it is (region, island, state, province, city etc), they are too many different kinds for them to be readily usable and thus they are not available.
List all the subdivision codes available for a specific country.
@Test
public void belgium() {
for (CountrySubdivisionCode code : SubdivisionFactory.getSubdivisions("BE")) {
System.out.format("[%s] %s\n", code, code.getName());
}
}This is wrapped also in i18n-regions, which would make every enum defined in this project available as a more generic 'Region' object, and also be accessible via the RegionService.
@Test
public void utrecht() {
CountrySubdivisionCode u = SubdivisionNL.valueOf("UT");
assertThat(u.getCountryCode()).isEqualTo("NL");
assertThat(u.getName()).isEqualTo("Utrecht");
}Another example
@Test
public void greatBritain() {
for (CountrySubdivisionCode code : SubdivisionFactory.getSubdivisions("GB")) {
System.out.format("[%s] %s\n", code, code.getName());
}
}All code is generated by the groovy script generateSubdivisions.groovy from the html files in src/build/resources.
A new set of html files is downloaded by issuing
mvn clean install -PdownloadThey are stored in src/build/resources and committed to versioning. These files are converted to java enums then. These appear as generated sources and are not committed.
The resulting list is however converted to .txt in a test-case and compared to a copy in src/test/resources. This way it is easily detected whether there were changes.
-
Verify with another source of the codes
-
If anyone wants them, include subdivision types in the enum
| version | changes/remarks | date |
|---|---|---|
0.6 |
also dropped region provider stuff again. This will be done in i18n-regions-subdivisions This is now just a clean set of dependency-less enums. Pckage was changd to |
oktober 2025 |
0.5 |
dropped direct nvi18n dependency, renamed interface to 'CountrySubdivision'. Being a 'RegionProvider' |
september 2025 |
0.4 |
adopted to org.meeuw |