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: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.getMinRows()
rowsgetMinCols()
columnsSheetRow.getCellCount()
must the same for every row in this sheet.getColumnCount()
must equal SheetRow.getCellCount()
, ie. the list of columns must be kept in
sync with the rows.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) valuegetMinSpareCols()
empty columns at the right end of this sheet. An empty
column is a column with all row cells to to an isCellEmpty(SheetCell) valueModifier and Type | Field and 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 and Description |
---|
ADataSheet() |
ADataSheet(int minCols,
int minRows) |
Modifier and Type | Method and Description |
---|---|
SheetColumn |
addColumnAtPosition(Integer colIdx) |
int |
addColumnWithName(String name)
Add a new column at the end of the column list and set the column name
|
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.
|
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 found
|
int |
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 all
SheetCell.getValue() -values to SheetCell.getReference() -reference, if reference value is
not null |
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.
|
void |
setColumn(Integer colIdx,
SheetColumn col)
Change the
SheetColumn -Objekt on the position colIdx |
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() |
public static final int DEFAULT_MIN_SPARE_ROWS
public static final int DEFAULT_MIN_SPARE_COLS
public static final int DEFAULT_MIN_ROWS
public static final int DEFAULT_MIN_COLS
public static final int UNDEFINED_POSITION
public ADataSheet()
public ADataSheet(int minCols, int minRows)
public SheetColumn addColumnAtPosition(Integer colIdx)
public int addColumnWithName(String name)
name
- the name of the columnpublic int addColumnWithNameSorted(String name, int sortStartPos)
name
- the column namesortStartPos
- the starting position within the column list in which the new column should be insertedpublic SheetRow<T> addRow(int rowIdx)
rowIdx
- 0-based index where to add the row.IndexOutOfBoundsException
- Iff rowIdx < 0 or rowIdx >= getRowCount()
.public SheetRow<T> addRowLast()
public SheetRow<T> findRowByCellValue(T searchValue, int columnIndex)
searchValue
- the search valuecolumnIndex
- the column index for the searchSheetRow
object or null
public SheetCell<T> getCell(int rowIndex, int colIndex)
rowIndex
- 0-based index of the row.colIndex
- 0-based index of the cell.null
if no such cell exists.public SheetColumn getColumn(int idx)
public SheetColumn getColumnByName(String name)
public Integer getColumnCount()
public List<SheetColumn> getColumnIndices()
public String getColumnName(int idx)
public int getColumnPositionByName(String name)
name
- the name of the columnInteger
the index of the columnpublic int getMinCols()
public int getMinRows()
public int getMinSpareCols()
public int getMinSpareRows()
public Integer getRowCount()
public final boolean isColSpare(int colIdx)
colIdx
- Integer
index of the columntrue
if it is a spare columnpublic boolean isEmpty()
public boolean isFirstRowIsHeader()
public final boolean isRowSpare(int rowIdx)
rowIdx
- Integer
index of the rowtrue
if it is a spare rowpublic void removeColumns(int startIdx, int endIdx)
public void resetAllCellValuesToReference()
SheetCell.getValue()
-values to SheetCell.getReference()
-reference, if reference value is
not nullpublic void setCellValue(T value, int colIdx, int rowIdx)
minSpareCols
or minSpareRows
is specified in data sheet then new columns or rows will be
added if necessary.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 putpublic void setColumn(Integer colIdx, SheetColumn col)
SheetColumn
-Objekt on the position colIdx
colIdx
- the position to change the objectcol
- a SheetColumn
-Objectpublic void setColumnName(Integer colIdx, String name)
colIdx
- position of the change column objectname
- the column namepublic void setFirstRowIsHeader(boolean firstRowIsHeader)
firstRowIsHeader
- the firstRowIsHeader to setpublic void setMinCols(int minCols)
minCols
- the minCols to setpublic void setMinRows(int minRows)
minRows
- the minRows to setpublic void setMinSpareCols(int minSpareCols)
minSpareCols
- the minSpareCols to setpublic void setMinSpareRows(int minSpareRows)
minSpareRows
- the minSpareRows to setpublic void setRows(Collection<SheetRow<T>> rows)
rows
- The rows to set. Modifications to this collection later does not affect this sheet.public void sortRows(Comparator<SheetRow<T>> comparator)
comparator
- Comparator for comparing two rows.public void sortRowsByColumnValue(String columnName, Comparator<T> comparator)
columnName
- Name of the column by which to sort.comparator
- Comparator for comparing the column values.public final void updateCols()
public final void updateRows()
Copyright © 2020 XIMA MEDIA GmbH. All rights reserved.