ICU-5976 Added TestICUEquivalent to NumberFormatTest. Cleaned up SPI configuration file and code. Changed NumberFormatProviderICU to return NumberFormatICU, not DecimalFormatICU by default.
X-SVN-Rev: 24127
This commit is contained in:
parent
4635ea3a9c
commit
ddfebd79a2
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -128,7 +128,7 @@ icu4j/localespi/src/META-INF/services/java.text.spi.NumberFormatProvider -text
|
||||
icu4j/localespi/src/META-INF/services/java.util.spi.CurrencyNameProvider -text
|
||||
icu4j/localespi/src/META-INF/services/java.util.spi.LocaleNameProvider -text
|
||||
icu4j/localespi/src/META-INF/services/java.util.spi.TimeZoneNameProvider -text
|
||||
icu4j/localespi/src/com/ibm/icu/impl/javaspi/ICUProvider.properties -text
|
||||
icu4j/localespi/src/com/ibm/icu/impl/javaspi/ICULocaleServiceProviderConfig.properties -text
|
||||
icu4j/preprocessor.txt -text
|
||||
icu4j/src/com/ibm/icu/ICUConfig.properties -text
|
||||
icu4j/src/com/ibm/icu/charset/CharsetISO2022.java -text
|
||||
|
@ -56,7 +56,7 @@
|
||||
<jar jarfile="${jar.file}" compress="true">
|
||||
<fileset dir="${src.dir}">
|
||||
<include name="META-INF/services/java.*Provider"/>
|
||||
<include name="com/ibm/icu/impl/javaspi/ICUProvider.properties"/>
|
||||
<include name="com/ibm/icu/impl/javaspi/ICULocaleServiceProviderConfig.properties"/>
|
||||
</fileset>
|
||||
<fileset dir="${build.dir}">
|
||||
<include name="com/ibm/icu/impl/**/*"/>
|
||||
|
@ -79,7 +79,7 @@ public class DateFormatTest extends TestFmwk {
|
||||
}
|
||||
|
||||
private com.ibm.icu.text.DateFormat getICUInstance(int dstyle, int tstyle, Locale loc, String[] methodName) {
|
||||
com.ibm.icu.text.DateFormat icudf;;
|
||||
com.ibm.icu.text.DateFormat icudf;
|
||||
String method;
|
||||
if (dstyle < 0) {
|
||||
icudf = com.ibm.icu.text.DateFormat.getTimeInstance(tstyle, loc);
|
||||
|
@ -6,7 +6,10 @@
|
||||
*/
|
||||
package com.ibm.icu.dev.test.localespi;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
@ -37,7 +40,39 @@ public class NumberFormatTest extends TestFmwk {
|
||||
|
||||
private void checkGetInstance(int type, Locale loc) {
|
||||
NumberFormat nf;
|
||||
String method;
|
||||
String[] method = new String[1];
|
||||
nf = getJDKInstance(type, loc, method);
|
||||
|
||||
boolean isIcuImpl = (nf instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatICU)
|
||||
|| (nf instanceof com.ibm.icu.impl.jdkadapter.NumberFormatICU);
|
||||
if (TestUtil.isICUExtendedLocale(loc)) {
|
||||
if (!isIcuImpl) {
|
||||
errln("FAIL: " + method[0] + " returned JDK NumberFormat for locale " + loc);
|
||||
}
|
||||
} else {
|
||||
if (isIcuImpl) {
|
||||
logln("INFO: " + method[0] + " returned ICU NumberFormat for locale " + loc);
|
||||
}
|
||||
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
|
||||
NumberFormat nfIcu = null;
|
||||
nfIcu = getJDKInstance(type, iculoc, null);
|
||||
if (isIcuImpl) {
|
||||
if (!nf.equals(nfIcu)) {
|
||||
errln("FAIL: " + method[0] + " returned ICU NumberFormat for locale " + loc
|
||||
+ ", but different from the one for locale " + iculoc);
|
||||
}
|
||||
} else {
|
||||
if (!(nfIcu instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatICU)
|
||||
&& !(nfIcu instanceof com.ibm.icu.impl.jdkadapter.NumberFormatICU)) {
|
||||
errln("FAIL: " + method[0] + " returned JDK NumberFormat for locale " + iculoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NumberFormat getJDKInstance(int type, Locale loc, String[] methodName) {
|
||||
NumberFormat nf = null;
|
||||
String method = null;
|
||||
|
||||
switch (type) {
|
||||
case DEFAULT_TYPE:
|
||||
@ -60,47 +95,191 @@ public class NumberFormatTest extends TestFmwk {
|
||||
nf = NumberFormat.getCurrencyInstance(loc);
|
||||
method = "getCurrencyInstance";
|
||||
break;
|
||||
default:
|
||||
errln("FAIL: Unknown number format type");
|
||||
return;
|
||||
}
|
||||
if (methodName != null) {
|
||||
methodName[0] = method;
|
||||
}
|
||||
return nf;
|
||||
}
|
||||
|
||||
boolean isIcuImpl = (nf instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatICU);
|
||||
if (TestUtil.isICUExtendedLocale(loc)) {
|
||||
if (!isIcuImpl) {
|
||||
errln("FAIL: " + method + " returned JDK NumberFormat for locale " + loc);
|
||||
}
|
||||
} else {
|
||||
if (isIcuImpl) {
|
||||
logln("INFO: " + method + " returned ICU NumberFormat for locale " + loc);
|
||||
}
|
||||
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
|
||||
NumberFormat nfIcu = null;
|
||||
switch (type) {
|
||||
case DEFAULT_TYPE:
|
||||
nfIcu = NumberFormat.getInstance(iculoc);
|
||||
break;
|
||||
case NUMBER_TYPE:
|
||||
nfIcu = NumberFormat.getNumberInstance(iculoc);
|
||||
break;
|
||||
case INTEGER_TYPE:
|
||||
nfIcu = NumberFormat.getIntegerInstance(iculoc);
|
||||
break;
|
||||
case PERCENT_TYPE:
|
||||
nfIcu = NumberFormat.getPercentInstance(iculoc);
|
||||
break;
|
||||
case CURRENCY_TYPE:
|
||||
nfIcu = NumberFormat.getCurrencyInstance(iculoc);
|
||||
break;
|
||||
}
|
||||
if (isIcuImpl) {
|
||||
if (!nf.equals(nfIcu)) {
|
||||
errln("FAIL: " + method + " returned ICU NumberFormat for locale " + loc
|
||||
+ ", but different from the one for locale " + iculoc);
|
||||
private com.ibm.icu.text.NumberFormat getICUInstance(int type, Locale loc, String[] methodName) {
|
||||
com.ibm.icu.text.NumberFormat icunf = null;
|
||||
String method = null;
|
||||
|
||||
switch (type) {
|
||||
case DEFAULT_TYPE:
|
||||
icunf = com.ibm.icu.text.NumberFormat.getInstance(loc);
|
||||
method = "getInstance";
|
||||
break;
|
||||
case NUMBER_TYPE:
|
||||
icunf = com.ibm.icu.text.NumberFormat.getNumberInstance(loc);
|
||||
method = "getNumberInstance";
|
||||
break;
|
||||
case INTEGER_TYPE:
|
||||
icunf = com.ibm.icu.text.NumberFormat.getIntegerInstance(loc);
|
||||
method = "getIntegerInstance";
|
||||
break;
|
||||
case PERCENT_TYPE:
|
||||
icunf = com.ibm.icu.text.NumberFormat.getPercentInstance(loc);
|
||||
method = "getPercentInstance";
|
||||
break;
|
||||
case CURRENCY_TYPE:
|
||||
icunf = com.ibm.icu.text.NumberFormat.getCurrencyInstance(loc);
|
||||
method = "getCurrencyInstance";
|
||||
break;
|
||||
}
|
||||
if (methodName != null) {
|
||||
methodName[0] = method;
|
||||
}
|
||||
return icunf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Testing the behavior of number format between ICU instance and its
|
||||
* equivalent created via the Locale SPI framework.
|
||||
*/
|
||||
public void TestICUEquivalent() {
|
||||
Locale[] TEST_LOCALES = {
|
||||
new Locale("en", "US"),
|
||||
new Locale("de", "DE"),
|
||||
new Locale("zh"),
|
||||
};
|
||||
|
||||
long[] TEST_LONGS = {
|
||||
40L,
|
||||
-1578L,
|
||||
112233445566778899L,
|
||||
};
|
||||
|
||||
double[] TEST_DOUBLES = {
|
||||
0.0451D,
|
||||
-1.679D,
|
||||
124578.369D,
|
||||
};
|
||||
|
||||
Object[] TEST_NUMBERS = {
|
||||
Byte.valueOf((byte)13),
|
||||
Integer.valueOf(3961),
|
||||
Long.valueOf(-3451237890000L),
|
||||
Float.valueOf(1.754F),
|
||||
Double.valueOf(-129.942362353D),
|
||||
new BigInteger("-15253545556575859505"),
|
||||
new BigDecimal("3.14159265358979323846264338"),
|
||||
};
|
||||
|
||||
String[] methodName = new String[1];
|
||||
for (Locale loc : TEST_LOCALES) {
|
||||
for (int type = 0; type <= 4; type++) {
|
||||
Locale iculoc = TestUtil.toICUExtendedLocale(loc);
|
||||
NumberFormat nf = getJDKInstance(type, iculoc, methodName);
|
||||
com.ibm.icu.text.NumberFormat icunf = getICUInstance(type, loc, null);
|
||||
|
||||
String s1, s2;
|
||||
Number n1, n2;
|
||||
boolean pe1, pe2;
|
||||
for (long l : TEST_LONGS) {
|
||||
s1 = nf.format(l);
|
||||
s2 = icunf.format(l);
|
||||
|
||||
if (!s1.equals(s2)) {
|
||||
errln("FAIL: Different results for formatting long " + l + " by NumberFormat("
|
||||
+ methodName[0] + ") in locale " + loc + " - JDK:" + s1 + " ICU:" + s2);
|
||||
}
|
||||
|
||||
pe1 = false;
|
||||
n1 = n2 = null;
|
||||
try {
|
||||
n1 = nf.parse(s1);
|
||||
} catch (ParseException e) {
|
||||
pe1 = true;
|
||||
}
|
||||
pe2 = false;
|
||||
try {
|
||||
n2 = icunf.parse(s2);
|
||||
} catch (ParseException e) {
|
||||
pe2 = true;
|
||||
}
|
||||
if ((pe1 && !pe2) || (!pe1 && pe2)) {
|
||||
errln("FAIL: ParseException thrown by " + (pe1 ? "JDK" : "ICU")
|
||||
+ " NumberFormat(" + methodName[0] + ") for parsing long" + l
|
||||
+ " in locale " + loc);
|
||||
} else if (!pe1 && !pe2 && !n1.equals(n2)) {
|
||||
errln("FAIL: Different results for parsing long " + l + " by NumberFormat("
|
||||
+ methodName[0] + ") in locale " + loc + " - JDK:" + n1 + " ICU:" + n2);
|
||||
} else if (pe1 && pe2) {
|
||||
logln("INFO: ParseException thrown by both JDK and ICU NumberFormat("
|
||||
+ methodName[0] + ") for parsing long " + l + " in locale " + loc);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!(nfIcu instanceof com.ibm.icu.impl.jdkadapter.DecimalFormatICU)) {
|
||||
errln("FAIL: " + method + " returned JDK NumberFormat for locale " + iculoc);
|
||||
|
||||
for (double d : TEST_DOUBLES) {
|
||||
s1 = nf.format(d);
|
||||
s2 = icunf.format(d);
|
||||
|
||||
if (!s1.equals(s2)) {
|
||||
errln("FAIL: Different results for formatting double " + d + " by NumberFormat("
|
||||
+ methodName[0] + ") in locale " + loc + " - JDK:" + s1 + " ICU:" + s2);
|
||||
}
|
||||
|
||||
pe1 = false;
|
||||
n1 = n2 = null;
|
||||
try {
|
||||
n1 = nf.parse(s1);
|
||||
} catch (ParseException e) {
|
||||
pe1 = true;
|
||||
}
|
||||
pe2 = false;
|
||||
try {
|
||||
n2 = icunf.parse(s2);
|
||||
} catch (ParseException e) {
|
||||
pe2 = true;
|
||||
}
|
||||
if ((pe1 && !pe2) || (!pe1 && pe2)) {
|
||||
errln("FAIL: ParseException thrown by " + (pe1 ? "JDK" : "ICU")
|
||||
+ " NumberFormat(" + methodName[0] + ") for parsing double" + d
|
||||
+ " in locale " + loc);
|
||||
} else if (!pe1 && !pe2 && !n1.equals(n2)) {
|
||||
errln("FAIL: Different results for parsing double " + d + " by NumberFormat("
|
||||
+ methodName[0] + ") in locale " + loc + " - JDK:" + n1 + " ICU:" + n2);
|
||||
} else if (pe1 && pe2) {
|
||||
logln("INFO: ParseException thrown by both JDK and ICU NumberFormat("
|
||||
+ methodName[0] + ") for parsing double " + d + " in locale " + loc);
|
||||
}
|
||||
}
|
||||
|
||||
for (Object o : TEST_NUMBERS) {
|
||||
s1 = nf.format(o);
|
||||
s2 = icunf.format(o);
|
||||
|
||||
if (!s1.equals(s2)) {
|
||||
errln("FAIL: Different results for formatting " + o.getClass().getName() + " by NumberFormat("
|
||||
+ methodName[0] + ") in locale " + loc + " - JDK:" + s1 + " ICU:" + s2);
|
||||
}
|
||||
|
||||
pe1 = false;
|
||||
n1 = n2 = null;
|
||||
try {
|
||||
n1 = nf.parse(s1);
|
||||
} catch (ParseException e) {
|
||||
pe1 = true;
|
||||
}
|
||||
pe2 = false;
|
||||
try {
|
||||
n2 = icunf.parse(s2);
|
||||
} catch (ParseException e) {
|
||||
pe2 = true;
|
||||
}
|
||||
if ((pe1 && !pe2) || (!pe1 && pe2)) {
|
||||
errln("FAIL: ParseException thrown by " + (pe1 ? "JDK" : "ICU")
|
||||
+ " NumberFormat(" + methodName[0] + ") for parsing " + o.getClass().getName()
|
||||
+ " in locale " + loc);
|
||||
} else if (!pe1 && !pe2 && !n1.equals(n2)) {
|
||||
errln("FAIL: Different results for parsing " + o.getClass().getName() + " by NumberFormat("
|
||||
+ methodName[0] + ") in locale " + loc + " - JDK:" + n1 + " ICU:" + n2);
|
||||
} else if (pe1 && pe2) {
|
||||
logln("INFO: ParseException thrown by both JDK and ICU NumberFormat("
|
||||
+ methodName[0] + ") for parsing " + o.getClass().getName() + " in locale " + loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,15 +18,20 @@ import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.text.DecimalFormatSymbols;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class ICULocale {
|
||||
private static final String SPI_PROP_FILE = "com/ibm/icu/impl/javaspi/ICUProvider.properties";
|
||||
private static final String ADD_VARIANTS_KEY = "com.ibm.icu.impl.javaspi.ICULocale.addIcuVariants";
|
||||
private static final String ADD_ISO3_LANG_KEY = "com.ibm.icu.impl.javaspi.ICULocale.addIso3Languages";
|
||||
private static final String SUFFIX_KEY = "com.ibm.icu.impl.javaspi.ICULocale.icuVariantSuffix";
|
||||
public class ICULocaleServiceProvider {
|
||||
private static final String SPI_PROP_FILE = "com/ibm/icu/impl/javaspi/ICULocaleServiceProviderConfig.properties";
|
||||
|
||||
private static final String DEFAULT_SUFFIX = "ICU";
|
||||
private static final boolean DEFAULT_ADD_VARIANTS = true;
|
||||
private static final boolean DEFAULT_ADD_ISO3_LANG = true;
|
||||
private static final String SUFFIX_KEY = "com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.icuVariantSuffix";
|
||||
private static final String ENABLE_VARIANTS_KEY = "com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.enableIcuVariants";
|
||||
private static final String ENABLE_ISO3_LANG_KEY = "com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.enableIso3Languages";
|
||||
private static final String USE_DECIMALFORMAT_KEY = "com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.useDecimalFormat";
|
||||
|
||||
private static boolean configLoaded = false;
|
||||
|
||||
private static String suffix = "ICU";
|
||||
private static boolean enableVariants = true;
|
||||
private static boolean enableIso3Lang = true;
|
||||
private static boolean useDecimalFormat = false;
|
||||
|
||||
private static final Locale[] SPECIAL_LOCALES = {
|
||||
new Locale("ja", "JP", "JP"),
|
||||
@ -38,9 +43,6 @@ public class ICULocale {
|
||||
};
|
||||
|
||||
private static Locale[] LOCALES = null;
|
||||
private static Boolean ADD_VARIANTS = null;
|
||||
private static Boolean ADD_ISO3_LANG = null;
|
||||
private static String SUFFIX = null;
|
||||
|
||||
public static Locale[] getAvailableLocales() {
|
||||
Locale[] all = getLocales();
|
||||
@ -61,6 +63,11 @@ public class ICULocale {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean useDecimalFormat() {
|
||||
loadConfiguration();
|
||||
return useDecimalFormat;
|
||||
}
|
||||
|
||||
private static final Locale THAI_NATIVE_DIGIT_LOCALE = new Locale("th", "TH", "TH");
|
||||
private static final char THAI_NATIVE_ZERO = '\u0E50';
|
||||
private static DecimalFormatSymbols THAI_NATIVE_DECIMAL_SYMBOLS = null;
|
||||
@ -94,7 +101,7 @@ public class ICULocale {
|
||||
String language = uloc.getLanguage();
|
||||
String country = uloc.getCountry();
|
||||
String variant = uloc.getVariant();
|
||||
if (language.length() >= 3 && !addIso3Languages()) {
|
||||
if (language.length() >= 3 && !enableIso3Languages()) {
|
||||
continue;
|
||||
}
|
||||
addLocale(new Locale(language, country, variant), localeSet);
|
||||
@ -111,7 +118,7 @@ public class ICULocale {
|
||||
private static void addLocale(Locale loc, Set<Locale> locales) {
|
||||
locales.add(loc);
|
||||
|
||||
if (addIcuVariants()) {
|
||||
if (enableIcuVariants()) {
|
||||
// Add ICU variant
|
||||
String language = loc.getLanguage();
|
||||
String country = loc.getCountry();
|
||||
@ -126,49 +133,51 @@ public class ICULocale {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean addIso3Languages() {
|
||||
initConfig();
|
||||
return ADD_ISO3_LANG.booleanValue();
|
||||
private static boolean enableIso3Languages() {
|
||||
return enableIso3Lang;
|
||||
}
|
||||
|
||||
private static boolean addIcuVariants() {
|
||||
initConfig();
|
||||
return ADD_VARIANTS.booleanValue();
|
||||
private static boolean enableIcuVariants() {
|
||||
loadConfiguration();
|
||||
return enableVariants;
|
||||
}
|
||||
|
||||
private static String getIcuSuffix() {
|
||||
initConfig();
|
||||
return SUFFIX;
|
||||
loadConfiguration();
|
||||
return suffix;
|
||||
}
|
||||
|
||||
private static synchronized void initConfig() {
|
||||
if (SUFFIX != null) {
|
||||
private static synchronized void loadConfiguration() {
|
||||
if (configLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
Properties spiConfigProps = new Properties();
|
||||
try {
|
||||
InputStream is = ClassLoader.getSystemResourceAsStream(SPI_PROP_FILE);
|
||||
spiConfigProps.load(is);
|
||||
|
||||
String addVariants = (String)spiConfigProps.get(ADD_VARIANTS_KEY);
|
||||
ADD_VARIANTS = Boolean.parseBoolean(addVariants);
|
||||
|
||||
String addIso3Lang = (String)spiConfigProps.get(ADD_ISO3_LANG_KEY);
|
||||
ADD_ISO3_LANG = Boolean.parseBoolean(addIso3Lang);
|
||||
|
||||
SUFFIX = (String)spiConfigProps.get(SUFFIX_KEY);
|
||||
String val = (String)spiConfigProps.get(SUFFIX_KEY);
|
||||
if (val != null && val.length() > 0) {
|
||||
suffix = val;
|
||||
}
|
||||
enableVariants = parseBooleanString((String)spiConfigProps.get(ENABLE_VARIANTS_KEY), enableVariants);
|
||||
enableIso3Lang = parseBooleanString((String)spiConfigProps.get(ENABLE_ISO3_LANG_KEY), enableIso3Lang);
|
||||
useDecimalFormat = parseBooleanString((String)spiConfigProps.get(USE_DECIMALFORMAT_KEY), useDecimalFormat);
|
||||
} catch (IOException ioe) {
|
||||
// Any IO errors, ignore
|
||||
}
|
||||
if (ADD_ISO3_LANG == null) {
|
||||
ADD_ISO3_LANG = Boolean.valueOf(DEFAULT_ADD_VARIANTS);
|
||||
configLoaded = true;
|
||||
}
|
||||
|
||||
private static boolean parseBooleanString(String str, boolean defaultVal) {
|
||||
if (str == null) {
|
||||
return defaultVal;
|
||||
}
|
||||
if (ADD_VARIANTS == null) {
|
||||
ADD_VARIANTS = Boolean.valueOf(DEFAULT_ADD_ISO3_LANG);
|
||||
}
|
||||
if (SUFFIX == null) {
|
||||
SUFFIX = DEFAULT_SUFFIX;
|
||||
if (str.equalsIgnoreCase("true")) {
|
||||
return true;
|
||||
} else if (str.equalsIgnoreCase("false")) {
|
||||
return false;
|
||||
}
|
||||
return defaultVal;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
#*
|
||||
#*******************************************************************************
|
||||
#* Copyright (C) 2008, International Business Machines Corporation and *
|
||||
#* others. All Rights Reserved. *
|
||||
#*******************************************************************************
|
||||
#* This is the properties is used for configuring ICU locale service provider
|
||||
#* implementation.
|
||||
#*
|
||||
|
||||
# Whether if Locales with ICU's variant suffix will be included in getAvailableLocales.
|
||||
# [default: true]
|
||||
com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.enableIcuVariants = true
|
||||
|
||||
# Suffix string used in Locale's variant field to specify the ICU implementation.
|
||||
# [default: ICU]
|
||||
com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.icuVariantSuffix = ICU
|
||||
|
||||
# Whether if 3-letter language Locales are included in getAvailabeLocales.
|
||||
# [default: true]
|
||||
com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.enableIso3Languages = true
|
||||
|
||||
# Whether if java.text.DecimalFormat subclass is used for NumberFormat#getXXXInstance.
|
||||
# DecimalFormat#format(Object,StringBuffer,FieldPosition) is declared as final, so
|
||||
# ICU cannot override the implementation. As a result, some number types such as
|
||||
# BigInteger/BigDecimal are not handled by the ICU implementation. If a client expects
|
||||
# NumberFormat#getXXXInstance returns a DecimalFormat (for example, need to manipulate
|
||||
# decimal format patterns), he/she can set true to this setting. However, in this case,
|
||||
# BigInteger/BigDecimal support is not done by ICU's implementation.
|
||||
# [default: false]
|
||||
com.ibm.icu.impl.javaspi.ICULocaleServiceProvider.useDecimalFormat = false
|
@ -1,11 +0,0 @@
|
||||
#*
|
||||
#*******************************************************************************
|
||||
#* Copyright (C) 2008, International Business Machines Corporation and *
|
||||
#* others. All Rights Reserved. *
|
||||
#*******************************************************************************
|
||||
#* This is the properties is used for configuring ICU locale service provider
|
||||
#* implementation.
|
||||
#*
|
||||
com.ibm.icu.impl.javaspi.ICULocale.addIso3Languages = true
|
||||
com.ibm.icu.impl.javaspi.ICULocale.addIcuVariants = true
|
||||
com.ibm.icu.impl.javaspi.ICULocale.icuVariantSuffix = ICU
|
@ -10,7 +10,7 @@ import java.text.BreakIterator;
|
||||
import java.text.spi.BreakIteratorProvider;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.impl.javaspi.ICULocale;
|
||||
import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;
|
||||
import com.ibm.icu.impl.jdkadapter.BreakIteratorICU;
|
||||
|
||||
public class BreakIteratorProviderICU extends BreakIteratorProvider {
|
||||
@ -18,34 +18,34 @@ public class BreakIteratorProviderICU extends BreakIteratorProvider {
|
||||
@Override
|
||||
public BreakIterator getCharacterInstance(Locale locale) {
|
||||
com.ibm.icu.text.BreakIterator icuBrkItr = com.ibm.icu.text.BreakIterator.getCharacterInstance(
|
||||
ICULocale.canonicalize(locale));
|
||||
ICULocaleServiceProvider.canonicalize(locale));
|
||||
return BreakIteratorICU.wrap(icuBrkItr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakIterator getLineInstance(Locale locale) {
|
||||
com.ibm.icu.text.BreakIterator icuBrkItr = com.ibm.icu.text.BreakIterator.getLineInstance(
|
||||
ICULocale.canonicalize(locale));
|
||||
ICULocaleServiceProvider.canonicalize(locale));
|
||||
return BreakIteratorICU.wrap(icuBrkItr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakIterator getSentenceInstance(Locale locale) {
|
||||
com.ibm.icu.text.BreakIterator icuBrkItr = com.ibm.icu.text.BreakIterator.getSentenceInstance(
|
||||
ICULocale.canonicalize(locale));
|
||||
ICULocaleServiceProvider.canonicalize(locale));
|
||||
return BreakIteratorICU.wrap(icuBrkItr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BreakIterator getWordInstance(Locale locale) {
|
||||
com.ibm.icu.text.BreakIterator icuBrkItr = com.ibm.icu.text.BreakIterator.getWordInstance(
|
||||
ICULocale.canonicalize(locale));
|
||||
ICULocaleServiceProvider.canonicalize(locale));
|
||||
return BreakIteratorICU.wrap(icuBrkItr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale[] getAvailableLocales() {
|
||||
return ICULocale.getAvailableLocales();
|
||||
return ICULocaleServiceProvider.getAvailableLocales();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import java.text.Collator;
|
||||
import java.text.spi.CollatorProvider;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.impl.javaspi.ICULocale;
|
||||
import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;
|
||||
import com.ibm.icu.impl.jdkadapter.CollatorICU;
|
||||
|
||||
public class CollatorProviderICU extends CollatorProvider {
|
||||
@ -18,13 +18,13 @@ public class CollatorProviderICU extends CollatorProvider {
|
||||
@Override
|
||||
public Collator getInstance(Locale locale) {
|
||||
com.ibm.icu.text.Collator icuCollator = com.ibm.icu.text.Collator.getInstance(
|
||||
ICULocale.canonicalize(locale));
|
||||
ICULocaleServiceProvider.canonicalize(locale));
|
||||
return CollatorICU.wrap(icuCollator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale[] getAvailableLocales() {
|
||||
return ICULocale.getAvailableLocales();
|
||||
return ICULocaleServiceProvider.getAvailableLocales();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import java.text.DateFormat;
|
||||
import java.text.spi.DateFormatProvider;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.impl.javaspi.ICULocale;
|
||||
import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;
|
||||
import com.ibm.icu.impl.jdkadapter.SimpleDateFormatICU;
|
||||
|
||||
public class DateFormatProviderICU extends DateFormatProvider {
|
||||
@ -34,12 +34,12 @@ public class DateFormatProviderICU extends DateFormatProvider {
|
||||
|
||||
@Override
|
||||
public Locale[] getAvailableLocales() {
|
||||
return ICULocale.getAvailableLocales();
|
||||
return ICULocaleServiceProvider.getAvailableLocales();
|
||||
}
|
||||
|
||||
private DateFormat getInstance(int dstyle, int tstyle, Locale locale) {
|
||||
com.ibm.icu.text.DateFormat icuDfmt;
|
||||
Locale actual = ICULocale.canonicalize(locale);
|
||||
Locale actual = ICULocaleServiceProvider.canonicalize(locale);
|
||||
if (dstyle == NONE) {
|
||||
icuDfmt = com.ibm.icu.text.DateFormat.getTimeInstance(tstyle, actual);
|
||||
} else if (tstyle == NONE) {
|
||||
@ -52,7 +52,7 @@ public class DateFormatProviderICU extends DateFormatProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
com.ibm.icu.text.DecimalFormatSymbols decfs = ICULocale.getDecimalFormatSymbolsForLocale(actual);
|
||||
com.ibm.icu.text.DecimalFormatSymbols decfs = ICULocaleServiceProvider.getDecimalFormatSymbolsForLocale(actual);
|
||||
if (decfs != null) {
|
||||
com.ibm.icu.text.NumberFormat icuNfmt = icuDfmt.getNumberFormat();
|
||||
if (icuNfmt instanceof com.ibm.icu.text.DecimalFormat) {
|
||||
|
@ -10,7 +10,7 @@ import java.text.DateFormatSymbols;
|
||||
import java.text.spi.DateFormatSymbolsProvider;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.impl.javaspi.ICULocale;
|
||||
import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;
|
||||
import com.ibm.icu.impl.jdkadapter.DateFormatSymbolsICU;
|
||||
|
||||
public class DateFormatSymbolsProviderICU extends DateFormatSymbolsProvider {
|
||||
@ -18,13 +18,13 @@ public class DateFormatSymbolsProviderICU extends DateFormatSymbolsProvider {
|
||||
@Override
|
||||
public DateFormatSymbols getInstance(Locale locale) {
|
||||
com.ibm.icu.text.DateFormatSymbols icuDfs = com.ibm.icu.text.DateFormatSymbols.getInstance(
|
||||
ICULocale.canonicalize(locale));
|
||||
ICULocaleServiceProvider.canonicalize(locale));
|
||||
return DateFormatSymbolsICU.wrap(icuDfs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale[] getAvailableLocales() {
|
||||
return ICULocale.getAvailableLocales();
|
||||
return ICULocaleServiceProvider.getAvailableLocales();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import java.text.DecimalFormatSymbols;
|
||||
import java.text.spi.DecimalFormatSymbolsProvider;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.impl.javaspi.ICULocale;
|
||||
import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;
|
||||
import com.ibm.icu.impl.jdkadapter.DecimalFormatSymbolsICU;
|
||||
|
||||
public class DecimalFormatSymbolsProviderICU extends
|
||||
@ -19,13 +19,13 @@ public class DecimalFormatSymbolsProviderICU extends
|
||||
@Override
|
||||
public DecimalFormatSymbols getInstance(Locale locale) {
|
||||
com.ibm.icu.text.DecimalFormatSymbols icuDecfs = com.ibm.icu.text.DecimalFormatSymbols.getInstance(
|
||||
ICULocale.canonicalize(locale));
|
||||
ICULocaleServiceProvider.canonicalize(locale));
|
||||
return DecimalFormatSymbolsICU.wrap(icuDecfs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale[] getAvailableLocales() {
|
||||
return ICULocale.getAvailableLocales();
|
||||
return ICULocaleServiceProvider.getAvailableLocales();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,8 +10,9 @@ import java.text.NumberFormat;
|
||||
import java.text.spi.NumberFormatProvider;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.impl.javaspi.ICULocale;
|
||||
import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;
|
||||
import com.ibm.icu.impl.jdkadapter.DecimalFormatICU;
|
||||
import com.ibm.icu.impl.jdkadapter.NumberFormatICU;
|
||||
|
||||
public class NumberFormatProviderICU extends NumberFormatProvider {
|
||||
|
||||
@ -42,12 +43,12 @@ public class NumberFormatProviderICU extends NumberFormatProvider {
|
||||
|
||||
@Override
|
||||
public Locale[] getAvailableLocales() {
|
||||
return ICULocale.getAvailableLocales();
|
||||
return ICULocaleServiceProvider.getAvailableLocales();
|
||||
}
|
||||
|
||||
private NumberFormat getInstance(int type, Locale locale) {
|
||||
com.ibm.icu.text.NumberFormat icuNfmt;
|
||||
Locale actual = ICULocale.canonicalize(locale);
|
||||
Locale actual = ICULocaleServiceProvider.canonicalize(locale);
|
||||
switch (type) {
|
||||
case NUMBER:
|
||||
icuNfmt = com.ibm.icu.text.NumberFormat.getNumberInstance(actual);
|
||||
@ -64,16 +65,24 @@ public class NumberFormatProviderICU extends NumberFormatProvider {
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(icuNfmt instanceof com.ibm.icu.text.DecimalFormat)) {
|
||||
// icuNfmt must be always DecimalFormat
|
||||
return null;
|
||||
}
|
||||
|
||||
com.ibm.icu.text.DecimalFormatSymbols decfs = ICULocale.getDecimalFormatSymbolsForLocale(actual);
|
||||
NumberFormat nf = null;
|
||||
if (ICULocaleServiceProvider.useDecimalFormat()) {
|
||||
nf = DecimalFormatICU.wrap((com.ibm.icu.text.DecimalFormat)icuNfmt);
|
||||
} else {
|
||||
nf = NumberFormatICU.wrap(icuNfmt);
|
||||
}
|
||||
|
||||
com.ibm.icu.text.DecimalFormatSymbols decfs = ICULocaleServiceProvider.getDecimalFormatSymbolsForLocale(actual);
|
||||
if (decfs != null) {
|
||||
((com.ibm.icu.text.DecimalFormat)icuNfmt).setDecimalFormatSymbols(decfs);
|
||||
}
|
||||
|
||||
return DecimalFormatICU.wrap((com.ibm.icu.text.DecimalFormat)icuNfmt);
|
||||
return nf;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ package com.ibm.icu.impl.javaspi.util;
|
||||
import java.util.Locale;
|
||||
import java.util.spi.CurrencyNameProvider;
|
||||
|
||||
import com.ibm.icu.impl.javaspi.ICULocale;
|
||||
import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;
|
||||
import com.ibm.icu.util.Currency;
|
||||
|
||||
public class CurrencyNameProviderICU extends CurrencyNameProvider {
|
||||
@ -17,7 +17,7 @@ public class CurrencyNameProviderICU extends CurrencyNameProvider {
|
||||
@Override
|
||||
public String getSymbol(String currencyCode, Locale locale) {
|
||||
Currency cur = Currency.getInstance(currencyCode);
|
||||
String sym = cur.getSymbol(ICULocale.canonicalize(locale));
|
||||
String sym = cur.getSymbol(ICULocaleServiceProvider.canonicalize(locale));
|
||||
if (sym.length() == 0 || sym.equals(currencyCode)) {
|
||||
return null;
|
||||
}
|
||||
@ -26,7 +26,7 @@ public class CurrencyNameProviderICU extends CurrencyNameProvider {
|
||||
|
||||
@Override
|
||||
public Locale[] getAvailableLocales() {
|
||||
return ICULocale.getAvailableLocales();
|
||||
return ICULocaleServiceProvider.getAvailableLocales();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ package com.ibm.icu.impl.javaspi.util;
|
||||
import java.util.Locale;
|
||||
import java.util.spi.LocaleNameProvider;
|
||||
|
||||
import com.ibm.icu.impl.javaspi.ICULocale;
|
||||
import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
public class LocaleNameProviderICU extends LocaleNameProvider {
|
||||
@ -17,7 +17,7 @@ public class LocaleNameProviderICU extends LocaleNameProvider {
|
||||
@Override
|
||||
public String getDisplayCountry(String countryCode, Locale locale) {
|
||||
String id = "und_" + countryCode;
|
||||
String disp = ULocale.getDisplayCountry(id, ULocale.forLocale(ICULocale.canonicalize(locale)));
|
||||
String disp = ULocale.getDisplayCountry(id, ULocale.forLocale(ICULocaleServiceProvider.canonicalize(locale)));
|
||||
if (disp.length() == 0 || disp.equals(countryCode)) {
|
||||
return null;
|
||||
}
|
||||
@ -26,7 +26,7 @@ public class LocaleNameProviderICU extends LocaleNameProvider {
|
||||
|
||||
@Override
|
||||
public String getDisplayLanguage(String languageCode, Locale locale) {
|
||||
String disp = ULocale.getDisplayLanguage(languageCode, ULocale.forLocale(ICULocale.canonicalize(locale)));
|
||||
String disp = ULocale.getDisplayLanguage(languageCode, ULocale.forLocale(ICULocaleServiceProvider.canonicalize(locale)));
|
||||
if (disp.length() == 0 || disp.equals(languageCode)) {
|
||||
return null;
|
||||
}
|
||||
@ -41,7 +41,7 @@ public class LocaleNameProviderICU extends LocaleNameProvider {
|
||||
|
||||
@Override
|
||||
public Locale[] getAvailableLocales() {
|
||||
return ICULocale.getAvailableLocales();
|
||||
return ICULocaleServiceProvider.getAvailableLocales();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ package com.ibm.icu.impl.javaspi.util;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.impl.javaspi.ICULocale;
|
||||
import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
|
||||
@ -17,7 +17,7 @@ public class TimeZoneNameProviderICU extends java.util.spi.TimeZoneNameProvider
|
||||
@Override
|
||||
public String getDisplayName(String ID, boolean daylight, int style, Locale locale) {
|
||||
TimeZone tz = TimeZone.getTimeZone(ID);
|
||||
Locale actualLocale = ICULocale.canonicalize(locale);
|
||||
Locale actualLocale = ICULocaleServiceProvider.canonicalize(locale);
|
||||
String disp = tz.getDisplayName(daylight, style, actualLocale);
|
||||
if (disp.length() == 0) {
|
||||
return null;
|
||||
@ -51,7 +51,7 @@ public class TimeZoneNameProviderICU extends java.util.spi.TimeZoneNameProvider
|
||||
|
||||
@Override
|
||||
public Locale[] getAvailableLocales() {
|
||||
return ICULocale.getAvailableLocales();
|
||||
return ICULocaleServiceProvider.getAvailableLocales();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user