/** * Set Cell on the table * * @param pRowIndex * @param pColumnIndex * @param pCell * @throws PuException * @throws IndexOutOfBoundsException */ public void setCell(int pRowIndex, int pColumnIndex, TCell pCell) throws PuException, IndexOutOfBoundsException { TRow row = _mListOfRows.get(pRowIndex); if (!row.getCell(pColumnIndex).getValueType().equals(pCell.getValueType())) { throw new PuException( _mContext, "New cell value type does not match expected value type." + " Expected type: " + row.getCell(pColumnIndex).getValueType() + " but was: " + pCell.getValueType()); } row.setCell(pColumnIndex, pCell); }
/** * Retrun List of cells of column X * * @param pColumnIndex * @return List of Cells */ public ArrayList<TCell> getColumnCells(int pColumnIndex) { ArrayList<TCell> lListOfCells = new ArrayList<TCell>(getRowsCount()); for (TRow row : _mListOfRows) { lListOfCells.add(row.getCell(pColumnIndex)); } return lListOfCells; }
@Override public int compare(TRow pRow1, TRow pRow2) { int lCompare = 0; int lIndexOfCoulmn = 0; // init Cells to compare TCell lCellRow1 = pRow1.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn])); TCell lCellRow2 = pRow2.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn])); for (int i = 0; i < _mListOfSortedColumnsName.length; i++) { // Update cells with the differents values of columns names lCellRow1 = pRow1.getCell(indexOfColumn(_mListOfSortedColumnsName[i])); lCellRow2 = pRow2.getCell(indexOfColumn(_mListOfSortedColumnsName[i])); switch (lCellRow1.getValueType()) { case INTEGER: // If eguals , incremente lIndexOfColumn to pass to the next // columns comparaison if (lCellRow1.asInteger() == lCellRow2.asInteger()) if (lIndexOfCoulmn < _mListOfSortedColumnsName.length - 1) lIndexOfCoulmn++; else break; break; case DOUBLE: // If eguals , incremente lIndexOfColumn to pass to the next columns comparaison if (lCellRow1.asDouble() == lCellRow2.asDouble()) if (lIndexOfCoulmn < _mListOfSortedColumnsName.length - 1) lIndexOfCoulmn++; else break; break; case BOOLEAN: case TEXT: if (lCellRow1.asString().equals(lCellRow2.asString())) if (lIndexOfCoulmn < _mListOfSortedColumnsName.length - 1) lIndexOfCoulmn++; else break; break; default: break; } // Update cells with the differents values of columns names lCellRow1 = pRow1.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn])); lCellRow2 = pRow2.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn])); switch (lCellRow1.getValueType()) { case INTEGER: lCompare = lCellRow1.asInteger() - lCellRow2.asInteger(); break; case DOUBLE: lCompare = Double.compare(lCellRow1.asDouble(), lCellRow2.asDouble()); break; case BOOLEAN: case TEXT: lCompare = lCellRow1.asString().compareTo(lCellRow2.asString()); break; default: break; } } // inverse sort if (_mSortType == TRowSortOrder.DESC) lCompare = -lCompare; return lCompare; }