Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3789)

Unified Diff: icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java

Issue 323340043: ticket:13285 Adding NumberingSystem constructor methods to DecimalFormatSymbols (J and C). (Closed) Base URL: svn+icussh://source.icu-project.org/repos/icu/trunk/
Patch Set: Second round of feedback Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b