package de.uka.ipd.consensus.impl;

import java.util.AbstractSet;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

import org.tm4j.tologx.TologResultsSet;

/**
 * TODO
 * @author much
 * @deprecated only used by deprecated TM4JRatingManager
 */
public class TM4JTologResultWrapperSet extends AbstractSet {

	private OntologyManagerImpl omi;
	private TologResultsSet     rs;


	public static Collection getInstance(OntologyManagerImpl omi, TologResultsSet rs) {
		if ((rs != null) && (rs.getNumRows() > 0)) {
			return new TM4JTologResultWrapperSet(omi,rs);
		}
		else {
			return Collections.EMPTY_SET;
		}
	}


	private TM4JTologResultWrapperSet(OntologyManagerImpl omi, TologResultsSet rs) {
		// Bedingung: erste Spalte des ResultSet enthält das Ergebnis-Objekt
		this.omi = omi;
		this.rs  = rs;
	}

	
	public Iterator iterator() {
		return new TM4JTologResultWrapperSetIterator();
	}


	public int size() {
		return rs.getNumRows();
	}




	private class TM4JTologResultWrapperSetIterator implements Iterator {

		private int pos = 0;


		public boolean hasNext() {
			return (pos < size());
		}


		public Object next() {
			Object obj = rs.getRow( pos ).get( 0 );
			pos++;
			return TM4JObjectWrapper.wrap( omi, obj );
		}

		
		public void remove() {
			throw new UnsupportedOperationException();
		}
	}

}
