Class ADataSheet<T extends Comparable<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 equal SheetRow.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
    • Constructor Detail

      • ADataSheet

        public ADataSheet()
      • ADataSheet

        public ADataSheet​(int minCols,
                          int minRows)
    • Method Detail

      • 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 name
        sortStartPos - 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 - Iff rowIdx < 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 value
        columnIndex - the column index for the search
        Returns:
        a SheetRow object or null
      • 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)
      • 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)
      • removeRows

        public void removeRows​(int startIdx,
                               int endIdx)
                        throws Exception
        Throws:
        Exception
      • 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. If minSpareCols or minSpareRows 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 sheet
        colIdx - Integer column index at which the value should be put
        rowIdx - Long row index at which the value should be put
      • setColumn

        public void setColumn​(Integer colIdx,
                              SheetColumn col)
        Change the SheetColumn-Objekt on the position colIdx
        Parameters:
        colIdx - the position to change the object
        col - a SheetColumn-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 object
        name - 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()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isCellEmpty

        protected abstract boolean isCellEmpty​(SheetCell<T> cell)