package net.sf.kerner.utils.collections;

import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;

import net.sf.kerner.utils.StringUtils;

public class CollectionUtils {

	private CollectionUtils() {
	}
	
	public static String toString(Iterable<?> elements){
		final StringBuilder b = new StringBuilder();
		b.append(StringUtils.NEW_LINE_STRING);
		final Iterator<?> i = elements.iterator();
		while(i.hasNext()){
			b.append(i.next());
			if(i.hasNext())
				b.append(StringUtils.NEW_LINE_STRING);
		}
		return b.toString();
	}
	
	public static <T> T getHighest(Collection<? extends T> elements, Comparator<T> c){
		T result = null;
		
		for(T e : elements){
			if(result == null){
				result = e;
			} else {
				int i = c.compare(e, result);
				if(i > 0)
					result = e;
			}
		}
		
		return result;
	}
	
	public static <T> T getLowest(Collection<? extends T> elements, Comparator<T> c){
		T result = null;
		
		for(T e : elements){
			if(result == null){
				result = e;
			} else {
				int i = c.compare(e, result);
				if(i < 0)
					result = e;
			}
		}
		
		return result;
	}

}

@@ -165,69 +165,540 @@
 ls;%0A
-%0Apublic class CollectionUtils %7B%0A%0A%09private CollectionUtils() %7B
+import net.sf.kerner.utils.collections.list.impl.ArrayListFactory;%0A%0Apublic class CollectionUtils %7B%0A%0A%09private CollectionUtils() %7B%0A%09%7D%0A%09%0A%09public static %3CC%3E Collection%3CC%3E append(Collection%3C? extends C%3E c1, Collection%3C? extends C%3E c2, CollectionFactory%3CC%3E factory)%7B%0A%09%09final Collection%3CC%3E result = factory.createCollection();%0A%09%09result.addAll(c1);%0A%09%09result.addAll(c2);%0A%09%09return result;%0A%09%7D%0A%09%0A%09public static %3CC%3E Collection%3CC%3E append(Collection%3C? extends C%3E c1, Collection%3C? extends C%3E c2)%7B%0A%09%09return append(c1, c2, new ArrayListFactory%3CC%3E());
 %0A%09%7D%0A

Introduce CollectionUtils#append().