| Constructor: |
public Locale(String language) {
this(language, "", ""); //$NON-NLS-1$//$NON-NLS-2$
}
Constructs a new {@code Locale} using the specified language. Parameters:
language -
the language this {@code Locale} represents.
|
public Locale(String language,
String country) {
this(language, country, ""); //$NON-NLS-1$
}
Constructs a new {@code Locale} using the specified language and country codes. Parameters:
language -
the language this {@code Locale} represents.
country -
the country this {@code Locale} represents.
|
public Locale(String language,
String country,
String variant) {
if (language == null || country == null || variant == null) {
throw new NullPointerException();
}
if(language.length() == 0 && country.length() == 0){
languageCode = "";
countryCode = "";
variantCode = variant;
return;
}
this.uLocale = new ULocale(language, country, variant);
languageCode = uLocale.getLanguage();
// Map new language codes to the obsolete language
// codes so the correct resource bundles will be used.
if (languageCode.equals("he")) {//$NON-NLS-1$
languageCode = "iw"; //$NON-NLS-1$
} else if (languageCode.equals("id")) {//$NON-NLS-1$
languageCode = "in"; //$NON-NLS-1$
} else if (languageCode.equals("yi")) {//$NON-NLS-1$
languageCode = "ji"; //$NON-NLS-1$
}
// countryCode is defined in ASCII character set
countryCode = country.length()!=0?uLocale.getCountry():"";
// Work around for be compatible with RI
variantCode = variant;
}
Constructs a new {@code Locale} using the specified language, country, and
variant codes. Parameters:
language -
the language this {@code Locale} represents.
country -
the country this {@code Locale} represents.
variant -
the variant this {@code Locale} represents.
Throws:
NullPointerException -
if {@code language}, {@code country}, or
{@code variant} is {@code null}.
|
| Method from java.util.Locale Detail: |
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
return null;
}
}
Returns a new {@code Locale} with the same language, country and variant codes as
this {@code Locale}. |
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof Locale) {
Locale o = (Locale) object;
return languageCode.equals(o.languageCode)
&& countryCode.equals(o.countryCode)
&& variantCode.equals(o.variantCode);
}
return false;
}
Compares the specified object to this {@code Locale} and returns whether they are
equal. The object must be an instance of {@code Locale} and have the same
language, country and variant. |
public static Locale[] getAvailableLocales() {
ULocale[] ulocales = ULocale.getAvailableLocales();
Locale[] locales = new Locale[ulocales.length];
for (int i = 0; i < locales.length; i++) {
locales[i] = ulocales[i].toLocale();
}
return locales;
}
Gets the list of installed {@code Locale}. At least a {@code Locale} that is equal to
{@code Locale.US} must be contained in this array. |
public String getCountry() {
return countryCode;
}
Gets the country code for this {@code Locale} or an empty string of no country
was set. |
public static Locale getDefault() {
return defaultLocale;
}
Gets the default {@code Locale}. |
public final String getDisplayCountry() {
return getDisplayCountry(getDefault());
}
Gets the full country name in the default {@code Locale} for the country code of
this {@code Locale}. If there is no matching country name, the country code is
returned. |
public String getDisplayCountry(Locale locale) {
return ULocale.forLocale(this).getDisplayCountry(ULocale.forLocale(locale));
}
Gets the full country name in the specified {@code Locale} for the country code
of this {@code Locale}. If there is no matching country name, the country code is
returned. |
public final String getDisplayLanguage() {
return getDisplayLanguage(getDefault());
}
Gets the full language name in the default {@code Locale} for the language code
of this {@code Locale}. If there is no matching language name, the language code
is returned. |
public String getDisplayLanguage(Locale locale) {
return ULocale.forLocale(this).getDisplayLanguage(ULocale.forLocale(locale));
}
Gets the full language name in the specified {@code Locale} for the language code
of this {@code Locale}. If there is no matching language name, the language code
is returned. |
public final String getDisplayName() {
return getDisplayName(getDefault());
}
Gets the full language, country, and variant names in the default {@code Locale}
for the codes of this {@code Locale}. |
public String getDisplayName(Locale locale) {
int count = 0;
StringBuilder buffer = new StringBuilder();
if (languageCode.length() > 0) {
buffer.append(getDisplayLanguage(locale));
count++;
}
if (countryCode.length() > 0) {
if (count == 1) {
buffer.append(" ("); //$NON-NLS-1$
}
buffer.append(getDisplayCountry(locale));
count++;
}
if (variantCode.length() > 0) {
if (count == 1) {
buffer.append(" ("); //$NON-NLS-1$
} else if (count == 2) {
buffer.append(","); //$NON-NLS-1$
}
buffer.append(getDisplayVariant(locale));
count++;
}
if (count > 1) {
buffer.append(")"); //$NON-NLS-1$
}
return buffer.toString();
}
Gets the full language, country, and variant names in the specified
Locale for the codes of this {@code Locale}. |
public final String getDisplayVariant() {
return getDisplayVariant(getDefault());
}
Gets the full variant name in the default {@code Locale} for the variant code of
this {@code Locale}. If there is no matching variant name, the variant code is
returned. |
public String getDisplayVariant(Locale locale) {
return ULocale.forLocale(this).getDisplayVariant(ULocale.forLocale(locale));
}
Gets the full variant name in the specified {@code Locale} for the variant code
of this {@code Locale}. If there is no matching variant name, the variant code is
returned. |
public String getISO3Country() throws MissingResourceException {
return ULocale.forLocale(this).getISO3Country();
}
Gets the three letter ISO country code which corresponds to the country
code for this {@code Locale}. |
public String getISO3Language() throws MissingResourceException {
return ULocale.forLocale(this).getISO3Language();
}
Gets the three letter ISO language code which corresponds to the language
code for this {@code Locale}. |
public static String[] getISOCountries() {
return ULocale.getISOCountries();
}
Gets the list of two letter ISO country codes which can be used as the
country code for a {@code Locale}. |
public static String[] getISOLanguages() {
return ULocale.getISOLanguages();
}
Gets the list of two letter ISO language codes which can be used as the
language code for a {@code Locale}. |
public String getLanguage() {
return languageCode;
}
Gets the language code for this {@code Locale} or the empty string of no language
was set. |
public String getVariant() {
return variantCode;
}
Gets the variant code for this {@code Locale} or an empty {@code String} of no variant
was set. |
public synchronized int hashCode() {
return countryCode.hashCode() + languageCode.hashCode()
+ variantCode.hashCode();
}
Returns an integer hash code for the receiver. Objects which are equal
return the same value for this method. |
public static synchronized void setDefault(Locale locale) {
if (locale != null) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(setLocalePermission);
}
defaultLocale = locale;
} else {
throw new NullPointerException();
}
}
Sets the default {@code Locale} to the specified {@code Locale}. |
public final String toString() {
StringBuilder result = new StringBuilder();
result.append(languageCode);
if (countryCode.length() > 0) {
result.append('_');
result.append(countryCode);
}
if (variantCode.length() > 0 && result.length() > 0) {
if (0 == countryCode.length()) {
result.append("__"); //$NON-NLS-1$
} else {
result.append('_');
}
result.append(variantCode);
}
return result.toString();
}
Returns the string representation of this {@code Locale}. It consists of the
language followed by the country and at the end the variant. They are
separated by underscores. If the language is missing the string begins
with an underscore. If the country is missing there are 2 underscores
between the language and the variant. the variant alone canot be defined
without a language and/or a country (in this case this method would
return the empty string).
Examples: "en", "en_US", "_US", "en__POSIX", "en_US_POSIX" |