package de.uka.ipd.consensus.impl;

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

/**
 * 
 * TODO
 * @author Thomas Much
 * @version 2006-06-14
 */
public class TM4JCollectionWrapperSet extends AbstractSet {

	private OntologyManagerImpl omi;
	private Collection          src;


	public static Collection getInstance(OntologyManagerImpl omi, Collection src) {
		if ((src != null) && (src.size() > 0)) {
			if (src instanceof TM4JCollectionWrapperSet) {
				return src;
			}
			else {
				return new TM4JCollectionWrapperSet(omi,src);
			}
		}
		else {
			return Collections.EMPTY_SET;
		}
	}


	private TM4JCollectionWrapperSet(OntologyManagerImpl omi, Collection src) {
		this.omi = omi;
		this.src = src;
	}


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


	public int size() {
		return src.size();
	}




	private class TM4JCollectionWrapperSetIterator implements Iterator {

		private Iterator it = src.iterator();

		
		public boolean hasNext() {
			return it.hasNext();
		}

		
		public Object next() {
			return TM4JObjectWrapper.wrap( omi, it.next() );
		}

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

}
