sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1627271 - in /sis/branches/JDK8/core/sis-utility/src: main/java/org/apache/sis/util/CharSequences.java test/java/org/apache/sis/util/CharSequencesTest.java
Date Wed, 24 Sep 2014 10:33:39 GMT
Author: desruisseaux
Date: Wed Sep 24 10:33:38 2014
New Revision: 1627271

URL: http://svn.apache.org/r1627271
Log:
Deprecate CharSequences.toString(...) since as of JDK8 its functionality is provided by java.util.StringJoiner.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java?rev=1627271&r1=1627270&r2=1627271&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
[UTF-8] Wed Sep 24 10:33:38 2014
@@ -18,6 +18,7 @@ package org.apache.sis.util;
 
 import java.util.Arrays;
 import java.nio.CharBuffer;
+import java.util.StringJoiner;
 
 import static java.lang.Character.*;
 
@@ -75,7 +76,6 @@ import static java.lang.Character.*;
  * @module
  *
  * @see StringBuilders
- * @see java.util.Arrays#toString(Object[])
  */
 public final class CharSequences extends Static {
     /**
@@ -934,27 +934,27 @@ search:     for (; fromIndex <= toIndex;
      * @param  separator  The element separator, which is usually {@code ", "}.
      * @return The (typically) comma-separated list, or {@code null} if the given {@code
collection}
      *         was null or contains only null elements.
+     *
+     * @see java.util.StringJoiner
+     * @see java.util.Arrays#toString(Object[])
+     *
+     * @deprecated As of JDK8, use {@link StringJoiner} instead.
      */
+    @Deprecated
     public static String toString(final Iterable<?> collection, final String separator)
{
         ArgumentChecks.ensureNonNull("separator", separator);
         String list = null;
         if (collection != null) {
-            StringBuilder buffer = null;
+            StringJoiner buffer = null;
             for (final Object element : collection) {
                 if (element != null) {
                     if (list == null) {
                         list = element.toString();
                     } else {
                         if (buffer == null) {
-                            buffer = new StringBuilder(list);
-                        }
-                        buffer.append(separator);
-                        if (element instanceof CharSequence) {
-                            // StringBuilder has numerous optimizations for this case.
-                            buffer.append((CharSequence) element);
-                        } else {
-                            buffer.append(element);
+                            buffer = new StringJoiner(separator).add(list);
                         }
+                        buffer.add(element.toString());
                     }
                 }
             }

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java?rev=1627271&r1=1627270&r2=1627271&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
[UTF-8] Wed Sep 24 10:33:38 2014
@@ -235,6 +235,7 @@ public final strictfp class CharSequence
      * Tests the {@link CharSequences#toString(Iterable, String)} method.
      */
     @Test
+    @SuppressWarnings("deprecation")
     public void testToString() {
         assertEquals("4, 8, 12, 9", CharSequences.toString(Arrays.asList(4, 8, 12, 9), ",
"));
         assertSame  ("singleton",   CharSequences.toString(Arrays.asList("singleton"), ",
"));



Mime
View raw message