package net.darkmist.alib.collection;

import java.util.Set;
import java.util.Iterator;
import java.util.LinkedHashSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public abstract class IteratorUtil
{
	private static final Class<IteratorUtil> CLASS = IteratorUtil.class;
        private static final Log logger = LogFactory.getLog(CLASS);

	public static <T> Set<T> addToSet(Set<T> set, Iterator<T> i)
	{
		while(i.hasNext())
		{
			T e = i.next();
			set.add(e);
		}
		return set;
	}

	public static <T> LinkedHashSet<T> toSet(Iterator<T> i)
	{
		LinkedHashSet<T> set = new LinkedHashSet<T>();
		addToSet(set, i);
		return set;
	}

	public static <T> LinkedHashSet<T> toSet(Iterator<T> i, int sizeGuess)
	{
		LinkedHashSet<T> set = new LinkedHashSet<T>(sizeGuess);
		addToSet(set, i);
		return set;
	}

	@SuppressWarnings("unchecked")
	public static <T> T[] toSetArray(Iterator<T> i)
	{
		return (T[])toSet(i).toArray();
	}

	@SuppressWarnings("unchecked")
	public static <T> T[] toSetArray(Iterator<T> i, int sizeGuess)
	{
		return (T[])toSet(i, sizeGuess).toArray();
	}
}

@@ -112,16 +112,57 @@
 HashSet;
+%0Aimport java.util.NoSuchElementException;
 %0A%0Aimport
@@ -1149,11 +1149,700 @@
 ay();%0A%09%7D
+%0A%0A%09private static class EmptyIterator%3CT%3E extends NonRemovingIterator%3CT%3E%0A%09%7B%0A%09%09private static EmptyIterator SINGLETON = new EmptyIterator();%0A%0A%09%09private EmptyIterator()%0A%09%09%7B%0A%09%09%7D%0A%0A%09%09static %3CT%3E EmptyIterator%3CT%3E instance()%0A%09%09%7B%0A%09%09%09return SINGLETON;%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public boolean hasNext()%0A%09%09%7B%0A%09%09%09return false;%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public T next()%0A%09%09%7B%0A%09%09%09throw new NoSuchElementException(%22This iterator has no content!%22);%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public boolean equals(Object o)%0A%09%09%7B%0A%09%09%09if(o == null)%0A%09%09%09%09return false;%0A%09%09%09if(!(o instanceof Iterator))%0A%09%09%09%09return false;%0A%09%09%09return !((Iterator)o).hasNext();%0A%09%09%7D%0A%09%7D%0A%0A%09public static %3CT%3E Iterator%3CT%3E getEmptyIterator()%0A%09%7B%0A%09%09return EmptyIterator.instance();%0A%09%7D
 %0A%7D%0A

Add empty iterator...