/** Print the table content */ public void printTable() { for (int row = 0; row < dataTable.getRowCount(); ++row) { for (int col = 0; col < dataTable.getColumnCount(); ++col) { System.out.print("<>" + dataTable.getCell(row, col) + " "); } } }
/** * get cell value by row/column index(only string is supported) * * @param rowIndex * @param colIndex * @return */ public String getCell(int rowIndex, int colIndex) { checkRowArgument(rowIndex); checkColArgument(colIndex); if (dataTable.getCell(rowIndex, colIndex) == null) { System.out.println("there no content in specified cell"); return null; } return dataTable.getCell(rowIndex, colIndex).toString(); }
/** * Check whether or not the cell exist * * @param value * @return true/false */ public boolean doesCellValueExist(String value) { for (int row = 0; row < dataTable.getRowCount(); ++row) { for (int col = 0; col < dataTable.getColumnCount(); col++) { if (value.equals(getCell(row, col))) { return true; } } } return false; }
/** * return the value by key , for the table only contains 2 columns , the first column is regarded * as key column, and the second is value column * * @param key * @param val * @return */ public boolean doesKeyValueExist(String key, String val) { for (int row = 0; row < dataTable.getRowCount(); ++row) { if (!key.equals(dataTable.getCell(row, 0))) { continue; } else { if (val.equals(dataTable.getCell(row, 1))) { return true; } else { return false; } } } return false; }
/** * Get the row name by index (start from 0) * * @param index * @return */ public String getRowHeader(int index) { checkRowArgument(index); return (String) dataTable.getRowHeader(index); }
/** * Get the column name by index (start from 0) * * @param index * @return */ public String getColumnHeader(int index) { checkColArgument(index); return (String) dataTable.getColumnHeader(index); }
/** @return the column count of the table */ public int getColumnCount() { return dataTable.getColumnCount(); }
/** @return the row count of the table */ public int getRowCount() { return dataTable.getRowCount(); }