mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-5197 cache conversions between string and ulocale
X-SVN-Rev: 19621
This commit is contained in:
parent
eda5a86809
commit
a3eec32c70
2 changed files with 33 additions and 4 deletions
|
@ -63,7 +63,7 @@ public class ICULocaleService extends ICUService {
|
|||
* getKey (stripping any prefix) into a ULocale.
|
||||
*/
|
||||
public Object get(ULocale locale, int kind, ULocale[] actualReturn) {
|
||||
Key key = createKey(locale.toString(), kind);
|
||||
Key key = createKey(locale, kind);
|
||||
if (actualReturn == null) {
|
||||
return getKey(key);
|
||||
}
|
||||
|
@ -190,6 +190,17 @@ public class ICULocaleService extends ICUService {
|
|||
return new LocaleKey(primaryID, canonicalPrimaryID, canonicalFallbackID, kind);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a LocaleKey with canonical primary and fallback IDs.
|
||||
*/
|
||||
public static LocaleKey createWithCanonical(ULocale locale, String canonicalFallbackID, int kind) {
|
||||
if (locale == null) {
|
||||
return null;
|
||||
}
|
||||
String canonicalPrimaryID = locale.getName();
|
||||
return new LocaleKey(canonicalPrimaryID, canonicalPrimaryID, canonicalFallbackID, kind);
|
||||
}
|
||||
|
||||
/**
|
||||
* PrimaryID is the user's requested locale string,
|
||||
* canonicalPrimaryID is this string in canonical form,
|
||||
|
@ -593,4 +604,8 @@ public class ICULocaleService extends ICUService {
|
|||
public Key createKey(String id, int kind) {
|
||||
return LocaleKey.createWithCanonicalFallback(id, validateFallbackLocale(), kind);
|
||||
}
|
||||
|
||||
public Key createKey(ULocale l, int kind) {
|
||||
return LocaleKey.createWithCanonical(l, validateFallbackLocale(), kind);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.TreeMap;
|
||||
import java.lang.ref.SoftReference;
|
||||
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
|
@ -1095,6 +1096,9 @@ public final class ULocale implements Serializable {
|
|||
* @stable ICU 3.0
|
||||
*/
|
||||
public static String getBaseName(String localeID){
|
||||
if (localeID.indexOf('@') == -1) {
|
||||
return localeID;
|
||||
}
|
||||
return new IDParser(localeID).getBaseName();
|
||||
}
|
||||
|
||||
|
@ -1116,8 +1120,19 @@ public final class ULocale implements Serializable {
|
|||
* @stable ICU 3.0
|
||||
*/
|
||||
public static String getName(String localeID){
|
||||
return new IDParser(localeID).getName();
|
||||
HashMap cache = (HashMap)nameCacheRef.get();
|
||||
if (cache == null) {
|
||||
cache = new HashMap();
|
||||
nameCacheRef = new SoftReference(cache);
|
||||
}
|
||||
String name = (String)cache.get(localeID);
|
||||
if (name == null) {
|
||||
name = new IDParser(localeID).getName();
|
||||
cache.put(localeID, name);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
private static SoftReference nameCacheRef = new SoftReference(new HashMap());
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
|
@ -2804,9 +2819,8 @@ public final class ULocale implements Serializable {
|
|||
*/
|
||||
|
||||
public static ULocale acceptLanguage(ULocale[] acceptLanguageList, boolean[]
|
||||
fallback) {
|
||||
fallback) {
|
||||
return acceptLanguage(acceptLanguageList, ULocale.getAvailableLocales(),
|
||||
fallback);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue