/**
 *PrimitiveVector class handles primitive moby object;  String, Integer, FloatVector and DateTime are primitive objects;
 * it has some methods to get article names for these primitive moby object.
 *@author Lixin
 */

package org.biomoby.shared.schema;

import java.util.Vector;

public class PrimitiveVector
{
	private Vector stringVector=new Vector();//a vector to store article names for string moby object
	private Vector integerVector=new Vector();// a vector to store article names for integer moby object
	private Vector floatVector=new Vector();//a vector to store article names for float moby object
	private Vector DateTimeVector=new Vector();// a vector to store article names for float moby object

	public PrimitiveVector(Vector vc)
	{
		getPrimitiveVector(vc);
	}

	public PrimitiveVector(Vector v1, Vector v2)
	{
		Vector com=new Vector();
		com=addVector(v1,v2);
		getPrimitiveVector(com);
	}

	/**
	 *add the content of the second vector to the first vector
	 *@param v1 the first vector
 	 *@param v2 the second vector
	 *@return a vector contain elements in both v1 and v2
	 */
	public static Vector addVector(Vector v1, Vector v2)
	{
		for(int i=0; i<v2.size();i++)
		{
			MElement tem=(MElement)v2.get(i);
			v1.add(tem);
		}
		return v1; //for vector, it is pass by reference
	}

	/**
	 *Given a vector of MElement object, put article names of primitive objects into their corresponding vectors.
	 *@param mElements a vector containing mElement objects
	 */
	private void getPrimitiveVector(Vector mElements)
	{
		int size=mElements.size();
		for(int i=0; i<size; i++) //iterate every elements in the vector
		{
			MElement tem=(MElement)mElements.get(i);
			String name=tem.getName();

			if(MElement.isPrimitive(name)) //check whether the element is primitive; only handle primitive ones
			{
				String artName=tem.getArticleName();
				
				if(name.equalsIgnoreCase("String"))
				{
					stringVector.add(artName);//insert into the vector article names of String object
				}
				else if(name.equalsIgnoreCase("Integer"))
				{
					integerVector.add(artName);//insert into the vector article names of Integer object
				}
				else if(name.equalsIgnoreCase("Float"))
				{
					floatVector.add(artName);//insert into the vector article names of Float object
				}
				else if(name.equalsIgnoreCase("DateTime"))
				{
					DateTimeVector.add(artName);//insert into the vector article names of DateTime object
				}
				else
				{
					System.out.println("Why can not find Vector for:"+name);
				}
				
			}
		}
	}

	/**
	 *get the stringVector field of this object
	 *@return stringVector of this object
	 */
	public Vector getStringVector()
	{
		return this.stringVector;
	}

	/**
	 *get the integerVector field of this object
	 *@return integerVector field of this object
	 */
	public Vector getIntegerVector()
	{
		return this.integerVector;
	}
	
	/**
	 *get the floatVector field of this object
	 *@return floatVector field of this object
	 */
	public Vector getFloatVector()
	{
		return this.floatVector;
	}

	/**
	 *get the DateTimeVector field of this object.
	 *@return DateTimeVector field of this object
	 */
	public Vector getDateTimeVector()
	{
		return this.DateTimeVector;
	}

	/**
	 *get a string to represent this object.
	 *@return a string representing this object
	 */
	public String toString()
	{
		return "stringVector:"+stringVector+"\n"+"integerVector:"+integerVector+"\n"+"floatVector"+floatVector+"\n"
		+"DateTimeVector:"+DateTimeVector+"\n\n";

	}



	
}
			
