summaryrefslogtreecommitdiffstats
path: root/icu/src/main/java
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-04-16 14:14:28 -0700
committerElliott Hughes <enh@google.com>2010-04-16 14:48:27 -0700
commit757a7942eed2b0aa457f8517a0259d2ac82c5b18 (patch)
tree00f74b34ca4edeac65d9cb38d8291ee249f5a806 /icu/src/main/java
parentb988f4652e9325f77c60c5aa4d71a703a0793ec3 (diff)
downloadlibcore-757a7942eed2b0aa457f8517a0259d2ac82c5b18.zip
libcore-757a7942eed2b0aa457f8517a0259d2ac82c5b18.tar.gz
libcore-757a7942eed2b0aa457f8517a0259d2ac82c5b18.tar.bz2
Merge LocaleData and Resources, rename Resources to ICU.
Also move our ICU tests into our little tree of tests. Bug: 2596471 Change-Id: I73b53d74c26ef9bf670f12cac58b51ba61eefead
Diffstat (limited to 'icu/src/main/java')
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/Collator.java1
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java1
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/util/ICU.java (renamed from icu/src/main/java/com/ibm/icu4jni/util/Resources.java)100
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java104
4 files changed, 97 insertions, 109 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/Collator.java b/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
index 3673d32..7883d30 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/Collator.java
@@ -11,7 +11,6 @@
package com.ibm.icu4jni.text;
import com.ibm.icu4jni.text.RuleBasedCollator;
-import com.ibm.icu4jni.util.Resources;
import java.util.Locale;
/**
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java
index 91f2beb..272d525 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java
@@ -16,7 +16,6 @@
package com.ibm.icu4jni.text;
-import com.ibm.icu4jni.util.Resources;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.Locale;
diff --git a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java b/icu/src/main/java/com/ibm/icu4jni/util/ICU.java
index 874d9be..b684068 100644
--- a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
+++ b/icu/src/main/java/com/ibm/icu4jni/util/ICU.java
@@ -16,26 +16,14 @@
package com.ibm.icu4jni.util;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.ListResourceBundle;
import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
import java.util.TimeZone;
import java.util.logging.Logger;
/**
* Makes ICU data accessible to Java.
- *
- * TODO: move the LocaleData stuff into LocaleData and rename this class.
*/
-public final class Resources {
- // A cache for the locale-specific data.
- private static final HashMap<String, LocaleData> localeDataCache =
- new HashMap<String, LocaleData>();
-
+public final class ICU {
/**
* Cache for ISO language names.
*/
@@ -52,49 +40,6 @@ public final class Resources {
private static String[] availableTimezones;
/**
- * Returns a shared LocaleData for the given locale.
- */
- public static LocaleData getLocaleData(Locale locale) {
- if (locale == null) {
- locale = Locale.getDefault();
- }
- String localeName = locale.toString();
- synchronized (localeDataCache) {
- LocaleData localeData = localeDataCache.get(localeName);
- if (localeData != null) {
- return localeData;
- }
- }
- LocaleData newLocaleData = makeLocaleData(locale);
- synchronized (localeDataCache) {
- LocaleData localeData = localeDataCache.get(localeName);
- if (localeData != null) {
- return localeData;
- }
- localeDataCache.put(localeName, newLocaleData);
- return newLocaleData;
- }
- }
-
- private static LocaleData makeLocaleData(Locale locale) {
- String language = locale.getLanguage();
- String country = locale.getCountry();
- String variant = locale.getVariant();
- // Start with data from the parent (next-most-specific) locale...
- LocaleData result = new LocaleData();
- if (variant.length() > 0) {
- result.overrideWithDataFrom(getLocaleData(new Locale(language, country, "")));
- } else if (country.length() > 0) {
- result.overrideWithDataFrom(getLocaleData(new Locale(language, "", "")));
- } else if (language.length() > 0) {
- result.overrideWithDataFrom(getLocaleData(Locale.ROOT));
- }
- // Override with data from this locale.
- result.overrideWithDataFrom(initLocaleData(locale));
- return result;
- }
-
- /**
* Returns an array of ISO language names (two-letter codes), fetched either
* from ICU's database or from our memory cache.
*
@@ -104,7 +49,6 @@ public final class Resources {
if (isoLanguages == null) {
isoLanguages = getISOLanguagesNative();
}
-
return isoLanguages.clone();
}
@@ -118,7 +62,6 @@ public final class Resources {
if (isoCountries == null) {
isoCountries = getISOCountriesNative();
}
-
return isoCountries.clone();
}
@@ -129,11 +72,9 @@ public final class Resources {
* @return The array.
*/
public static String[] getKnownTimezones() {
- // TODO Drop the Linux ZoneInfo stuff in favor of ICU.
if (availableTimezones == null) {
availableTimezones = TimeZone.getAvailableIDs();
}
-
return availableTimezones.clone();
}
@@ -233,8 +174,7 @@ public final class Resources {
result[i][4] = arrayToFill[4][i];
}
- Logger.getLogger(Resources.class.getSimpleName()).info(
- "Loaded time zone names for " + locale + " in "
+ Logger.global.info("Loaded time zone names for " + locale + " in "
+ (System.currentTimeMillis() - start) + "ms.");
return result;
@@ -348,6 +288,10 @@ public final class Resources {
private static native String[] getAvailableLocalesNative();
private static native String[] getAvailableNumberFormatLocalesNative();
+ public static native String getCurrencyCodeNative(String locale);
+ public static native int getCurrencyFractionDigitsNative(String currencyCode);
+ public static native String getCurrencySymbolNative(String locale, String currencyCode);
+
public static native String getDisplayCountryNative(String countryCode, String locale);
public static native String getDisplayLanguageNative(String languageCode, String locale);
public static native String getDisplayVariantNative(String variantCode, String locale);
@@ -355,11 +299,6 @@ public final class Resources {
public static native String getISO3CountryNative(String locale);
public static native String getISO3LanguageNative(String locale);
- public static native String getCurrencyCodeNative(String locale);
- public static native String getCurrencySymbolNative(String locale, String currencyCode);
-
- public static native int getCurrencyFractionDigitsNative(String currencyCode);
-
private static native String[] getISOLanguagesNative();
private static native String[] getISOCountriesNative();
@@ -368,30 +307,5 @@ public final class Resources {
private static native String getDisplayTimeZoneNative(String id, boolean isDST, int style,
String locale);
- private static LocaleData initLocaleData(Locale locale) {
- LocaleData localeData = new LocaleData();
- if (!initLocaleDataImpl(locale.toString(), localeData)) {
- throw new AssertionError("couldn't initialize LocaleData for locale " + locale);
- }
- if (localeData.fullTimeFormat != null) {
- // There are some full time format patterns in ICU that use the pattern character 'v'.
- // Java doesn't accept this, so we replace it with 'z' which has about the same result
- // as 'v', the timezone name.
- // 'v' -> "PT", 'z' -> "PST", v is the generic timezone and z the standard tz
- // "vvvv" -> "Pacific Time", "zzzz" -> "Pacific Standard Time"
- localeData.fullTimeFormat = localeData.fullTimeFormat.replace('v', 'z');
- }
- if (localeData.numberPattern != null) {
- // The number pattern might contain positive and negative subpatterns. Arabic, for
- // example, might look like "#,##0.###;#,##0.###-" because the minus sign should be
- // written last. Macedonian supposedly looks something like "#,##0.###;(#,##0.###)".
- // (The negative subpattern is optional, though, and not present in most locales.)
- // By only swallowing '#'es and ','s after the '.', we ensure that we don't
- // accidentally eat too much.
- localeData.integerPattern = localeData.numberPattern.replaceAll("\\.[#,]*", "");
- }
- return localeData;
- }
-
- private static native boolean initLocaleDataImpl(String locale, LocaleData result);
+ static native boolean initLocaleDataImpl(String locale, LocaleData result);
}
diff --git a/icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java b/icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java
index 0ba18d1..e27bd54 100644
--- a/icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java
+++ b/icu/src/main/java/com/ibm/icu4jni/util/LocaleData.java
@@ -18,6 +18,8 @@ package com.ibm.icu4jni.util;
import java.text.DateFormat;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Locale;
/**
* Passes locale-specific from ICU native code to Java.
@@ -27,29 +29,32 @@ import java.util.Arrays;
* them a clone rather than the original.
*/
public final class LocaleData {
+ // A cache for the locale-specific data.
+ private static final HashMap<String, LocaleData> localeDataCache = new HashMap<String, LocaleData>();
+
public Integer firstDayOfWeek;
public Integer minimalDaysInFirstWeek;
-
+
public String[] amPm;
-
+
public String[] eras;
-
+
public String[] longMonthNames;
public String[] shortMonthNames;
-
+
public String[] longWeekdayNames;
public String[] shortWeekdayNames;
-
+
public String fullTimeFormat;
public String longTimeFormat;
public String mediumTimeFormat;
public String shortTimeFormat;
-
+
public String fullDateFormat;
public String longDateFormat;
public String mediumDateFormat;
public String shortDateFormat;
-
+
// DecimalFormatSymbols.
public char zeroDigit;
public char digit;
@@ -63,15 +68,61 @@ public final class LocaleData {
public String exponentSeparator;
public String infinity;
public String NaN;
-
+
public String currencySymbol;
public String internationalCurrencySymbol;
-
+
public String numberPattern;
public String integerPattern;
public String currencyPattern;
public String percentPattern;
-
+
+ private LocaleData() {
+ }
+
+ /**
+ * Returns a shared LocaleData for the given locale.
+ */
+ public static LocaleData get(Locale locale) {
+ if (locale == null) {
+ locale = Locale.getDefault();
+ }
+ String localeName = locale.toString();
+ synchronized (localeDataCache) {
+ LocaleData localeData = localeDataCache.get(localeName);
+ if (localeData != null) {
+ return localeData;
+ }
+ }
+ LocaleData newLocaleData = makeLocaleData(locale);
+ synchronized (localeDataCache) {
+ LocaleData localeData = localeDataCache.get(localeName);
+ if (localeData != null) {
+ return localeData;
+ }
+ localeDataCache.put(localeName, newLocaleData);
+ return newLocaleData;
+ }
+ }
+
+ private static LocaleData makeLocaleData(Locale locale) {
+ String language = locale.getLanguage();
+ String country = locale.getCountry();
+ String variant = locale.getVariant();
+ // Start with data from the parent (next-most-specific) locale...
+ LocaleData result = new LocaleData();
+ if (!variant.isEmpty()) {
+ result.overrideWithDataFrom(get(new Locale(language, country, "")));
+ } else if (!country.isEmpty()) {
+ result.overrideWithDataFrom(get(new Locale(language, "", "")));
+ } else if (!language.isEmpty()) {
+ result.overrideWithDataFrom(get(Locale.ROOT));
+ }
+ // Override with data from this locale.
+ result.overrideWithDataFrom(initLocaleData(locale));
+ return result;
+ }
+
@Override public String toString() {
return "LocaleData[" +
"firstDayOfWeek=" + firstDayOfWeek + "," +
@@ -109,8 +160,8 @@ public final class LocaleData {
"currencyPattern=" + currencyPattern + "," +
"percentPattern=" + percentPattern + "]";
}
-
- public void overrideWithDataFrom(LocaleData overrides) {
+
+ private void overrideWithDataFrom(LocaleData overrides) {
if (overrides.firstDayOfWeek != null) {
firstDayOfWeek = overrides.firstDayOfWeek;
}
@@ -214,7 +265,7 @@ public final class LocaleData {
percentPattern = overrides.percentPattern;
}
}
-
+
public String getDateFormat(int style) {
switch (style) {
case DateFormat.SHORT:
@@ -228,7 +279,7 @@ public final class LocaleData {
}
throw new AssertionError();
}
-
+
public String getTimeFormat(int style) {
switch (style) {
case DateFormat.SHORT:
@@ -242,4 +293,29 @@ public final class LocaleData {
}
throw new AssertionError();
}
+
+ private static LocaleData initLocaleData(Locale locale) {
+ LocaleData localeData = new LocaleData();
+ if (!ICU.initLocaleDataImpl(locale.toString(), localeData)) {
+ throw new AssertionError("couldn't initialize LocaleData for locale " + locale);
+ }
+ if (localeData.fullTimeFormat != null) {
+ // There are some full time format patterns in ICU that use the pattern character 'v'.
+ // Java doesn't accept this, so we replace it with 'z' which has about the same result
+ // as 'v', the timezone name.
+ // 'v' -> "PT", 'z' -> "PST", v is the generic timezone and z the standard tz
+ // "vvvv" -> "Pacific Time", "zzzz" -> "Pacific Standard Time"
+ localeData.fullTimeFormat = localeData.fullTimeFormat.replace('v', 'z');
+ }
+ if (localeData.numberPattern != null) {
+ // The number pattern might contain positive and negative subpatterns. Arabic, for
+ // example, might look like "#,##0.###;#,##0.###-" because the minus sign should be
+ // written last. Macedonian supposedly looks something like "#,##0.###;(#,##0.###)".
+ // (The negative subpattern is optional, though, and not present in most locales.)
+ // By only swallowing '#'es and ','s after the '.', we ensure that we don't
+ // accidentally eat too much.
+ localeData.integerPattern = localeData.numberPattern.replaceAll("\\.[#,]*", "");
+ }
+ return localeData;
+ }
}