ICU-20888 Hide or remove old list formatter methods
diff --git a/icu4c/source/i18n/measfmt.cpp b/icu4c/source/i18n/measfmt.cpp
index 08e6f66..ec8b47a 100644
--- a/icu4c/source/i18n/measfmt.cpp
+++ b/icu4c/source/i18n/measfmt.cpp
@@ -581,7 +581,10 @@
UMeasureFormatWidth w,
NumberFormat *nfToAdopt,
UErrorCode &status) {
- static const char *listStyles[] = {"unit", "unit-short", "unit-narrow"};
+ static const UListFormatterWidth listWidths[] = {
+ ULISTFMT_WIDTH_WIDE,
+ ULISTFMT_WIDTH_SHORT,
+ ULISTFMT_WIDTH_NARROW};
LocalPointer<NumberFormat> nf(nfToAdopt);
if (U_FAILURE(status)) {
return;
@@ -620,7 +623,8 @@
delete listFormatter;
listFormatter = ListFormatter::createInstance(
locale,
- listStyles[getRegularWidth(fWidth)],
+ ULISTFMT_TYPE_UNITS,
+ listWidths[getRegularWidth(fWidth)],
status);
}
diff --git a/icu4c/source/i18n/unicode/listformatter.h b/icu4c/source/i18n/unicode/listformatter.h
index 76a7289..d7ab1d2 100644
--- a/icu4c/source/i18n/unicode/listformatter.h
+++ b/icu4c/source/i18n/unicode/listformatter.h
@@ -197,22 +197,6 @@
*/
static ListFormatter* createInstance(
const Locale& locale, UListFormatterType type, UListFormatterWidth width, UErrorCode& errorCode);
-
-#ifndef U_HIDE_INTERNAL_API
- /**
- * Creates a ListFormatter appropriate for a locale and style.
- *
- * TODO(ICU-20888): Remove this in ICU 68.
- *
- * @param locale The locale.
- * @param style the style, either "standard", "or", "unit", "unit-narrow", or "unit-short"
- * @param errorCode ICU error code, set if no data available for the given locale.
- * @return A ListFormatter object created from internal data derived from
- * CLDR data.
- * @internal
- */
- static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
-#endif /* U_HIDE_INTERNAL_API */
/**
* Destructor.
@@ -273,6 +257,15 @@
#endif /* U_HIDE_INTERNAL_API */
private:
+
+ /**
+ * Creates a ListFormatter appropriate for a locale and style.
+ *
+ * @param locale The locale.
+ * @param style the style, either "standard", "or", "unit", "unit-narrow", or "unit-short"
+ */
+ static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
+
static void initializeHash(UErrorCode& errorCode);
static const ListFormatInternal* getListFormatInternal(const Locale& locale, const char *style, UErrorCode& errorCode);
struct ListPatternsSink;
diff --git a/icu4c/source/test/intltest/listformattertest.cpp b/icu4c/source/test/intltest/listformattertest.cpp
index 34536e6..8316422 100644
--- a/icu4c/source/test/intltest/listformattertest.cpp
+++ b/icu4c/source/test/intltest/listformattertest.cpp
@@ -45,7 +45,6 @@
TESTCASE_AUTO(TestFieldPositionIteratorWith3ItemsPatternShift);
TESTCASE_AUTO(TestFormattedValue);
TESTCASE_AUTO(TestDifferentStyles);
- TESTCASE_AUTO(TestBadStylesFail);
TESTCASE_AUTO(TestCreateStyled);
TESTCASE_AUTO(TestContextual);
TESTCASE_AUTO(TestNextPosition);
@@ -276,8 +275,11 @@
const char16_t *expectedFormatted,
const char* testName) {
IcuTestErrorCode errorCode(*this, testName);
- LocalPointer<ListFormatter> formatter(
- ListFormatter::createInstance(Locale("ur", "IN"), "unit-narrow", errorCode));
+ LocalPointer<ListFormatter> formatter(ListFormatter::createInstance(
+ Locale("ur", "IN"),
+ ULISTFMT_TYPE_UNITS,
+ ULISTFMT_WIDTH_NARROW,
+ errorCode));
if (U_FAILURE(errorCode)) {
dataerrln(
"ListFormatter::createInstance(Locale(\"ur\", \"IN\"), \"unit-narrow\", errorCode) failed in "
@@ -608,16 +610,22 @@
}
}
-void ListFormatterTest::DoTheRealListStyleTesting(Locale locale,
- UnicodeString items[], int itemCount,
- const char* style, const char* expected, IcuTestErrorCode status) {
+void ListFormatterTest::DoTheRealListStyleTesting(
+ Locale locale,
+ UnicodeString items[],
+ int itemCount,
+ UListFormatterType type,
+ UListFormatterWidth width,
+ const char* expected,
+ IcuTestErrorCode status) {
LocalPointer<ListFormatter> formatter(
- ListFormatter::createInstance(locale, style, status));
+ ListFormatter::createInstance(locale, type, width, status));
UnicodeString actualResult;
formatter->format(items, itemCount, actualResult, status);
- assertEquals(style, UnicodeString(expected), actualResult);
+ assertEquals(Int64ToUnicodeString(type) + "-" + Int64ToUnicodeString(width),
+ UnicodeString(expected), actualResult);
}
void ListFormatterTest::TestDifferentStyles() {
@@ -625,24 +633,11 @@
UnicodeString input[4] = { u"rouge", u"jaune", u"bleu", u"vert" };
IcuTestErrorCode status(*this, "TestDifferentStyles()");
- DoTheRealListStyleTesting(locale, input, 4, "standard", "rouge, jaune, bleu et vert", status);
- DoTheRealListStyleTesting(locale, input, 4, "or", "rouge, jaune, bleu ou vert", status);
- DoTheRealListStyleTesting(locale, input, 4, "unit", "rouge, jaune, bleu et vert", status);
- DoTheRealListStyleTesting(locale, input, 4, "unit-narrow", "rouge jaune bleu vert", status);
- DoTheRealListStyleTesting(locale, input, 4, "unit-short", "rouge, jaune, bleu et vert", status);
-}
-
-void ListFormatterTest::TestBadStylesFail() {
- Locale locale("fr");
- const char * badStyles[4] = { "", "duration", "duration-short", "something-clearly-wrong" };
- IcuTestErrorCode status(*this, "TestBadStylesFail()");
-
- for (int i = 0; i < 4; ++i) {
- LocalPointer<ListFormatter> formatter(ListFormatter::createInstance(locale, badStyles[i], status));
- if (!status.expectErrorAndReset(U_MISSING_RESOURCE_ERROR, "style \"%s\"", badStyles[i])) {
- // Do nothing, expectErrorAndReset already reports the error
- }
- }
+ DoTheRealListStyleTesting(locale, input, 4, ULISTFMT_TYPE_AND, ULISTFMT_WIDTH_WIDE, "rouge, jaune, bleu et vert", status);
+ DoTheRealListStyleTesting(locale, input, 4, ULISTFMT_TYPE_OR, ULISTFMT_WIDTH_WIDE, "rouge, jaune, bleu ou vert", status);
+ DoTheRealListStyleTesting(locale, input, 4, ULISTFMT_TYPE_UNITS, ULISTFMT_WIDTH_WIDE, "rouge, jaune, bleu et vert", status);
+ DoTheRealListStyleTesting(locale, input, 4, ULISTFMT_TYPE_UNITS, ULISTFMT_WIDTH_NARROW, "rouge jaune bleu vert", status);
+ DoTheRealListStyleTesting(locale, input, 4, ULISTFMT_TYPE_UNITS, ULISTFMT_WIDTH_SHORT, "rouge, jaune, bleu et vert", status);
}
void ListFormatterTest::TestCreateStyled() {
diff --git a/icu4c/source/test/intltest/listformattertest.h b/icu4c/source/test/intltest/listformattertest.h
index aeba483..0805e7b 100644
--- a/icu4c/source/test/intltest/listformattertest.h
+++ b/icu4c/source/test/intltest/listformattertest.h
@@ -52,7 +52,6 @@
void TestFieldPositionIteratorWith3ItemsPatternShift();
void TestFormattedValue();
void TestDifferentStyles();
- void TestBadStylesFail();
void TestCreateStyled();
void TestContextual();
void TestNextPosition();
@@ -111,8 +110,9 @@
void DoTheRealListStyleTesting(
Locale locale,
UnicodeString items[],
- int32_t itemCount,
- const char* style,
+ int itemCount,
+ UListFormatterType type,
+ UListFormatterWidth width,
const char* expected,
IcuTestErrorCode status);
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/ListFormatter.java b/icu4j/main/classes/core/src/com/ibm/icu/text/ListFormatter.java
index e746e8f..ebde045 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/text/ListFormatter.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/text/ListFormatter.java
@@ -51,66 +51,6 @@
private final PatternHandler patternHandler;
/**
- * Indicates the style of Listformatter
- * TODO(ICU-20888): Remove this in ICU 68.
- * @internal
- * @deprecated This API is ICU internal only.
- */
- @Deprecated
- public enum Style {
- /**
- * Standard, conjunction style.
- * @internal
- * @deprecated This API is ICU internal only.
- */
- @Deprecated
- STANDARD("standard"),
- /**
- * Disjunction style.
- * @internal
- * @deprecated This API is ICU internal only.
- */
- @Deprecated
- OR("or"),
- /**
- * Style for full units
- * @internal
- * @deprecated This API is ICU internal only.
- */
- @Deprecated
- UNIT("unit"),
- /**
- * Style for units in abbreviated form
- * @internal
- * @deprecated This API is ICU internal only.
- */
- @Deprecated
- UNIT_SHORT("unit-short"),
- /**
- * Style for units in narrow form
- * @internal
- * @deprecated This API is ICU internal only.
- */
- @Deprecated
- UNIT_NARROW("unit-narrow");
-
- private final String name;
-
- Style(String name) {
- this.name = name;
- }
- /**
- * @internal
- * @deprecated This API is ICU internal only.
- */
- @Deprecated
- public String getName() {
- return name;
- }
-
- }
-
- /**
* Type of meaning expressed by the list.
*
* @draft ICU 67
@@ -417,20 +357,6 @@
}
/**
- * Create a list formatter that is appropriate for a locale and style.
- *
- * @param locale the locale in question.
- * @param style the style
- * @return ListFormatter
- * @internal
- * @deprecated This API is ICU internal only.
- */
- @Deprecated
- public static ListFormatter getInstance(ULocale locale, Style style) {
- return cache.get(locale, style.getName());
- }
-
- /**
* Create a list formatter that is appropriate for a locale.
*
* @param locale
@@ -439,7 +365,7 @@
* @stable ICU 50
*/
public static ListFormatter getInstance(ULocale locale) {
- return getInstance(locale, Style.STANDARD);
+ return getInstance(locale, Type.AND, Width.WIDE);
}
/**
@@ -451,7 +377,7 @@
* @stable ICU 50
*/
public static ListFormatter getInstance(Locale locale) {
- return getInstance(ULocale.forLocale(locale), Style.STANDARD);
+ return getInstance(ULocale.forLocale(locale), Type.AND, Width.WIDE);
}
/**
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
index e0665f0..b9f072a 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
@@ -160,21 +160,21 @@
*
* @stable ICU 53
*/
- WIDE(ListFormatter.Style.UNIT, UnitWidth.FULL_NAME, UnitWidth.FULL_NAME),
+ WIDE(ListFormatter.Width.WIDE, UnitWidth.FULL_NAME, UnitWidth.FULL_NAME),
/**
* Abbreviate when possible.
*
* @stable ICU 53
*/
- SHORT(ListFormatter.Style.UNIT_SHORT, UnitWidth.SHORT, UnitWidth.ISO_CODE),
+ SHORT(ListFormatter.Width.SHORT, UnitWidth.SHORT, UnitWidth.ISO_CODE),
/**
* Brief. Use only a symbol for the unit when possible.
*
* @stable ICU 53
*/
- NARROW(ListFormatter.Style.UNIT_NARROW, UnitWidth.NARROW, UnitWidth.SHORT),
+ NARROW(ListFormatter.Width.NARROW, UnitWidth.NARROW, UnitWidth.SHORT),
/**
* Identical to NARROW except when formatMeasures is called with an hour and minute; minute and
@@ -183,7 +183,7 @@
*
* @stable ICU 53
*/
- NUMERIC(ListFormatter.Style.UNIT_NARROW, UnitWidth.NARROW, UnitWidth.SHORT),
+ NUMERIC(ListFormatter.Width.NARROW, UnitWidth.NARROW, UnitWidth.SHORT),
/**
* The default format width for getCurrencyFormat(), which is to show the symbol for currency
@@ -193,9 +193,9 @@
* @deprecated ICU 61 This API is ICU internal only.
*/
@Deprecated
- DEFAULT_CURRENCY(ListFormatter.Style.UNIT, UnitWidth.FULL_NAME, UnitWidth.SHORT);
+ DEFAULT_CURRENCY(ListFormatter.Width.SHORT, UnitWidth.FULL_NAME, UnitWidth.SHORT);
- private final ListFormatter.Style listFormatterStyle;
+ final ListFormatter.Width listWidth;
/**
* The {@link UnitWidth} (used for newer NumberFormatter API) that corresponds to this
@@ -209,15 +209,14 @@
*/
final UnitWidth currencyWidth;
- private FormatWidth(ListFormatter.Style style, UnitWidth unitWidth, UnitWidth currencyWidth) {
- this.listFormatterStyle = style;
+ private FormatWidth(
+ ListFormatter.Width listWidth,
+ UnitWidth unitWidth,
+ UnitWidth currencyWidth) {
+ this.listWidth = listWidth;
this.unitWidth = unitWidth;
this.currencyWidth = currencyWidth;
}
-
- ListFormatter.Style getListFormatterStyle() {
- return listFormatterStyle;
- }
}
/**
@@ -457,7 +456,8 @@
}
ListFormatter listFormatter = ListFormatter.getInstance(getLocale(),
- formatWidth.getListFormatterStyle());
+ ListFormatter.Type.UNITS,
+ formatWidth.listWidth);
if (fieldPosition != DontCareFieldPosition.INSTANCE) {
formatMeasuresSlowTrack(listFormatter, appendTo, fieldPosition, measures);
return;
diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/ListFormatterTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/ListFormatterTest.java
index 9407bd5..6bfa555 100644
--- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/ListFormatterTest.java
+++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/ListFormatterTest.java
@@ -193,9 +193,9 @@
}
- void DoTheRealListStyleTesting(ULocale locale, String items[], ListFormatter.Style style, String expected) {
- ListFormatter listFormatter = ListFormatter.getInstance(locale, style);
- assertEquals("Style \"" + style + "\"", expected, listFormatter.format((Object[])items));
+ void DoTheRealListStyleTesting(ULocale locale, String items[], ListFormatter.Type type, ListFormatter.Width width, String expected) {
+ ListFormatter listFormatter = ListFormatter.getInstance(locale, type, width);
+ assertEquals("Style \"" + type + "/" + width + "\"", expected, listFormatter.format((Object[])items));
}
@Test
@@ -203,11 +203,11 @@
ULocale locale = ULocale.FRENCH;
String[] input = { "rouge", "jaune", "bleu", "vert" };
- DoTheRealListStyleTesting(locale, input, ListFormatter.Style.STANDARD, "rouge, jaune, bleu et vert");
- DoTheRealListStyleTesting(locale, input, ListFormatter.Style.OR, "rouge, jaune, bleu ou vert");
- DoTheRealListStyleTesting(locale, input, ListFormatter.Style.UNIT, "rouge, jaune, bleu et vert");
- DoTheRealListStyleTesting(locale, input, ListFormatter.Style.UNIT_NARROW, "rouge jaune bleu vert");
- DoTheRealListStyleTesting(locale, input, ListFormatter.Style.UNIT_SHORT, "rouge, jaune, bleu et vert");
+ DoTheRealListStyleTesting(locale, input, ListFormatter.Type.AND, ListFormatter.Width.WIDE, "rouge, jaune, bleu et vert");
+ DoTheRealListStyleTesting(locale, input, ListFormatter.Type.OR, ListFormatter.Width.WIDE, "rouge, jaune, bleu ou vert");
+ DoTheRealListStyleTesting(locale, input, ListFormatter.Type.UNITS, ListFormatter.Width.WIDE, "rouge, jaune, bleu et vert");
+ DoTheRealListStyleTesting(locale, input, ListFormatter.Type.UNITS, ListFormatter.Width.NARROW, "rouge jaune bleu vert");
+ DoTheRealListStyleTesting(locale, input, ListFormatter.Type.UNITS, ListFormatter.Width.SHORT, "rouge, jaune, bleu et vert");
}
private boolean isDefaultLocaleEnglishLike() {