Class SpreadsheetWorksheet

  • Direct Known Subclasses:
    ConcreteWorksheet, ExcelWorksheet, GSWorksheet

    public abstract class SpreadsheetWorksheet
    extends java.lang.Object
    This class represents a worksheet. Worksheets are assumed to be valid only if they have a name. A worksheet may or may not exist in a spreadsheet (model) and this can be indicated through the constructor. If a worksheet does not exist in the spreadsheet it is expected to be created the first time is is accessed.
    Author:
    Martins Francis
    • Field Detail

      • existsInSpreadsheet

        protected boolean existsInSpreadsheet
      • name

        protected java.lang.String name
      • alias

        protected java.lang.String alias
      • dataTypeStrict

        protected boolean dataTypeStrict
    • Constructor Detail

      • SpreadsheetWorksheet

        public SpreadsheetWorksheet​(SpreadsheetModel model,
                                    java.lang.String name,
                                    boolean existsInSpreadsheet)
    • Method Detail

      • getExistsInSpreadsheet

        public boolean getExistsInSpreadsheet()
      • getDoesNotExistInSpreadsheet

        public boolean getDoesNotExistInSpreadsheet()
      • getName

        public java.lang.String getName()
      • getAlias

        public java.lang.String getAlias()
      • isDataTypeStrict

        public boolean isDataTypeStrict()
      • isIdentifiablyBy

        public boolean isIdentifiablyBy​(java.lang.String identifier)
        A worksheet can be identified by either it's name or alias.
        Parameters:
        identifier -
        Returns:
        true if identifier describes this worksheet
      • createInSpreadsheet

        protected abstract void createInSpreadsheet()
        The purpose of this method is to create this worksheet in the spreadsheet
        Throws:
        java.lang.RuntimeException
      • addWorksheetMetadata

        protected void addWorksheetMetadata​(ISpreadsheetMetadata.SpreadsheetWorksheetMetadata metadata)
                                     throws java.lang.IllegalArgumentException
        Adds worksheet metadata to the worksheet
        Parameters:
        metadata -
        Throws:
        java.lang.IllegalArgumentException
      • getColumn

        public SpreadsheetColumn getColumn​(java.lang.String identifier)
        Gets the column with the matching identifier
        Parameters:
        identifier -
        Returns:
        column with the given identifier
      • getColumn

        public SpreadsheetColumn getColumn​(int index)
        Gets the header column with the matching index
        Parameters:
        index -
        Returns:
        column with the given index
      • addColumn

        public SpreadsheetColumn addColumn​(int index,
                                           java.lang.String name)
        Adds information about an existing header column to the worksheet.
        Parameters:
        index -
        name -
        Returns:
        SpreadsheetColumn
      • createColumn

        protected abstract SpreadsheetColumn createColumn​(int index)
        Creates a column with the specified column index
        Parameters:
        index -
        Returns:
        column
      • getRows

        public abstract java.util.List<SpreadsheetRow> getRows()
        Gets all rows contained by the worksheet
        Returns:
        List of rows
      • addRow

        public SpreadsheetRow addRow​(java.util.Map<java.lang.String,​java.lang.Object> parameters)
        Writes a row to the worksheet. The Map links column identifiers with desired cell values. Cells that do not have a value provided will contain value returned by getDefaultEmptyCellValue() or the default value for the column's data type if worksheet is data type strict.
        Parameters:
        parameters -
        Returns:
        the newly written row
        Throws:
        java.lang.IllegalArgumentException - if a column identifier could not be mapped to a column in the worksheet
      • addRowWithValuesInColumns

        public SpreadsheetRow addRowWithValuesInColumns​(java.util.Map<SpreadsheetColumn,​java.lang.Object> parameters)
        Writes a row to the worksheet. The Map links columns with desired cell values. Cells that do not have a value provided will contain value returned by getDefaultEmptyCellValue() or the default value for the column's data type if worksheet is data type strict.
        Parameters:
        parameters -
        Returns:
        the newly written row
      • getValuesForEmptyRow

        public java.util.Map<SpreadsheetColumn,​java.lang.String> getValuesForEmptyRow()
        The purpose of this method is to return a map where each column of this worksheet is associated with its default value.
        Returns:
        Map
      • getDefaultEmptyCellValue

        public abstract java.lang.String getDefaultEmptyCellValue()
        This method returns the default value to be written to a cell when a new empty row is created in a worksheet that is not enforcing data type strictness.
        Returns:
        String
      • insertRow

        protected abstract SpreadsheetRow insertRow​(java.util.Map<SpreadsheetColumn,​java.lang.String> values)
        Inserts a new row in the worksheet with given values in the given columns.
        Parameters:
        values -
        Returns:
        the newly created row
      • deleteRow

        public void deleteRow​(SpreadsheetRow row)
                       throws EolRuntimeException
        Deletes the given row from the worksheet. This method handles deletions of referencing rows, referenced rows and regular rows. It also takes care of cascading updates if specified to do so.
        Parameters:
        row -
        Throws:
        EolRuntimeException
      • findRows

        public java.util.List<SpreadsheetRow> findRows​(SpreadsheetColumn column,
                                                       java.lang.String value)
        Finds all rows in the worksheet whose cell, corresponding to the given column, has the provided value. By 'has' it means that if the cell may contain multiple values then if one of those values match the search value then the row is returned. If the cell may not contain multiple values the cell's value must be an exact match to the search value.
        Parameters:
        column -
        value -
        Returns:
        List of rows whose cell contains value
      • checkThatWorksheetExists

        protected void checkThatWorksheetExists()
                                         throws java.lang.IllegalStateException
        This method checks if this worksheet exists in the spreadsheet.
        Throws:
        java.lang.IllegalStateException - if worksheet does not exist
      • getNonexistentWorksheetMessage

        protected java.lang.String getNonexistentWorksheetMessage()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object