package javaslang.collection;

import java.util.Collection;
import java.util.List;

import javaslang.option.None;
import javaslang.option.Option;
import javaslang.option.Some;

/**
 * Additions to {@link java.util.Collections}.
 */
public final class Collections {

	private Collections() {
		throw new AssertionError(Collections.class.getName() + " cannot be instantiated.");
	}

	/**
	 * Tests if given Collection is null or empty.
	 * 
	 * @param c A Collection
	 * @return true, if c is null or empty, false otherwise
	 */
	public static boolean isNullOrEmpty(Collection<?> c) {
		return c == null || c.size() == 0;
	}

	/**
	 * Returns the last element of the given list.
	 * 
	 * @param <T> type of list elements
	 * @param list A List, may be null or empty.
	 * @return The last element of the list or null, if the list is null, empty or the last
	 *         element is null.
	 */
	public static <T> Option<T> lastElement(List<T> list) {
		return isNullOrEmpty(list) ? None.<T>instance() : new Some<T>(list.get(list.size() - 1));
	}
	
}

@@ -24,16 +24,60 @@
 ction;%0A%0A
+import static javaslang.lang.Lang.require;%0A%0A
 import j
@@ -412,24 +412,529 @@
 iated.%22);%0A%09%7D
+%0A%09%0A%09/**%0A%09 * Adds an element to a given collection and returns the element.%0A%09 * The element is returned, even if %7B@code c.add(elem)%7D returns false.%0A%09 * %0A%09 * @param %3CT%3E the component type of the collection%0A%09 * @param %3CE%3E the element type, extends T%0A%09 * @param c A Collection of component type T%0A%09 * @param elem An element of type T%0A%09 * @return The given element%0A%09 */%0A%09public static %3CT,E extends T%3E E add(Collection%3CT%3E c, E elem) %7B%0A%09%09require(c != null, %22collection is null%22);%0A%09%09c.add(elem);%0A%09%09return elem;%0A%09%7D
 %0A%0A%09/**%0A%09 * T

add method which returns the element