/*
 *  Copyright 2011 Eric F. Savage, code@efsavage.com
 *
 *   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.
 */
/*
 *  Copyright 2011 Eric F. Savage, code@efsavage.com
 *
 *   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.ajah.util;

import java.util.Collection;

/**
 * Utilities for dealing with members of the Collections API.
 * 
 * @author <a href="http://efsavage.com">Eric F. Savage</a>, <a
 *         href="mailto:code@efsavage.com">code@efsavage.com</a>.
 */
public class CollectionUtils {

	/**
	 * Checks to see if a collection is null or empty.
	 * 
	 * @param collection
	 *            Collection to test, may be null.
	 * @return true if the collection is null or empty, otherwise false.
	 */
	public static boolean isEmpty(final Collection<?> collection) {
		return collection == null || collection.size() < 1;
	}

	/**
	 * Returns null if the supplied collection is empty.
	 * 
	 * @param collection
	 *            The collection to test.
	 * @return The original collection if not empty, otherwise null.
	 */
	public static <T, C extends Collection<T>> C nullIfEmpty(final C collection) {
		if (isEmpty(collection)) {
			return null;
		}
		return collection;
	}

}

@@ -1306,26 +1306,99 @@
 va.util.
-Collection
+ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.List;%0Aimport java.util.Map
 ;%0A%0A/**%0A 
@@ -2283,16 +2283,16 @@
 ll;%0A%09%09%7D%0A
-
 %09%09return
@@ -2308,10 +2308,939 @@
 on;%0A%09%7D%0A%0A
+%09/**%0A%09 * Removes the entries of a map that have null values.%0A%09 * %0A%09 * @param map%0A%09 *            The map to strip.%0A%09 * @return The map that was passed in.%0A%09 */%0A%09public static %3CK, V%3E Map%3CK, V%3E stripNulls(Map%3CK, V%3E map) %7B%0A%09%09List%3CObject%3E toRemove = null;%0A%09%09for (Object key : map.keySet()) %7B%0A%09%09%09if (map.get(key) == null) %7B%0A%09%09%09%09toRemove = safeAdd(toRemove, key);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09if (toRemove != null) %7B%0A%09%09%09for (Object key : toRemove) %7B%0A%09%09%09%09map.remove(key);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return map;%0A%09%7D%0A%0A%09/**%0A%09 * Shorthand method for adding an item to a list, and creating that list if%0A%09 * necessary.%0A%09 * %0A%09 * @param list%0A%09 *            The list to add to.%0A%09 * @param item%0A%09 *            The item to add.%0A%09 * @return The original list that was passed in, or a new list.%0A%09 */%0A%09private static %3CT%3E List%3CT%3E safeAdd(List%3CT%3E list, T item) %7B%0A%09%09List%3CT%3E retVal = list;%0A%09%09if (retVal == null) %7B%0A%09%09%09retVal = new ArrayList%3C%3E();%0A%09%09%7D%0A%09%09retVal.add(item);%0A%09%09return retVal;%0A%09%7D%0A%0A
 %7D%0A

Add stripNulls, safeAdd methods