Locale.
This class tries to handle null input gracefully. An exception will not be thrown for a null input. Each method documents its behavior in
more detail.
Locale
| Modifier and Type | Class and Description |
|---|---|
| private static class | LocaleUtils.
Avoids synchronization, initializes on demand. |
| Modifier and Type | Field and Description |
|---|---|
| private static final ConcurrentMap | cCountriesByLanguage
Concurrent map of country locales by language. |
| private static final ConcurrentMap | cLanguagesByCountry
Concurrent map of language locales by country. |
| private static final char | DASH
The dash character |
| private static final char | UNDERSCORE
The underscore character |
| private static final String | UNDETERMINED
The undetermined language .</am> |
| Access | Constructor and Description |
|---|---|
| public | LocaleUtils()
Deprecated
TODO Make private in 4.0.
|
| Modifier and Type | Method and Description |
|---|---|
| public static List | Returns: the unmodifiable and sorted list of available locales.Obtains an unmodifiable and sorted list of installed locales. |
| private static List | |
| public static Set | Returns: the unmodifiable set of available locales.Obtains an unmodifiable set of installed locales. |
| public static List | Returns: an unmodifiable List of Locale objects, not null.the 2 letter language code, null returns empty. languageCode)Obtains the list of countries supported for a given language. |
| private static boolean | Returns: whether the given Locale defines a variant.The Locale to test. locale)Tests whether the given Locale defines a variant. |
| private static boolean | Returns: whether the given Locale defines a country.The Locale to test. locale)Tests whether the given Locale defines a country. |
| private static boolean | Returns: whether the given string is the length of an ISO 3166 alpha-2 country code.The string to test. str)Tests whether the given string is the length of an ISO 3166 alpha-2 country code. |
| private static boolean | Returns: whether the given string is the length of an ISO 3166 alpha-3 country code.The string to test. str)Tests whether the given string is the length of an ISO 3166 alpha-3 country code. |
| public static boolean | Returns: true if the locale is a known locale.the Locale object to check if it is available. locale)Checks if the locale specified is in the set of available locales. |
| private static boolean | Returns: true, is the given String is a ISO 3166 compliant country code.the String to check. str)Tests whether the given String is a ISO 3166 alpha-2 country code. |
| private static boolean | Returns: true, if the given String is a ISO 639 compliant language code.the String to check. str)Tests whether the given String is a ISO 639 compliant language code. |
| public static boolean | Returns: whether a Locale's language is undetermined.the locale to test. locale)Tests whether a Locale's language is undetermined. |
| private static boolean | Returns: true, is the given String is a UN M.49 numeric area code.the String to check. str)TestsNo whether the given String is a UN M.49 numeric area code. |
| public static List | Returns: an unmodifiable List of Locale objects, not null.the 2-letter country code, null returns empty. countryCode)Obtains the list of languages supported for a given country. |
| public static List | Returns: the unmodifiable list of Locale objects, 0 being locale, not null.the locale to start from. locale)Obtains the list of locales to search through when performing a locale search. |
| public static List | Returns: the unmodifiable list of Locale objects, 0 being locale, not null.the locale to start from, null returns empty list. locale, final Locale the default locale to use if no other is found. defaultLocale)Obtains the list of locales to search through when performing a locale search. |
| pack-priv static Locale | |
| private static Locale | Returns: a Locale parsed from the given String.the String to parse as a Locale. str)Tries to parse a Locale from the given String. |
| public static Locale | toLocale(final Locale
a locale or locale)null.Returns the given locale if non- |
| public static Locale |
| cCountriesByLanguage | back to summary |
|---|---|
| private static final ConcurrentMap<String, List<Locale>> cCountriesByLanguage Concurrent map of country locales by language. | |
| cLanguagesByCountry | back to summary |
|---|---|
| private static final ConcurrentMap<String, List<Locale>> cLanguagesByCountry Concurrent map of language locales by country. | |
| DASH | back to summary |
|---|---|
| private static final char DASH The dash character | |
| UNDERSCORE | back to summary |
|---|---|
| private static final char UNDERSCORE The underscore character | |
| UNDETERMINED | back to summary |
|---|---|
| private static final String UNDETERMINED The undetermined language .
If a language is empty, or not well-formed (for example "a" or "e2"),
| |
| LocaleUtils | back to summary |
|---|---|
| public LocaleUtils()
Deprecated TODO Make private in 4.0.
This constructor is public to permit tools that require a JavaBean instance to operate.
| |
| availableLocaleList | back to summary |
|---|---|
| public static List Obtains an unmodifiable and sorted list of installed locales.
This method is a wrapper around | |
| availableLocaleList | back to summary |
|---|---|
| private static List | |
| availableLocaleSet | back to summary |
|---|---|
| public static Set Obtains an unmodifiable set of installed locales.
This method is a wrapper around | |
| countriesByLanguage | back to summary |
|---|---|
| public static List Obtains the list of countries supported for a given language. This method takes a language code and searches to find the countries available for that language. Variant locales are removed. | |
| hasCountry | back to summary |
|---|---|
| private static boolean hasCountry(final Locale locale) Tests whether the given Locale defines a variant.
| |
| hasVariant | back to summary |
|---|---|
| private static boolean hasVariant(final Locale locale) Tests whether the given Locale defines a country.
| |
| isAlpha2Len | back to summary |
|---|---|
| private static boolean isAlpha2Len(final String str) Tests whether the given string is the length of an ISO 3166 alpha-2 country code. | |
| isAlpha3Len | back to summary |
|---|---|
| private static boolean isAlpha3Len(final String str) Tests whether the given string is the length of an ISO 3166 alpha-3 country code. | |
| isAvailableLocale | back to summary |
|---|---|
| public static boolean isAvailableLocale(final Locale locale) Checks if the locale specified is in the set of available locales.
| |
| isISO3166CountryCode | back to summary |
|---|---|
| private static boolean isISO3166CountryCode(final String str) Tests whether the given String is a ISO 3166 alpha-2 country code. | |
| isISO639LanguageCode | back to summary |
|---|---|
| private static boolean isISO639LanguageCode(final String str) Tests whether the given String is a ISO 639 compliant language code. | |
| isLanguageUndetermined | back to summary |
|---|---|
| public static boolean isLanguageUndetermined(final Locale locale) Tests whether a Locale's language is undetermined.
A Locale's language tag is undetermined if it's value is
| |
| isNumericAreaCode | back to summary |
|---|---|
| private static boolean isNumericAreaCode(final String str) TestsNo whether the given String is a UN M.49 numeric area code.
| |
| languagesByCountry | back to summary |
|---|---|
| public static List Obtains the list of languages supported for a given country. This method takes a country code and searches to find the languages available for that country. Variant locales are removed. | |
| localeLookupList | back to summary |
|---|---|
| public static List Obtains the list of locales to search through when performing a locale search.
localeLookupList(Locale("fr", "CA", "xxx"))
= [Locale("fr", "CA", "xxx"), Locale("fr", "CA"), Locale("fr")]
| |
| localeLookupList | back to summary |
|---|---|
| public static List Obtains the list of locales to search through when performing a locale search.
localeLookupList(Locale("fr", "CA", "xxx"), Locale("en"))
= [Locale("fr", "CA", "xxx"), Locale("fr", "CA"), Locale("fr"), Locale("en"]
The result list begins with the most specific locale, then the next more general and so on, finishing with the default locale. The list will never contain the same locale twice. | |
| ofCountry | back to summary |
|---|---|
| pack-priv static Locale ofCountry(final String country) Creates new Locale for the given country.
| |
| parseLocale | back to summary |
|---|---|
| private static Locale parseLocale(final String str) Tries to parse a Locale from the given String.
See
| |
| toLocale | back to summary |
|---|---|
| public static Locale toLocale(final Locale locale) Returns the given locale if non-
| |
| toLocale | back to summary |
|---|---|
| public static Locale toLocale(final String str) Converts a String to a Locale. This method takes the string format of a locale and creates the locale object from it.
LocaleUtils.toLocale("") = new Locale("", "")
LocaleUtils.toLocale("en") = new Locale("en", "")
LocaleUtils.toLocale("en_GB") = new Locale("en", "GB")
LocaleUtils.toLocale("en-GB") = new Locale("en", "GB")
LocaleUtils.toLocale("en_001") = new Locale("en", "001")
LocaleUtils.toLocale("en_GB_xxx") = new Locale("en", "GB", "xxx") (#)
LocaleUtils.toLocale("US") = new Locale("", "US") // Because "US" is Locale.getISOCountries()
(#) The behavior of the JDK variant constructor changed between JDK1.3 and JDK1.4. In JDK1.3, the constructor upper cases the variant, in JDK1.4, it doesn't. Thus, the result from getVariant() may vary depending on your JDK. This method validates the input strictly. The language code must be lowercase. The country code must be uppercase. The separator must be an underscore or a dash. The length must be correct.
| |
| Modifier and Type | Field and Description |
|---|---|
| private static final List | AVAILABLE_LOCALE_ULIST
Private unmodifiable and sorted list of available locales. |
| private static final Set | AVAILABLE_LOCALE_USET
Private unmodifiable set of available locales. |
| Access | Constructor and Description |
|---|---|
| private |
| AVAILABLE_LOCALE_ULIST | back to summary |
|---|---|
| private static final List<Locale> AVAILABLE_LOCALE_ULIST Private unmodifiable and sorted list of available locales. | |
| AVAILABLE_LOCALE_USET | back to summary |
|---|---|
| private static final Set<Locale> AVAILABLE_LOCALE_USET Private unmodifiable set of available locales. | |
| SyncAvoid | back to summary |
|---|---|
| private SyncAvoid() | |