package com.eactive.eai.transformer.dao.excel;

public class ArraySheet implements Sheet {
	String[][] cells;
	
	public ArraySheet(int row, int col) {
		cells = new String[row][col];
	}
	
    public void setString(int row, int col, String value) {
    	cells[row][col] = value;
    }

    public String getCellString(int row, int col) throws Exception {
    	return cells[row][col];
    }
    
    public int getCellInt(int row, int col) throws Exception {
    	return Integer.parseInt(cells[row][col]);
    }
    
    public boolean existsRow(int row) throws Exception {
    	return cells.length > row;
    }
    
    public boolean existsCell(int row, int col) throws Exception {
    	if (!existsRow(row))
    		return false;
    	return cells[row].length > col;
    }   
    
    public boolean isEquals(int row, int col, String value) throws Exception {
    	if (value == null)
    		return false;
    	return value.equals(cells[row][col]);
    }
    
    public String getCellValue(int row, int col) {
    	return cells[row][col];
    }
    
    public String toString() {
    	StringBuilder sb = new StringBuilder();
    	for (int i=0; i<cells.length; i++) {
        	for (int j=0; j<cells[i].length; j++) {
        		sb.append("sheet[" + i + "][" + j + "] : " + cells[i][j] + "\n");
        	}
    	}
    	return sb.toString();
    }
}
