/**
 *This class has a instance variable mVector.  It is a MElement vector.  This class includes a method.  The method 
 *getHashtable() will return a hashtabel. The keys are the name of MElement; the values are vectors containning articel name.
 *@author Lixin
 */


package org.biomoby.shared.schema;

import java.util.Hashtable;
import java.util.Vector;

public class MElementHashtable
{
	private Vector mVector; //a vector of MElement

	public MElementHashtable(Vector vc)
	{
		this.mVector=vc;
	}

	/**
	*get a hashtabe; the kyes are the names of MElement; the values are vectors containning article names.
	*@return a hashtable
	*/
	public Hashtable getHashtable()
	{
		Hashtable tmp=new Hashtable();

		int size=mVector.size();
		
		for(int i=0; i<size; i++)
		{
			MElement mElement=(MElement)mVector.get(i);
			String name=mElement.getName();
			Vector vc=getArticleNames(name);//get articles name for the element having the name

			tmp.put(mElement,vc);//have override hashCode() of MElement; 
		}
		return tmp;
	}

	

	
	/**
	 *given a name of Element, find a vector which includes all article names; we also are given a vector of MElement,
	 *and here it is called mVector.Normally mVector is hasVector or hasaVector in Builder.java
	 *@param elementName a name of MElement
	 *@return a vector containing article names
	 */
	public Vector getArticleNames(String elementName)
	{
		Vector tmp=new Vector();

		int size=mVector.size(); //mVector is an instance variable. norally is hasa or has vector in Builder.java
		for(int i=0;i<size;i++)
		{
			MElement mElement=(MElement)mVector.get(i);
			String nameM=mElement.getName();
			if(nameM.equalsIgnoreCase(elementName)) //if the name of element is the same as the elementName
			{
				String artic=mElement.getArticleName();
				tmp.add(artic);  //put the article name of this element into the returned vector
			}
		}
		return tmp;
	}

	/**
	*return the instance variable mVector
	*/	
	public Vector getMVector()
	{
		return this.mVector;
	}


}
