dlr         01/08/24 14:24:52

  Modified:    util/src/java/org/apache/commons/util StringUtils.java
  Log:
  Replaced Iterator implode() overload with more descriptively named and
  accurately documented join() version.
  
  Revision  Changes    Path
  1.5       +27 -9     
jakarta-commons-sandbox/util/src/java/org/apache/commons/util/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/util/src/java/org/apache/commons/util/StringUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -u -r1.4 -r1.5
  --- StringUtils.java  2001/08/24 21:12:28     1.4
  +++ StringUtils.java  2001/08/24 21:24:52     1.5
  @@ -76,7 +76,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jon S. Stevens</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Greg Coladonato</a>
  - * @version $Id: StringUtils.java,v 1.4 2001/08/24 21:12:28 dlr Exp $
  + * @version $Id: StringUtils.java,v 1.5 2001/08/24 21:24:52 dlr Exp $
    */
   public class StringUtils
   {
  @@ -289,6 +289,30 @@
       }
   
       /**
  +     * Merges the list of <code>Object</code> intances supplied by an
  +     * <code>Iterator</code> into a single piece text.  No delimiter
  +     * is added before or after the list.
  +     *
  +     * @param iterator The list provider.
  +     * @param separator String delimiter to separate list elements
  +     * with.
  +     * @return Text delimited list as a <code>String</code>.
  +     */
  +    public static String join(Iterator iterator, String separator)
  +    {
  +        StringBuffer csv = new StringBuffer();
  +        while (iterator.hasNext())
  +        {
  +            csv.append(iterator.next());
  +            if (iterator.hasNext())
  +            {
  +                csv.append(separator);
  +            }
  +        }
  +        return csv.toString();
  +    }
  +
  +    /**
        * Takes a block of text which might have long lines in it and wraps
        * the long lines based on the supplied wrapColumn parameter. It was
        * initially implemented for use by VelocityEmail. If there are tabs
  @@ -426,16 +450,10 @@
        * @param sep String delimiter
        *
        * @return String delimited list of the passed in object's toStrings.
  +     * @deprecated Use join(Iterator, String) instead.
        */
       static public String implode(Iterator iterator, String sep) {
  -        StringBuffer buffer = new StringBuffer();
  -        while(iterator.hasNext()) {
  -            buffer.append(iterator.next());
  -            if(iterator.hasNext()) {
  -                buffer.append(sep);
  -            }
  -        }
  -        return buffer.toString();
  +        return join(iterator, sep);
       }
       
       /**
  
  
  

Reply via email to