LocalStringUtils.java [src/m/utils] Revision: default  Date:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package m.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.apache.commons.lang3.StringUtils;

/**
 *
 * @author ktraff
 */
public class LocalStringUtils {

    /**
     * Needed to override the default StringUtils implementation of this method
     * because it doesn't properly exclude empty values from being joined.
     * @param collection
     * @param separator
     * @return 
     */
    public static String join(Collection collection, String separator) {
        ArrayList<Object> toJoin = new ArrayList<>();
        StringBuilder ret = new StringBuilder();
        // Remove empty strings.
        for (Object obj : collection) {
            if (obj.toString().length() > 0) {
                toJoin.add(obj);
            }
        }
        
        String joined = StringUtils.join(toJoin, separator);
        return joined;
    }
    
    public static String join(Object [] arr, String separator) {
        return join(Arrays.asList(arr), separator);
    }
    
}