/** * Validate the given code. * * @param stringCode * the string code * @return true, if successful */ public static boolean validate(final String stringCode) { return LocaleCode.getByCode(stringCode) != null; }
/** * Get a list of {@code LocaleCode} instances whose country matches the given one. * * <p> * This method is an alias of {@link #getByCountry(String, boolean) * getByCountry}{@code (country, false)}. * </p> * * @param country * Country code. ISO 3166-1 alpha-2 or alpha-3. * * @return * List of {@code LocaleCode} instances. If there is no {@code LocaleCode} * instance whose country matches the given one, the size of the returned * list is zero. * * @since 1.13 */ public static List<LocaleCode> getByCountryIgnoreCase(String country) { return getByCountry(country, false); }
/** * Get a list of {@code LocaleCode} instances whose language matches the given one. * * <p> * This method is an alias of {@link #getByLanguage(String, boolean) * getByLanguage}{@code (language, false)}. * </p> * * @param language * Language code. ISO 639 alpha-2 or alpha-3. * * @return * List of {@code LocaleCode} instances. If there is no {@code LocaleCode} * instance whose language matches the given one, the size of the returned * list is zero. * * @since 1.13 */ public static List<LocaleCode> getByLanguageIgnoreCase(String language) { return getByLanguage(language, false); }
private static LocaleCode getByCombinedCode(String code, boolean caseSensitive, int splitPosition) { // Get the character that separates the language code from the country code. char separator = code.charAt(splitPosition); if (separator == '_') { if (caseSensitive && splitPosition == 2) { // The given code can be handled as enum name. return getByEnumName(code); } } else if (separator != '-') { // Bad format. return null; } // Extract the language part and the country part from the given code. String language = code.substring(0, splitPosition); String country = code.substring(splitPosition + 1); return getByCode(language, country, caseSensitive); }
case 9: return getByCode(code, null, caseSensitive); return getByCombinedCode(code, caseSensitive, 2); return getByCombinedCode(code, caseSensitive, 9);
/** * Get a list of {@code LocaleCode} instances whose country matches the given one. * * @param country * {@code CountryCode} instance that represents a country. * * @return * List of {@code LocaleCode} instances. If there is no {@code LocaleCode} * instance whose country matches the given one, the size of the returned * list is zero. * * @since 1.3 */ public static List<LocaleCode> getByCountry(CountryCode country) { List<LocaleCode> list = new ArrayList<LocaleCode>(); if (country == null) { return list; } for (LocaleCode code : values()) { if (code.getCountry() == country) { list.add(code); } } return list; }
/** * Get a list of {@code LocaleCode} instances whose language matches the given one. * * @param language * {@code LanguageCode} instance that represents a language. * * @return * List of {@code LocaleCode} instances. If there is no {@code LocaleCode} * instance whose language matches the given one, the size of the returned * list is zero. * * @since 1.3 */ public static List<LocaleCode> getByLanguage(LanguageCode language) { List<LocaleCode> list = new ArrayList<LocaleCode>(); if (language == null) { return list; } for (LocaleCode code : values()) { if (code.getLanguage() == language) { list.add(code); } } return list; }
@Override public Locale toLocale() { return LocaleCode.undefined.toLocale(); } },
return getByEnumName(language); return getByEnumName(language + "_" + country);
private static LocaleCode getByCombinedCode(String code, boolean caseSensitive, int splitPosition) { // Get the character that separates the language code from the country code. char separator = code.charAt(splitPosition); if (separator == '_') { if (caseSensitive && splitPosition == 2) { // The given code can be handled as enum name. return getByEnumName(code); } } else if (separator != '-') { // Bad format. return null; } // Extract the language part and the country part from the given code. String language = code.substring(0, splitPosition); String country = code.substring(splitPosition + 1); return getByCode(language, country, caseSensitive); }
case 9: return getByCode(code, null, caseSensitive); return getByCombinedCode(code, caseSensitive, 2); return getByCombinedCode(code, caseSensitive, 9);
/** * Get a list of {@code LocaleCode} instances whose country matches the given one. * * @param country * {@code CountryCode} instance that represents a country. * * @return * List of {@code LocaleCode} instances. If there is no {@code LocaleCode} * instance whose country matches the given one, the size of the returned * list is zero. * * @since 1.3 */ public static List<LocaleCode> getByCountry(CountryCode country) { List<LocaleCode> list = new ArrayList<LocaleCode>(); if (country == null) { return list; } for (LocaleCode code : values()) { if (code.getCountry() == country) { list.add(code); } } return list; }
/** * Get a list of {@code LocaleCode} instances whose language matches the given one. * * @param language * {@code LanguageCode} instance that represents a language. * * @return * List of {@code LocaleCode} instances. If there is no {@code LocaleCode} * instance whose language matches the given one, the size of the returned * list is zero. * * @since 1.3 */ public static List<LocaleCode> getByLanguage(LanguageCode language) { List<LocaleCode> list = new ArrayList<LocaleCode>(); if (language == null) { return list; } for (LocaleCode code : values()) { if (code.getLanguage() == language) { list.add(code); } } return list; }
@Override public Locale toLocale() { return LocaleCode.undefined.toLocale(); } },
return getByEnumName(language); return getByEnumName(language + "_" + country);
/** * Get a {@code LocaleCode} instance that corresponds to the given code. * * <p> * This method just calls {@link #getByCode(String, boolean) getByCode}{@code (code, false)}. * </p> * * @param code * A locale code. * * @return * A {@code LocaleCode} instance, or {@code null} if not found. * * @since 1.13 * * @see #getByCode(String, boolean) */ public static LocaleCode getByCodeIgnoreCase(String code) { return getByCode(code, false); }
/** * Get a list of {@code LocaleCode} instances whose country matches the given one. * * <p> * This method is an alias of {@link #getByCountry(String, boolean) * getByCountry}{@code (country, false)}. * </p> * * @param country * Country code. ISO 3166-1 alpha-2 or alpha-3. * * @return * List of {@code LocaleCode} instances. If there is no {@code LocaleCode} * instance whose country matches the given one, the size of the returned * list is zero. * * @since 1.13 */ public static List<LocaleCode> getByCountryIgnoreCase(String country) { return getByCountry(country, false); }
/** * Get a list of {@code LocaleCode} instances whose language matches the given one. * * <p> * This method is an alias of {@link #getByLanguage(String, boolean) * getByLanguage}{@code (language, false)}. * </p> * * @param language * Language code. ISO 639 alpha-2 or alpha-3. * * @return * List of {@code LocaleCode} instances. If there is no {@code LocaleCode} * instance whose language matches the given one, the size of the returned * list is zero. * * @since 1.13 */ public static List<LocaleCode> getByLanguageIgnoreCase(String language) { return getByLanguage(language, false); }
/** * Get a {@code LocaleCode} instance that corresponds to the given code. * * <p> * This method just calls {@link #getByCode(String, boolean) getByCode}{@code (code, false)}. * </p> * * @param code * A locale code. * * @return * A {@code LocaleCode} instance, or {@code null} if not found. * * @since 1.13 * * @see #getByCode(String, boolean) */ public static LocaleCode getByCodeIgnoreCase(String code) { return getByCode(code, false); }
/** * Get a list of {@code LocaleCode} instances whose country matches the given one. * * <p> * This method is an alias of {@link #getByCountry(String, boolean) * getByCountry}{@code (country, true)}. * Note that the behavior has changed since the version 1.13. In the older versions, * this method was an alias of {@code getByCountry(country, false)}. * </p> * * @param country * Country code. ISO 3166-1 alpha-2 or alpha-3. * * @return * List of {@code LocaleCode} instances. If there is no {@code LocaleCode} * instance whose country matches the given one, the size of the returned * list is zero. * * @since 1.3 */ public static List<LocaleCode> getByCountry(String country) { return getByCountry(country, true); }