From 12b26e30733596e44de7c38c65e082eb6903c864 Mon Sep 17 00:00:00 2001 From: Travis Keep Date: Mon, 22 Jul 2013 22:18:54 +0000 Subject: [PATCH] ICU-10067 Implement feedback from API proposal. X-SVN-Rev: 33955 --- .../core/src/com/ibm/icu/text/ListFormatter.java | 13 +++++++++---- .../ibm/icu/dev/test/format/ListFormatterTest.java | 13 +++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) 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 c1bc9c75016..ed31e418e4f 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 @@ -149,11 +149,16 @@ final public class ListFormatter { /** * Returns the pattern to use for a particular item count. * @param count the item count. - * @return the pattern with {0}, {1}, {2}, etc. - * @internal - * @deprecated This API is ICU internal only. + * @return the pattern with {0}, {1}, {2}, etc. For English, + * getPatternForNumItems(3) == "{0}, {1}, and {2}" + * @throws IllegalArgumentException when count is 0 or negative. + * @draft ICU 52 + * @provisional This API might change or be removed in a future release. */ - public String createPatternForNumItems(int count) { + public String getPatternForNumItems(int count) { + if (count <= 0) { + throw new IllegalArgumentException("count must be > 0"); + } ArrayList list = new ArrayList(); for (int i = 0; i < count; i++) { list.add(String.format("{%d}", i)); 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 dd3418eef2c..099f35c0e6c 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 @@ -117,8 +117,17 @@ public class ListFormatterTest extends TestFmwk { assertEquals( "createPatternForNumItems", "{0}, {1}, and {2}", - listFormatter.createPatternForNumItems(3)); - + listFormatter.getPatternForNumItems(3)); + } + + public void TestGetPatternForNumItemsException() { + ListFormatter listFormatter = ListFormatter.getInstance(ULocale.ENGLISH); + try { + listFormatter.getPatternForNumItems(0); + fail("IllegalArgumentException expected."); + } catch (IllegalArgumentException expected) { + // expected. + } } public void TestGetLocale() { -- 2.40.0