package speiger.src.coreengine.utils.collections.iterators;

import java.io.BufferedReader;
import java.io.Reader;
import java.util.Enumeration;
import java.util.Iterator;

import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;

public class IterableWrapper<T> implements Iterable<T> {
	Iterator<T> iter;
	
	protected IterableWrapper(Iterator<T> value) {
		iter = value;
	}
	
	public IterableWrapper<T> asReadOnly() {
		iter = new ReadOnlyIterator<T>(iter);
		return this;
	}
	
	@Override
	public Iterator<T> iterator() {
		return iter;
	}
	
	public static <T> IterableWrapper<T> reverseWrap(ObjectBidirectionalIterator<T> value) {
		return new IterableWrapper<T>(new ReverseIterator<T>(value));
	}
	
	public static <T> IterableWrapper<T> wrap(Iterator<T> value) {
		return new IterableWrapper<T>(value);
	}
	
	public static <T> IterableWrapper<T> wrap(Enumeration<T> value) {
		return new IterableWrapper<T>(new EnumIterator<T>(value));
	}
	
	public static IterableWrapper<String> wrap(Reader reader) {
		return new IterableWrapper<String>(new ReaderIterator(reader));
	}
	
	public static IterableWrapper<String> wrap(BufferedReader reader) {
		return new IterableWrapper<String>(new ReaderIterator(reader));
	}
}
