import java.util.*;

/**
 * This class represents a segmentation in items of video file
 * and used in known-items task programs of TREC 2001.
 * Not the entire video is represented in a segmentation, the term of segmentation
 * is used for convenience, but it's just a bunch of items of the same video
 * that need to be processed together cause result of one particular system 
 * for one particular topic.
 * 
 * @author NIST-ITL-IAD-Retrieval Group
 * This software was produced by NIST, an agency of the
 * U.S. government, and by statute is not subject to copyright in the
 * United States. Recipients of this software assume all
 * responsibilities associated with its operation, modification and
 * maintenance.
 *
 */
public abstract class Segmentation{

    /**
     * This object is containing all items of the video.
     *
     */
	protected TreeSet itemSet;
    /**
     * This is the topic number for the one the results (items) has been founded.
     *
     */
	protected String topicNumber = "";
    /**
     * This is just the number of dropped out items for cause of duplicate in results.
     *
     */
	protected int droppedOut = 0;
    /**
     * Returns an iterator on the items of the segmentation.
     *
     * @return     an iterator on the items of the segmentation.
     */
	public Iterator getElements(){
		return this.itemSet.iterator();
	}
    /**
     * Add a given item to the segmentation. 
     * Update "droppedOut" if it is a duplicate (according to the Comparator).
     *
     * @param     t the item to be added to the segmentation.
     */
	public void add(Item t){
		boolean notContained = true;
		Iterator i = itemSet.iterator();
		Comparator c = this.itemSet.comparator();
		while(i.hasNext() && notContained){
			Item s = (Item)i.next();
			if(c.compare(t,s) == 0){
				notContained = false;
				droppedOut++;
			}
		}
		if(notContained)
			itemSet.add(t);
	}
	
    public boolean contains(Object o){
    	return itemSet.contains(o);	
    }
    /**
     * Returns the number of items of the segmentation.
     *
     * @return     Number of items of the segmentation.
     */
	public int getItemCount(){ return itemSet.size(); }
    /**
     * Gets the topic number.
     *
     * @return     The topic number.
     */
	public String getTopicNumber(){ return this.topicNumber; }
    /**
     * Gets the number of dropped out duplicate items.
     *
     * @return     The number of dropped out duplicate items.
     */
	public int getDroppedOut(){ return droppedOut; }
    /**
     * Returns a simple string representing the items of the segmentation.
     *
     * @return     a simple string representing the items of the segmentation.
     */	
	public String toString(){
		String toReturn = "";
		Iterator e = itemSet.iterator();
		while(e.hasNext()){
			Item s = (Item) e.next();
			toReturn += s.toString();
		}
		return toReturn;
	}
}
