/*******************************************************************************
 * Copyright 2012-present Pixate, Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.pixate.freestyle.util;

import java.util.Collection;

public class CollectionUtil {

	/**
	 * Returns a String representation of the given collection by separating the
	 * elements with the given separator.
	 * 
	 * @param collection
	 * @param separator
	 * @return
	 */
	public static String toString(Collection<String> collection,
			String separator) {
		if (collection == null || collection.isEmpty()) {
			return "";
		}
		StringBuilder builder = new StringBuilder();
		int count = collection.size();
		for (String str : collection) {
			builder.append(str);
			if (--count > 0) {
				builder.append(separator);
			}
		}
		return builder.toString();
	}

	/**
	 * Returns <code>true</code> if the given collection is <code>null</code> or
	 * empty.
	 * 
	 * @param collection
	 * @return <code>true</code> if the given collection is <code>null</code> or
	 *         empty; <code>false</code> otherwise.
	 */
	public static boolean isEmpty(Collection<?> collection) {
		return collection == null || collection.isEmpty();
	}
}

@@ -851,22 +851,28 @@
 Util %7B%0A%0A
-%09/**%0A%09
+    /**%0A    
  * Retur
@@ -940,17 +940,20 @@
 ing the%0A
-%09
+    
  * eleme
@@ -982,22 +982,28 @@
 arator.%0A
-%09 * %0A%09
+     * %0A    
  * @para
@@ -1011,25 +1011,28 @@
  collection%0A
-%09
+    
  * @param se
@@ -1039,17 +1039,20 @@
 parator%0A
-%09
+    
  * @retu
@@ -1054,22 +1054,28 @@
 @return%0A
-%09 */%0A%09
+     */%0A    
 public s
@@ -1107,22 +1107,32 @@
 lection%3C
-String
+? extends Object
 %3E collec
@@ -1136,20 +1136,17 @@
 lection,
-%0A%09%09%09
+ 
 String s
@@ -1157,18 +1157,24 @@
 ator) %7B%0A
-%09%09
+        
 if (coll
@@ -1219,28 +1219,49 @@
 ) %7B%0A
-%09%09%09return %22%22;%0A%09%09%7D%0A%09%09
+            return %22%22;%0A        %7D%0A        
 Stri
@@ -1301,18 +1301,24 @@
 lder();%0A
-%09%09
+        
 int coun
@@ -1344,25 +1344,31 @@
 ();%0A
-%09%09for (String str
+        for (Object obj
  : c
@@ -1380,19 +1380,28 @@
 tion) %7B%0A
-%09%09%09
+            
 builder.
@@ -1411,17 +1411,26 @@
 end(
-str);%0A%09%09%09
+obj);%0A            
 if (
@@ -1448,12 +1448,24 @@
 ) %7B%0A
-%09%09%09%09
+                
 buil
@@ -1491,19 +1491,40 @@
 r);%0A
-%09%09%09%7D%0A%09%09%7D%0A%09%09
+            %7D%0A        %7D%0A        
 retu
@@ -1550,18 +1550,27 @@
 ();%0A
-%09%7D%0A%0A%09/**%0A%09
+    %7D%0A%0A    /**%0A    
  * R
@@ -1642,17 +1642,20 @@
 ode%3E or%0A
-%09
+    
  * empty
@@ -1660,14 +1660,20 @@
 ty.%0A
-%09 * %0A%09
+     * %0A    
  * @
@@ -1689,17 +1689,20 @@
 lection%0A
-%09
+    
  * @retu
@@ -1770,17 +1770,20 @@
 ode%3E or%0A
-%09
+    
  *      
@@ -1826,14 +1826,20 @@
 se.%0A
-%09 */%0A%09
+     */%0A    
 publ
@@ -1896,10 +1896,16 @@
 ) %7B%0A
-%09%09
+        
 retu
@@ -1955,9 +1955,12 @@
 ();%0A
-%09
+    
 %7D%0A%7D%0A

Change a toString utility method to accept any type of collection.