Class SpreadsheetWorksheet
java.lang.Object
org.eclipse.epsilon.emc.spreadsheets.SpreadsheetWorksheet
- Direct Known Subclasses:
ExcelWorksheet
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 Summary
Modifier and TypeFieldDescriptionprotected String
protected boolean
protected boolean
protected SpreadsheetWorksheetHeader
protected SpreadsheetModel
protected String
-
Constructor Summary
ConstructorDescriptionSpreadsheetWorksheet
(SpreadsheetModel model, String name, boolean existsInSpreadsheet) -
Method Summary
Modifier and TypeMethodDescriptionAdds information about an existing header column to the worksheet.Adds information about an existing header column to the worksheet.Writes a row to the worksheet.addRowWithValuesInColumns
(Map<SpreadsheetColumn, Object> parameters) Writes a row to the worksheet.protected void
Adds worksheet metadata to the worksheetprotected void
This method checks if this worksheet exists in the spreadsheet.protected abstract SpreadsheetColumn
createColumn
(int index) Creates a column with the specified column indexprotected abstract void
The purpose of this method is to create this worksheet in the spreadsheetvoid
deleteRow
(SpreadsheetRow row) Deletes the given row from the worksheet.findRows
(SpreadsheetColumn column, String value) Finds all rows in the worksheet whose cell, corresponding to the given column, has the provided value.getAlias()
getColumn
(int index) Gets the header column with the matching indexGets the column with the matching identifierabstract String
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.boolean
boolean
getModel()
getName()
protected String
abstract List<SpreadsheetRow>
getRows()
Gets all rows contained by the worksheetThe purpose of this method is to return a map where each column of this worksheet is associated with its default value.protected abstract SpreadsheetRow
insertRow
(Map<SpreadsheetColumn, String> values) Inserts a new row in the worksheet with given values in the given columns.boolean
boolean
isIdentifiablyBy
(String identifier) A worksheet can be identified by either it's name or alias.protected abstract void
Loads header row information - index and name - from the spreadsheet if the worksheet exists in the spreadsheetabstract void
removeRow
(SpreadsheetRow row) Deletes the given row from the actual worksheet.toString()
-
Field Details
-
model
-
header
-
existsInSpreadsheet
protected boolean existsInSpreadsheet -
name
-
alias
-
dataTypeStrict
protected boolean dataTypeStrict
-
-
Constructor Details
-
SpreadsheetWorksheet
-
-
Method Details
-
getModel
-
getHeader
-
getExistsInSpreadsheet
public boolean getExistsInSpreadsheet() -
getDoesNotExistInSpreadsheet
public boolean getDoesNotExistInSpreadsheet() -
getName
-
getAlias
-
isDataTypeStrict
public boolean isDataTypeStrict() -
isIdentifiablyBy
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
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
Gets the column with the matching identifier- Parameters:
identifier
-- Returns:
- column with the given identifier
-
getColumn
Gets the header column with the matching index- Parameters:
index
-- Returns:
- column with the given index
-
addColumn
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
Creates a column with the specified column index- Parameters:
index
-- Returns:
- column
-
getRows
Gets all rows contained by the worksheet- Returns:
- List of rows
-
addRow
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 bygetDefaultEmptyCellValue()
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
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 bygetDefaultEmptyCellValue()
or the default value for the column's data type if worksheet is data type strict.- Parameters:
parameters
-- Returns:
- the newly written row
-
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
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
Inserts a new row in the worksheet with given values in the given columns.- Parameters:
values
-- Returns:
- the newly created row
-
deleteRow
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
Deletes the given row from the actual worksheet.- Parameters:
row
-- Throws:
EolRuntimeException
-
findRows
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
This method checks if this worksheet exists in the spreadsheet.- Throws:
IllegalStateException
- if worksheet does not exist
-
getNonexistentWorksheetMessage
-
toString
-