package aalg.algebra;

import java.util.Iterator;

/**
 * Implementation of Iterable that uses underlying Iterable for getting elements and filters them.
 * Filtering is done by calling method containsElement on filtering structure.
 * @author Ing. Petr Ležák
 *
 * @param <T> type of elements
 */
public class FilteringIterable<T extends IElement> implements Iterable<T> {
	
	private final Iterable<T> baseIterable;
	private final IAlgebraicStructure<T> filteringStructure;
	
	/**
	 * Creates filtering iterable.
	 * @param baseIterable underlying iterable 
	 * @param filteringStructure structure that is used as element filter
	 */
	public FilteringIterable (final Iterable<T> baseIterable, final IAlgebraicStructure<T> filteringStructure) {
		this.baseIterable = baseIterable;
		this.filteringStructure = filteringStructure;
	}

	@Override
	public Iterator<T> iterator() {
		return new FilteringIterator<T>(baseIterable.iterator(), filteringStructure);
	}

}
