Class SpreadsheetWorksheet

java.lang.Object
org.eclipse.epsilon.emc.spreadsheets.SpreadsheetWorksheet
Direct Known Subclasses:
ExcelWorksheet

public abstract class SpreadsheetWorksheet extends 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 Details

  • Constructor Details

    • SpreadsheetWorksheet

      public SpreadsheetWorksheet(SpreadsheetModel model, String name, boolean existsInSpreadsheet)
  • Method Details

    • getModel

      public SpreadsheetModel getModel()
    • getHeader

      public SpreadsheetWorksheetHeader getHeader()
    • getExistsInSpreadsheet

      public boolean getExistsInSpreadsheet()
    • getDoesNotExistInSpreadsheet

      public boolean getDoesNotExistInSpreadsheet()
    • getName

      public String getName()
    • getAlias

      public String getAlias()
    • isDataTypeStrict

      public boolean isDataTypeStrict()
    • isIdentifiablyBy

      public boolean isIdentifiablyBy(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:
      RuntimeException
    • loadHeader

      protected abstract void loadHeader() throws EolModelLoadingException
      Loads header row information - index and name - from the spreadsheet if the worksheet exists in the spreadsheet
      Throws:
      EolModelLoadingException
    • addWorksheetMetadata

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

      public SpreadsheetColumn getColumn(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, String name)
      Adds information about an existing header column to the worksheet.
      Parameters:
      index -
      name -
      Returns:
      SpreadsheetColumn
    • addColumn

      Adds information about an existing header column to the worksheet. If the column described by the given metadata does not exist the column is created.
      Parameters:
      metadata -
      Returns:
      SpreadsheetColumn
    • createColumn

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

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

      public SpreadsheetRow addRow(Map<String,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:
      IllegalArgumentException - if a column identifier could not be mapped to a column in the worksheet
    • addRowWithValuesInColumns

      public SpreadsheetRow addRowWithValuesInColumns(Map<SpreadsheetColumn,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 Map<SpreadsheetColumn,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<SpreadsheetColumn, String>
    • getDefaultEmptyCellValue

      public abstract 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(Map<SpreadsheetColumn,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
    • removeRow

      public abstract void removeRow(SpreadsheetRow row)
      Deletes the given row from the actual worksheet.
      Parameters:
      row -
      Throws:
      EolRuntimeException
    • findRows

      public List<SpreadsheetRow> findRows(SpreadsheetColumn column, 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 IllegalStateException
      This method checks if this worksheet exists in the spreadsheet.
      Throws:
      IllegalStateException - if worksheet does not exist
    • getNonexistentWorksheetMessage

      protected String getNonexistentWorksheetMessage()
    • toString

      public String toString()
      Overrides:
      toString in class Object