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 int
DEFAULT_MIN_COLS
static int
DEFAULT_MIN_ROWS
static int
DEFAULT_MIN_SPARE_COLS
static int
DEFAULT_MIN_SPARE_ROWS
static int
UNDEFINED_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 SheetColumn
addColumnAtPosition(Integer colIdx)
int
addColumnWithName(String name)
Add a new column at the end of the column list and set the column nameint
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.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.boolean
equals(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)
SheetColumn
getColumn(int idx)
SheetColumn
getColumnByName(String name)
Integer
getColumnCount()
List<SheetColumn>
getColumnIndices()
String
getColumnName(int idx)
int
getColumnPositionByName(String name)
Returns the first position from the columns index list where the column with the given name was foundint
getMinCols()
int
getMinRows()
int
getMinSpareCols()
int
getMinSpareRows()
Integer
getRowCount()
List<SheetRow<T>>
getRows()
int
hashCode()
protected abstract boolean
isCellEmpty(SheetCell<T> cell)
boolean
isColSpare(int colIdx)
Checks whether the given column index is one of a spare column (to the right of the sheet)boolean
isEmpty()
boolean
isFirstRowIsHeader()
boolean
isRowSpare(int rowIdx)
Checks whether the given row index is one of a spare row (at the end of the sheet)void
removeColumns(int startIdx, int endIdx)
void
removeRowIf(Predicate<SheetRow<T>> predicate)
void
removeRows(int startIdx, int endIdx)
void
resetAllCellValuesToReference()
Resets allSheetCell.getValue()
-values toSheetCell.getReference()
-reference, if reference value is not nullvoid
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.void
setColumn(Integer colIdx, SheetColumn col)
Change theSheetColumn
-Objekt on the positioncolIdx
void
setColumnName(Integer colIdx, String name)
Change the name of then column object at the position of 'colIdx'void
setFirstRowIsHeader(boolean firstRowIsHeader)
void
setMinCols(int minCols)
void
setMinRows(int minRows)
void
setMinSpareCols(int minSpareCols)
void
setMinSpareRows(int minSpareRows)
void
setRows(Collection<SheetRow<T>> rows)
Sets the rows of this sheet to the given rows.void
sortRows(Comparator<SheetRow<T>> comparator)
Sorts the rows by the given comparator, while ensuring the invariants of this data sheet.void
sortRowsByColumnValue(String columnName, Comparator<T> comparator)
Sort the rows by values of the given column (define by column name).String
toString()
void
updateCols()
void
updateRows()
-
-
-
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
SheetRow
object 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
null
if 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:
Integer
the 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
-Integer
index of the column- Returns:
true
if 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
-Integer
index of the row- Returns:
true
if 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. IfminSpareCols
orminSpareRows
is specified in data sheet then new columns or rows will be added if necessary.- Parameters:
value
-Comparable
value to be put in the data sheetcolIdx
-Integer
column index at which the value should be putrowIdx
-Long
row 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()
-
-