]> granicus.if.org Git - icu/commitdiff
ICU-10063 Change ListFormatter.format() method to take a Collection<?> instead of...
authorTravis Keep <keep94@gmail.com>
Fri, 29 Mar 2013 22:23:24 +0000 (22:23 +0000)
committerTravis Keep <keep94@gmail.com>
Fri, 29 Mar 2013 22:23:24 +0000 (22:23 +0000)
X-SVN-Rev: 33480

icu4j/main/classes/core/src/com/ibm/icu/text/ListFormatter.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/ListFormatterTest.java

index d7e01e15560f054ebc4f4b7be070fa9bcd752684..d5b753a0103e53c03ab438f74cc3f7c36570b3a8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 2012-2012, Google, International Business Machines Corporation and
+ * Copyright (C) 2012-2013, Google, International Business Machines Corporation and
  * others. All Rights Reserved.
  *******************************************************************************
  */
@@ -117,11 +117,11 @@ final public class ListFormatter {
      * @draft ICU 50
      * @provisional This API might change or be removed in a future release.
      */
-    public String format(Collection<Object> items) {
+    public String format(Collection<?> items) {
         // TODO optimize this for the common case that the patterns are all of the
         // form {0}<sometext>{1}.
         // We avoid MessageFormat, because there is no "sub" formatting.
-        Iterator<Object> it = items.iterator();
+        Iterator<?> it = items.iterator();
         int count = items.size();
         switch (count) {
         case 0:
index 2bdb1df6012083785b803e4ca34f290c5f2218d0..803df536f2baa270e24f079c3013b7a183088354 100644 (file)
@@ -1,11 +1,12 @@
 /*
  *******************************************************************************
- * Copyright (C) 2012-2012, Google, International Business Machines Corporation and
+ * Copyright (C) 2012-2013, Google, International Business Machines Corporation and
  * others. All Rights Reserved.
  *******************************************************************************
  */
 package com.ibm.icu.dev.test.format;
 
+import java.util.ArrayList;
 import java.util.Locale;
 
 import com.ibm.icu.dev.test.TestFmwk;
@@ -101,6 +102,15 @@ public class ListFormatterTest extends TestFmwk {
         assertEquals("4", strings[4], listFormat.format("A", "B", "C", "D"));
         assertEquals("5", strings[5], listFormat.format("A", "B", "C", "D", "E"));
     }
+    
+    public void TestFromList() {
+        ListFormatter listFormatter = ListFormatter.getInstance(ULocale.ENGLISH);
+        ArrayList<String> list = new ArrayList<String>();
+        list.add("A");
+        list.add("B");
+        list.add("C");
+        assertEquals("list", "A, B, and C", listFormatter.format(list));
+    }
 
     private boolean isDefaultLocaleEnglishLike() {
         ULocale defaultLocale = ULocale.getDefault(ULocale.Category.FORMAT);