hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1143624 - in /hadoop/common/trunk/common: CHANGES.txt src/java/org/apache/hadoop/util/StringUtils.java
Date Thu, 07 Jul 2011 01:31:59 GMT
Author: mattf
Date: Thu Jul  7 01:31:58 2011
New Revision: 1143624

URL: http://svn.apache.org/viewvc?rev=1143624&view=rev
Log:
HADOOP-7451. Generalize StringUtils#join. Contributed by Chris Douglas.

Modified:
    hadoop/common/trunk/common/CHANGES.txt   (contents, props changed)
    hadoop/common/trunk/common/src/java/org/apache/hadoop/util/StringUtils.java

Modified: hadoop/common/trunk/common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/CHANGES.txt?rev=1143624&r1=1143623&r2=1143624&view=diff
==============================================================================
--- hadoop/common/trunk/common/CHANGES.txt (original)
+++ hadoop/common/trunk/common/CHANGES.txt Thu Jul  7 01:31:58 2011
@@ -239,6 +239,8 @@ Trunk (unreleased changes)
 
     HADOOP-7429. Add another IOUtils#copyBytes method. (eli)
 
+    HADOOP-7451. Generalize StringUtils#join. (Chris Douglas via mattf)
+
   OPTIMIZATIONS
   
     HADOOP-7333. Performance improvement in PureJavaCrc32. (Eric Caspole

Propchange: hadoop/common/trunk/common/CHANGES.txt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jul  7 01:31:58 2011
@@ -1,4 +1,4 @@
-/hadoop/common/branches/yahoo-merge/CHANGES.txt:1079157,1079163-1079164
+/hadoop/common/branches/yahoo-merge/CHANGES.txt:1079157,1079163-1079164,1079167
 /hadoop/core/branches/branch-0.18/CHANGES.txt:727226
 /hadoop/core/branches/branch-0.19/CHANGES.txt:713112
 /hadoop/core/trunk/CHANGES.txt:776175-785643,785929-786278

Modified: hadoop/common/trunk/common/src/java/org/apache/hadoop/util/StringUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/java/org/apache/hadoop/util/StringUtils.java?rev=1143624&r1=1143623&r2=1143624&view=diff
==============================================================================
--- hadoop/common/trunk/common/src/java/org/apache/hadoop/util/StringUtils.java (original)
+++ hadoop/common/trunk/common/src/java/org/apache/hadoop/util/StringUtils.java Thu Jul  7
01:31:58 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;
@@ -741,16 +742,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