/*
 * Created on Feb 7, 2004
 */
package LumiSoft.Data;

import java.util.*;

/**
 * 
 */
public class DataRowCollection implements Iterable<DataRow>
{
	private DataTable          m_pOwner = null;
	private ArrayList<DataRow> m_pRows  = null;
	
	/**
	 * Default constructor.
	 * @param owner
	 */
	protected DataRowCollection(DataTable owner)
	{
		m_pOwner = owner;
		m_pRows  = new ArrayList<DataRow>();
	}
	
	
	/**
	 * Add new DataRow to collection. 
	 * @param row
	 */
	public void Add(DataRow row)
	{
		m_pRows.add(row);
	}
	/**
	 * Creates a row using specified values and adds it to the DataRowCollection.
	 * @param values
	 * @return
	 */
	public DataRow Add(Object[] values)
	{
		// TODO: Check that values count = table columns count and are right data type
		
		DataRow dr = new DataRow(m_pOwner,values);
		Add(dr);
		
		return dr;
	}
	
	/**
	 * Removes the specified DataRow from the collection.
	 * @param row
	 */
	public void Remove(DataRow row)
	{
		m_pRows.remove(row);
	}
	/**
	 * Removes the row at the specified index from the collection.
	 * @param index
	 */
	public void Remove(int index)
	{
		m_pRows.remove(index);
	}	
	
	/**
	 * Deletes all rows.
	 *
	 */
	public void Clear()
	{
		m_pRows.clear();
	}
	
	/**
	 * Gets the row at the specified index.
	 * @param index
	 * @return
	 */
	public DataRow get(int index)
	{
		return m_pRows.get(index);
	}
	
	/**
	 * Gets the total number of rows in a collection.
	 * @return
	 */
	public int getCount()
	{
		return m_pRows.size();
	}
	
	
	/**
	 * Gets iterator.
	 */
	public Iterator<DataRow> iterator()
	{
		return m_pRows.iterator();
	}
}
