X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FCountry.java;h=dedaa7e00f0bcc2f1962af801efee4c87ec712b2;hp=977b1485c5d8ec73fac08ed3aa4008838a38a57d;hb=7d7ae589bf07124d8489f325e5a9a1963462bb9b;hpb=0b0db3d1f59e3473fad2d8011f75552b7de1671e diff --git a/src/org/cacert/gigi/dbObjects/Country.java b/src/org/cacert/gigi/dbObjects/Country.java index 977b1485..dedaa7e0 100644 --- a/src/org/cacert/gigi/dbObjects/Country.java +++ b/src/org/cacert/gigi/dbObjects/Country.java @@ -6,13 +6,16 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Random; +import java.util.RandomAccess; import org.cacert.gigi.GigiApiException; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.database.GigiResultSet; import org.cacert.gigi.output.template.SprintfCommand; +/** + * Represents a country containing its ISO 3166-1-Code and its English name. + */ public class Country { public enum CountryCodeType { @@ -30,17 +33,36 @@ public class Country { } } + /** + * Id of the database entry. + */ private final int id; + /** + * English name of the country. + */ private final String country; + /** + * ISO 3166-1 alpha-2 code of the country. + */ private final String countryCode2; + /** + * ISO 3166-1 alpha-3 code of the country. + */ private final String countryCode3; + /** + * A unmodifiable {@link RandomAccess}-List of all Countries. + */ private static final List countries; + /** + * An unmodifiable index of all 2- and 3-letter country codes. + */ private static final Map byString; + static { LinkedList cs = new LinkedList<>(); HashMap ccd = new HashMap<>(); @@ -72,10 +94,22 @@ public class Country { return country; } + /** + * Returns the default (ISO 3166-1 alpha-2) country code of this country. + * + * @return the country code + */ public String getCode() { return countryCode2; } + /** + * Gets the specified type of country code for this country. + * + * @param type + * the type of the code + * @return the corresponding code + */ public String getCode(CountryCodeType type) { switch (type) { case CODE_2_CHARS: @@ -87,14 +121,40 @@ public class Country { } } + /** + * Gets an unmodifiable, {@link RandomAccess}-List of all countries. + * + * @return the list. + */ public static List getCountries() { return countries; } + /** + * Checks a country code for its validity and conformance to the given type. + * + * @param countrycode + * the code to check + * @param cType + * the type it should have + * @throws GigiApiException + * if the code was wrong + */ public static void checkCountryCode(String countrycode, CountryCodeType cType) throws GigiApiException { getCountryByCode(countrycode, cType); } + /** + * Fetches the {@link Country} object for the given country code. + * + * @param countrycode + * the code to fetch the county for + * @param cType + * the type of the code + * @return the specified country + * @throws GigiApiException + * if the code was wrong. + */ public static Country getCountryByCode(String countrycode, CountryCodeType cType) throws GigiApiException { if (countrycode.length() != cType.getLen()) { throw new GigiApiException(SprintfCommand.createSimple("Country code length does not have the required length of {0} characters", Integer.toString(cType.getLen()))); @@ -106,9 +166,4 @@ public class Country { return i; } - public static Country getRandomCountry() { - List cc = Country.getCountries(); - int rnd = new Random().nextInt(cc.size()); - return cc.get(rnd); - } }