import java.util.*;

/**
 * This class represents a segmentation related to a video file
 * used in shot boundary detection task programs of TREC 2001.
 *
 * @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{
	/**
     * The video name the segmentation is related to.
     *
     * @see #getVideoName()
     */
	protected String videoName;
	/**
     * This object is containing all the transitions of the segmentation.
     *
     * @see #getElements()
     */
	protected TreeSet transitionSet;
	/**
     * Returns the number of Cut transitions within the segmentation.
     *
     * @return     the number of Cut transitions within the segmentation.
     */	
	protected int getCutFrameCount(){
		int toReturn = 0;
		Iterator i = this.transitionSet.iterator();
		while(i.hasNext()){
			Transition t = (Transition) i.next();
			if(t.type.equals("CUT"))
				toReturn++;
		}
		return toReturn;
	}
	/**
     * Returns an iterator on the transitions within the segmentation.
     *
     * @return     an iterator on the transitions within the segmentation.
     */	
    protected Iterator getElements(){
		return this.transitionSet.iterator();
	}
	/**
     * Add a given transition to the segmentation.
     *
     * @param     aTransition the transition to be added to the segmentation.
     */
	protected void add(Transition aTransition){ 
		transitionSet.add(aTransition);	
	}
	/**
     * Returns the video name the segmentation is related to.
     *
     * @return     the video name the segmentation is related to.
     */	
	protected String getVideoName(){ 
		return videoName;
	}
	/**
     * Returns the number of transitions within the segmentation.
     *
     * @return     the number of transitions within the segmentation.
     */	
	protected int getTransitionCount(){ 
		return transitionSet.size();
	}
	/**
     * Returns an Xml string representing the segmentation in a pre-defined format.
     *
     * @return     an Xml string representing the segmentation.
     */	
	public String toString(){
		String toReturn = "<seg src=\""+videoName+"\">"+System.getProperty("line.separator");
		Iterator e = transitionSet.iterator();
		while(e.hasNext()){
			Transition s = (Transition) e.next();
			toReturn += s.toString();
		}
		toReturn += "</seg>"+System.getProperty("line.separator");
		return toReturn;
	}
}