hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r1079167 - /hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/util/StringUtils.java
Date Tue, 08 Mar 2011 04:41:24 GMT
Author: omalley
Date: Tue Mar  8 04:41:23 2011
New Revision: 1079167

URL: http://svn.apache.org/viewvc?rev=1079167&view=rev
Log:
commit 3d4224cc2171a7bbf82048f09a1148aec3dda50d
Author: Mahadev Konar <mahadev@yahoo-inc.com>
Date:   Fri Feb 4 12:51:17 2011 -0800

      Generalize StringUtils::join
     (Chris Douglas)
    
    +++ b/YAHOO-CHANGES.txt
    +     Generalize StringUtils::join (Chris Douglas)

Modified:
    hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/util/StringUtils.java

Modified: hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/util/StringUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/util/StringUtils.java?rev=1079167&r1=1079166&r2=1079167&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/util/StringUtils.java (original)
+++ hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/util/StringUtils.java Tue
Mar  8 04:41:23 2011
@@ -29,6 +29,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.StringTokenizer;
@@ -740,16 +741,15 @@ public class StringUtils {
    * @param separator Separator to join with.
    * @param strings Strings to join.
    */
-  public static String join(CharSequence separator, Iterable<String> strings) {
-    StringBuilder sb = new StringBuilder();
-    boolean first = true;
-    for (String s : strings) {
-      if (first) {
-        first = false;
-      } else {
-        sb.append(separator);
-      }
-      sb.append(s);
+  public static String join(CharSequence separator, Iterable<?> strings) {
+    Iterator<?> i = strings.iterator();
+    if (!i.hasNext()) {
+      return "";
+    }
+    StringBuilder sb = new StringBuilder(i.next().toString());
+    while (i.hasNext()) {
+      sb.append(separator);
+      sb.append(i.next().toString());
     }
     return sb.toString();
   }



Mime
View raw message