import java.util.NoSuchElementException;

/**
 * CountableMatrix is a matrix of Countable objects
 * Your job is to fill in the method below.
 * Other methods have been provided for you.
 * 
 * @author Nancy Harris
 * @version V1 04/22/2013
 *
 */
public class SizableMatrixV3 {

	private Sizable[][] matrix;
	
	/** Constructor accepts an array of Countable objects
	 * and creates this CountableMatrix object
	 * 
	 * @param inMatrix The array to use
	 */
	public SizableMatrixV3(Sizable [][] inMatrix)
	{
		this.matrix = inMatrix;
	}
	
	
	/** 
	 * getAverageObjectSize calculates the average size
	 * of objects in the matrix.
	 * 
	 * If the matrix is null or empty (no Sizable objects), 
	 * throw a NoSuchElement exception. 
	 * 
	 * @return the average object size
	 */
	public double getAverageObjectSize()
	{
		// make me
		return -9999.9;
	}
	
	
	/**
	 * getLargestinRow returns the size of the largest object in 
	 * the given row. If the row is negative or is not in the matrix
	 * throw an ArrayIndexOutOfBoundsException with the message:
	 * "Row: " followed by the row number followed by " not valid."
	 * If the matrix is null or empty (no Sizable objects) or the row contains no 
	 *  Sizable objects, throw a NoSuchElement exception.
	 * 
	 * @param row The row you are interested in
	 * @return the description from the showValue method
	 *    of the largest object in the row
	 */
	public String getLargestinRow(int row)
	{
		// Make me
		return "Something";
	}
	
		
	/************************** private helper methods **************
	/** 
	 * isRow returns true if this row exists in the matrix.
	 * @param row The row number to check
	 * @return true if the row exists in this matrix, false otherwise
	 */
	private boolean isRow(int row)
	{
		boolean result = false;
		if (row >= 0 && matrix != null && 
				row < this.matrix.length && 
				this.matrix[row] != null)
			result = true;
		return result;
	}
	/** 
	 * isColumn returns true if the column exists in at least one
	 * row and false otherwise
	 * @param column The column number to check
	 * @return true if the column exists in at least one row in the
	 * matrix, false otherwise.
	 */
	private boolean isColumn(int column)
	{
		boolean result = false;
		if (column >= 0 && matrix != null)
			for (int row = 0; row < matrix.length && !result; row++)
			{
				if (matrix[row].length > column)
					result = true;
			}
		return result;
	}
}
