mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-15 01:42:37 +00:00
ICU-6496 Changed some cache implementation to use ICUCache.
X-SVN-Rev: 24498
This commit is contained in:
parent
8950721fa1
commit
2e78ff98b0
3 changed files with 20 additions and 36 deletions
|
@ -8,15 +8,15 @@
|
|||
package com.ibm.icu.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import com.ibm.icu.impl.Grego;
|
||||
import com.ibm.icu.impl.ICUCache;
|
||||
import com.ibm.icu.impl.ICUConfig;
|
||||
import com.ibm.icu.impl.JavaTimeZone;
|
||||
import com.ibm.icu.impl.SimpleCache;
|
||||
import com.ibm.icu.impl.TimeZoneAdapter;
|
||||
import com.ibm.icu.impl.ZoneMeta;
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
|
@ -160,7 +160,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
|||
/**
|
||||
* Cache to hold the SimpleDateFormat objects for a Locale.
|
||||
*/
|
||||
private static Hashtable cachedLocaleData = new Hashtable(3);
|
||||
private static ICUCache cachedLocaleData = new SimpleCache();
|
||||
|
||||
/**
|
||||
* Gets the time zone offset, for current date, modified in case of
|
||||
|
@ -395,6 +395,10 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
|||
* @deprecated This API is ICU internal only.
|
||||
*/
|
||||
private String _getDisplayName(boolean daylight, int style, ULocale locale) {
|
||||
if (locale == null) {
|
||||
throw new NullPointerException("locale is null");
|
||||
}
|
||||
|
||||
/* NOTES:
|
||||
* (1) We use SimpleDateFormat for simplicity; we could do this
|
||||
* more efficiently but it would duplicate the SimpleDateFormat code
|
||||
|
@ -408,12 +412,10 @@ abstract public class TimeZone implements Serializable, Cloneable {
|
|||
|
||||
// We keep a cache, indexed by locale. The cache contains a
|
||||
// SimpleDateFormat object, which we create on demand.
|
||||
SoftReference data = (SoftReference)cachedLocaleData.get(locale);
|
||||
SimpleDateFormat format;
|
||||
if (data == null ||
|
||||
(format = (SimpleDateFormat)data.get()) == null) {
|
||||
SimpleDateFormat format = (SimpleDateFormat)cachedLocaleData.get(locale);
|
||||
if (format == null) {
|
||||
format = new SimpleDateFormat(null, locale);
|
||||
cachedLocaleData.put(locale, new SoftReference(format));
|
||||
cachedLocaleData.put(locale, format);
|
||||
}
|
||||
|
||||
String[] patterns = { "z", "zzzz", "v", "vvvv" };
|
||||
|
|
|
@ -8,20 +8,19 @@
|
|||
package com.ibm.icu.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.text.ParseException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.ibm.icu.impl.SimpleCache;
|
||||
import com.ibm.icu.impl.ICUCache;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.impl.SimpleCache;
|
||||
|
||||
/**
|
||||
* A class analogous to {@link java.util.Locale} that provides additional
|
||||
|
@ -905,7 +904,7 @@ public final class ULocale implements Serializable {
|
|||
return locale;
|
||||
}
|
||||
|
||||
private static SoftReference nameCacheRef = new SoftReference(Collections.synchronizedMap(new HashMap()));
|
||||
private static ICUCache nameCache = new SimpleCache();
|
||||
/**
|
||||
* Keep our own default ULocale.
|
||||
*/
|
||||
|
@ -1176,15 +1175,10 @@ public final class ULocale implements Serializable {
|
|||
* @stable ICU 3.0
|
||||
*/
|
||||
public static String getName(String localeID){
|
||||
Map cache = (Map)nameCacheRef.get();
|
||||
if (cache == null) {
|
||||
cache = Collections.synchronizedMap(new HashMap());
|
||||
nameCacheRef = new SoftReference(cache);
|
||||
}
|
||||
String name = (String)cache.get(localeID);
|
||||
String name = (String)nameCache.get(localeID);
|
||||
if (name == null) {
|
||||
name = new IDParser(localeID).getName();
|
||||
cache.put(localeID, name);
|
||||
nameCache.put(localeID, name);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -17,9 +17,11 @@ import java.util.MissingResourceException;
|
|||
import java.util.ResourceBundle;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.ibm.icu.impl.ICUCache;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.impl.ICUResourceBundleReader;
|
||||
import com.ibm.icu.impl.ResourceBundleWrapper;
|
||||
import com.ibm.icu.impl.SimpleCache;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
//#if defined(FOUNDATION10) || defined(J2SE13) || defined(ECLIPSE_FRAGMENT)
|
||||
|
@ -302,18 +304,10 @@ public abstract class UResourceBundle extends ResourceBundle{
|
|||
}
|
||||
|
||||
// Cache for ResourceBundle instantiation
|
||||
private static SoftReference BUNDLE_CACHE;
|
||||
private static ICUCache BUNDLE_CACHE = new SimpleCache();
|
||||
|
||||
private static void addToCache(ResourceCacheKey key, UResourceBundle b) {
|
||||
Map m = null;
|
||||
if (BUNDLE_CACHE != null) {
|
||||
m = (Map)BUNDLE_CACHE.get();
|
||||
}
|
||||
if (m == null) {
|
||||
m = new HashMap();
|
||||
BUNDLE_CACHE = new SoftReference(m);
|
||||
}
|
||||
m.put(key, b);
|
||||
BUNDLE_CACHE.put(key, b);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -339,13 +333,7 @@ public abstract class UResourceBundle extends ResourceBundle{
|
|||
}
|
||||
}
|
||||
private static UResourceBundle loadFromCache(ResourceCacheKey key) {
|
||||
if (BUNDLE_CACHE != null) {
|
||||
Map m = (Map)BUNDLE_CACHE.get();
|
||||
if (m != null) {
|
||||
return (UResourceBundle)m.get(key);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return (UResourceBundle)BUNDLE_CACHE.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue