Package de.xima.fc.gui.common.model.data
Class ADataSheet<T extends Comparable<T>>
- java.lang.Object
-
- de.xima.fc.gui.common.model.data.ADataSheet<T>
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
StringDataSheet
public abstract class ADataSheet<T extends Comparable<T>> extends Object implements Serializable
A data sheet for two dimensional data. It is indexed by the row index and the column index, both 0-based.
Invariants of the data sheet:- The
SheetRow.getId()must always reflect the current index of the row in this sheet. For example, a row at row index 3 must have its ID set to 3. - There must be at least
getMinRows()rows - There must be at least
getMinCols()columns - The
SheetRow.getCellCount()must the same for every row in this sheet. getColumnCount()must equalSheetRow.getCellCount(), ie. the list of columns must be kept in sync with the rows.- There must exist at least
getMinSpareRows()empty rows at the bottom end of this sheet. An empty row is a row with all column cells set to an isCellEmpty(SheetCell) value - There must exist at least
getMinSpareCols()empty columns at the right end of this sheet. An empty column is a column with all row cells to to an isCellEmpty(SheetCell) value
- Author:
- XIMA MEDIA GmbH, XIMA MEDIA GmbH
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MIN_COLSstatic intDEFAULT_MIN_ROWSstatic intDEFAULT_MIN_SPARE_COLSstatic intDEFAULT_MIN_SPARE_ROWSstatic intUNDEFINED_POSITION
-
Constructor Summary
Constructors Constructor Description ADataSheet()ADataSheet(int minCols, int minRows)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description SheetColumnaddColumnAtPosition(Integer colIdx)intaddColumnWithName(String name)Add a new column at the end of the column list and set the column nameintaddColumnWithNameSorted(String name, int sortStartPos)Add a new column in the column list, set the column name and sort the new column lexicographically in the column list from the given begin position.SheetRow<T>addRow(int rowIdx)Adds a new row at the given index.SheetRow<T>addRowLast()Adds a new row at the end of the rows list.booleanequals(Object obj)SheetRow<T>findRowByCellValue(T searchValue, int columnIndex)Finds the first row with the value at the given column index.SheetCell<T>getCell(int rowIndex, int colIndex)SheetColumngetColumn(int idx)SheetColumngetColumnByName(String name)IntegergetColumnCount()List<SheetColumn>getColumnIndices()StringgetColumnName(int idx)intgetColumnPositionByName(String name)Returns the first position from the columns index list where the column with the given name was foundintgetMinCols()intgetMinRows()intgetMinSpareCols()intgetMinSpareRows()IntegergetRowCount()List<SheetRow<T>>getRows()inthashCode()protected abstract booleanisCellEmpty(SheetCell<T> cell)booleanisColSpare(int colIdx)Checks whether the given column index is one of a spare column (to the right of the sheet)booleanisEmpty()booleanisFirstRowIsHeader()booleanisRowSpare(int rowIdx)Checks whether the given row index is one of a spare row (at the end of the sheet)voidremoveColumns(int startIdx, int endIdx)voidremoveRowIf(Predicate<SheetRow<T>> predicate)voidremoveRows(int startIdx, int endIdx)voidresetAllCellValuesToReference()Resets allSheetCell.getValue()-values toSheetCell.getReference()-reference, if reference value is not nullvoidsetCellValue(T value, int colIdx, int rowIdx)Puts the value in the data sheet at the position specified by the given row and column index.voidsetColumn(Integer colIdx, SheetColumn col)Change theSheetColumn-Objekt on the positioncolIdxvoidsetColumnName(Integer colIdx, String name)Change the name of then column object at the position of 'colIdx'voidsetFirstRowIsHeader(boolean firstRowIsHeader)voidsetMinCols(int minCols)voidsetMinRows(int minRows)voidsetMinSpareCols(int minSpareCols)voidsetMinSpareRows(int minSpareRows)voidsetRows(Collection<SheetRow<T>> rows)Sets the rows of this sheet to the given rows.voidsortRows(Comparator<SheetRow<T>> comparator)Sorts the rows by the given comparator, while ensuring the invariants of this data sheet.voidsortRowsByColumnValue(String columnName, Comparator<T> comparator)Sort the rows by values of the given column (define by column name).StringtoString()voidupdateCols()voidupdateRows()
-
-
-
Field Detail
-
DEFAULT_MIN_SPARE_ROWS
public static final int DEFAULT_MIN_SPARE_ROWS
- See Also:
- Constant Field Values
-
DEFAULT_MIN_SPARE_COLS
public static final int DEFAULT_MIN_SPARE_COLS
- See Also:
- Constant Field Values
-
DEFAULT_MIN_ROWS
public static final int DEFAULT_MIN_ROWS
- See Also:
- Constant Field Values
-
DEFAULT_MIN_COLS
public static final int DEFAULT_MIN_COLS
- See Also:
- Constant Field Values
-
UNDEFINED_POSITION
public static final int UNDEFINED_POSITION
- See Also:
- Constant Field Values
-
-
Method Detail
-
addColumnAtPosition
public SheetColumn addColumnAtPosition(Integer colIdx)
-
addColumnWithName
public int addColumnWithName(String name)
Add a new column at the end of the column list and set the column name- Parameters:
name- the name of the column- Returns:
- the new position
-
addColumnWithNameSorted
public int addColumnWithNameSorted(String name, int sortStartPos)
Add a new column in the column list, set the column name and sort the new column lexicographically in the column list from the given begin position.- Parameters:
name- the column namesortStartPos- the starting position within the column list in which the new column should be inserted- Returns:
- Position at which the column was added.
-
addRow
public SheetRow<T> addRow(int rowIdx)
Adds a new row at the given index.- Parameters:
rowIdx- 0-based index where to add the row.- Returns:
- The newly added row.
- Throws:
IndexOutOfBoundsException- IffrowIdx < 0 or rowIdx >=.getRowCount()
-
addRowLast
public SheetRow<T> addRowLast()
Adds a new row at the end of the rows list.- Returns:
- the last sheet row
-
findRowByCellValue
public SheetRow<T> findRowByCellValue(T searchValue, int columnIndex)
Finds the first row with the value at the given column index.- Parameters:
searchValue- the search valuecolumnIndex- the column index for the search- Returns:
- a
SheetRowobject ornull
-
getCell
public SheetCell<T> getCell(int rowIndex, int colIndex)
- Parameters:
rowIndex- 0-based index of the row.colIndex- 0-based index of the cell.- Returns:
- The cell at the given position, or
nullif no such cell exists.
-
getColumn
public SheetColumn getColumn(int idx)
-
getColumnByName
public SheetColumn getColumnByName(String name)
-
getColumnCount
public Integer getColumnCount()
- Returns:
- the columnCount
-
getColumnIndices
public List<SheetColumn> getColumnIndices()
- Returns:
- the columnIndices
-
getColumnName
public String getColumnName(int idx)
-
getColumnPositionByName
public int getColumnPositionByName(String name)
Returns the first position from the columns index list where the column with the given name was found- Parameters:
name- the name of the column- Returns:
Integerthe index of the column
-
getMinCols
public int getMinCols()
- Returns:
- the minCols
-
getMinRows
public int getMinRows()
- Returns:
- the minRows
-
getMinSpareCols
public int getMinSpareCols()
- Returns:
- the minSpareCols
-
getMinSpareRows
public int getMinSpareRows()
- Returns:
- the minSpareRows
-
getRowCount
public Integer getRowCount()
-
isColSpare
public final boolean isColSpare(int colIdx)
Checks whether the given column index is one of a spare column (to the right of the sheet)- Parameters:
colIdx-Integerindex of the column- Returns:
trueif it is a spare column
-
isEmpty
public boolean isEmpty()
-
isFirstRowIsHeader
public boolean isFirstRowIsHeader()
- Returns:
- the firstRowIsHeader
-
isRowSpare
public final boolean isRowSpare(int rowIdx)
Checks whether the given row index is one of a spare row (at the end of the sheet)- Parameters:
rowIdx-Integerindex of the row- Returns:
trueif it is a spare row
-
removeColumns
public void removeColumns(int startIdx, int endIdx)
-
resetAllCellValuesToReference
public void resetAllCellValuesToReference()
Resets allSheetCell.getValue()-values toSheetCell.getReference()-reference, if reference value is not null
-
setCellValue
public void setCellValue(T value, int colIdx, int rowIdx)
Puts the value in the data sheet at the position specified by the given row and column index. IfminSpareColsorminSpareRowsis specified in data sheet then new columns or rows will be added if necessary.- Parameters:
value-Comparablevalue to be put in the data sheetcolIdx-Integercolumn index at which the value should be putrowIdx-Longrow index at which the value should be put
-
setColumn
public void setColumn(Integer colIdx, SheetColumn col)
Change theSheetColumn-Objekt on the positioncolIdx- Parameters:
colIdx- the position to change the objectcol- aSheetColumn-Object
-
setColumnName
public void setColumnName(Integer colIdx, String name)
Change the name of then column object at the position of 'colIdx'- Parameters:
colIdx- position of the change column objectname- the column name
-
setFirstRowIsHeader
public void setFirstRowIsHeader(boolean firstRowIsHeader)
- Parameters:
firstRowIsHeader- the firstRowIsHeader to set
-
setMinCols
public void setMinCols(int minCols)
- Parameters:
minCols- the minCols to set
-
setMinRows
public void setMinRows(int minRows)
- Parameters:
minRows- the minRows to set
-
setMinSpareCols
public void setMinSpareCols(int minSpareCols)
- Parameters:
minSpareCols- the minSpareCols to set
-
setMinSpareRows
public void setMinSpareRows(int minSpareRows)
- Parameters:
minSpareRows- the minSpareRows to set
-
setRows
public void setRows(Collection<SheetRow<T>> rows)
Sets the rows of this sheet to the given rows.- Parameters:
rows- The rows to set. Modifications to this collection later does not affect this sheet.
-
sortRows
public void sortRows(Comparator<SheetRow<T>> comparator)
Sorts the rows by the given comparator, while ensuring the invariants of this data sheet.- Parameters:
comparator- Comparator for comparing two rows.
-
sortRowsByColumnValue
public void sortRowsByColumnValue(String columnName, Comparator<T> comparator)
Sort the rows by values of the given column (define by column name).- Parameters:
columnName- Name of the column by which to sort.comparator- Comparator for comparing the column values.
-
updateCols
public final void updateCols()
-
updateRows
public final void updateRows()
-
-