Index: icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java |
=================================================================== |
--- icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java (revision 40286) |
+++ icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java (working copy) |
@@ -53,7 +53,7 @@ |
* @stable ICU 2.0 |
*/ |
public DecimalFormatSymbols() { |
- initialize(ULocale.getDefault(Category.FORMAT)); |
+ this(ULocale.getDefault(Category.FORMAT)); |
} |
/** |
@@ -62,7 +62,7 @@ |
* @stable ICU 2.0 |
*/ |
public DecimalFormatSymbols(Locale locale) { |
- initialize(ULocale.forLocale(locale)); |
+ this(ULocale.forLocale(locale)); |
} |
/** |
@@ -71,9 +71,17 @@ |
* @stable ICU 3.2 |
*/ |
public DecimalFormatSymbols(ULocale locale) { |
- initialize(locale); |
+ initialize(locale, null); |
} |
+ private DecimalFormatSymbols(Locale locale, NumberingSystem ns) { |
+ this(ULocale.forLocale(locale), ns); |
+ } |
+ |
+ private DecimalFormatSymbols(ULocale locale, NumberingSystem ns) { |
+ initialize(locale, ns); |
+ } |
+ |
/** |
* Returns a DecimalFormatSymbols instance for the default locale. |
* |
@@ -124,6 +132,46 @@ |
} |
/** |
+ * {@icu} Returns a DecimalFormatSymbols instance for the given locale with digits and symbols |
+ * corresponding to the given {@link NumberingSystem}. |
+ * |
+ * <p>This method behaves equivalently to {@link #getInstance} called with a locale having a |
+ * "numbers=xxxx" keyword specifying the numbering system by name. |
+ * |
+ * <p>In this method, the NumberingSystem argument will be used even if the locale has its own |
+ * "numbers=xxxx" keyword. |
+ * |
+ * @param locale the locale. |
+ * @param ns the numbering system. |
+ * @return A DecimalFormatSymbols instance. |
+ * @provisional This API might change or be removed in a future release. |
+ * @draft ICU 60 |
+ */ |
+ public static DecimalFormatSymbols forNumberingSystem(Locale locale, NumberingSystem ns) { |
+ return new DecimalFormatSymbols(locale, ns); |
+ } |
+ |
+ /** |
+ * {@icu} Returns a DecimalFormatSymbols instance for the given locale with digits and symbols |
+ * corresponding to the given {@link NumberingSystem}. |
+ * |
+ * <p>This method behaves equivalently to {@link #getInstance} called with a locale having a |
+ * "numbers=xxxx" keyword specifying the numbering system by name. |
+ * |
+ * <p>In this method, the NumberingSystem argument will be used even if the locale has its own |
+ * "numbers=xxxx" keyword. |
+ * |
+ * @param locale the locale. |
+ * @param ns the numbering system. |
+ * @return A DecimalFormatSymbols instance. |
+ * @provisional This API might change or be removed in a future release. |
+ * @draft ICU 60 |
+ */ |
+ public static DecimalFormatSymbols forNumberingSystem(ULocale locale, NumberingSystem ns) { |
+ return new DecimalFormatSymbols(locale, ns); |
+ } |
+ |
+ /** |
* Returns an array of all locales for which the <code>getInstance</code> methods of |
* this class can return localized instances. |
* |
@@ -1289,10 +1337,16 @@ |
/** |
* Initializes the symbols from the locale data. |
*/ |
- private void initialize( ULocale locale ) { |
+ private void initialize(ULocale locale, NumberingSystem ns) { |
this.requestedLocale = locale.toLocale(); |
this.ulocale = locale; |
- CacheData data = cachedLocaleData.getInstance(locale, null /* unused */); |
+ |
+ // TODO: The cache requires a single key, so we just save the NumberingSystem into the |
+ // locale string. NumberingSystem is then decoded again in the loadData() method. It would |
+ // be more efficient if we didn't have to serialize and deserialize the NumberingSystem. |
+ ULocale keyLocale = (ns == null) ? locale : locale.setKeywordValue("numbers", ns.getName()); |
+ CacheData data = cachedLocaleData.getInstance(keyLocale, null /* unused */); |
+ |
setLocale(data.validLocale, data.validLocale); |
setDigitStrings(data.digits); |
String[] numberElements = data.numberElements; |