Skip to content

Commit

Permalink
Fixed bug in c.u.Util#join() methods where if the first value was emp…
Browse files Browse the repository at this point in the history
…ty, the delimiter was not properly applied.
  • Loading branch information
cwensel committed Aug 21, 2009
1 parent 64307c3 commit 0a853ea
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Expand Up @@ -2,7 +2,9 @@ Cascading Change Log

unreleased

Fixed issue in c.t.h.FSDigestOutputStream where seek() now must be implemented with modern versions of Hadoop.
Fixed bug in c.u.Util#join() methods where if the first value was empty, the delimiter was not properly applied.

Fixed issue in c.t.h.FSDigestOutputStream where seek() now must be implemented with modern versions of Hadoop.

1.0.14

Expand Down
53 changes: 40 additions & 13 deletions src/core/cascading/util/Util.java
Expand Up @@ -21,6 +21,23 @@

package cascading.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import cascading.flow.FlowElement;
import cascading.flow.FlowException;
import cascading.flow.Scope;
Expand All @@ -31,17 +48,13 @@
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.mapred.JobConf;
import org.apache.log4j.Logger;
import org.jgrapht.ext.*;
import org.jgrapht.ext.DOTExporter;
import org.jgrapht.ext.EdgeNameProvider;
import org.jgrapht.ext.IntegerNameProvider;
import org.jgrapht.ext.MatrixExporter;
import org.jgrapht.ext.VertexNameProvider;
import org.jgrapht.graph.SimpleDirectedGraph;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/** Class Util provides reusable operations. */
public class Util
{
Expand Down Expand Up @@ -98,16 +111,19 @@ public static Object deserializeBase64( String string ) throws IOException
public static String join( int[] list, String delim )
{
StringBuffer buffer = new StringBuffer();
int count = 0;

for( Object s : list )
{
if( s == null )
continue;

if( buffer.length() != 0 )
if( count != 0 )
buffer.append( delim );

buffer.append( s );

count++;
}

return buffer.toString();
Expand All @@ -128,16 +144,19 @@ public static String join( String delim, String... strings )
public static String join( Object[] list, String delim )
{
StringBuffer buffer = new StringBuffer();
int count = 0;

for( Object s : list )
{
if( s == null )
continue;

if( buffer.length() != 0 )
if( count != 0 )
buffer.append( delim );

buffer.append( s );

count++;
}

return buffer.toString();
Expand Down Expand Up @@ -180,12 +199,16 @@ public static String join( Collection collection, String delim )
*/
public static void join( StringBuffer buffer, Collection collection, String delim )
{
int count = 0;

for( Object s : collection )
{
if( buffer.length() != 0 )
if( count != 0 )
buffer.append( delim );

buffer.append( s );

count++;
}
}

Expand All @@ -200,14 +223,18 @@ public static String print( Collection collection, String delim )

public static void print( StringBuffer buffer, Collection collection, String delim )
{
int count = 0;

for( Object s : collection )
{
if( buffer.length() != 0 )
if( count != 0 )
buffer.append( delim );

buffer.append( "[" );
buffer.append( s );
buffer.append( "]" );

count++;
}
}

Expand Down

0 comments on commit 0a853ea

Please sign in to comment.