Package adams.data.spreadsheet
Class HeaderRow
- java.lang.Object
-
- adams.data.spreadsheet.AbstractRow
-
- adams.data.spreadsheet.HeaderRow
-
- All Implemented Interfaces:
Mergeable<Row>
,Row
,Serializable
- Direct Known Subclasses:
InstancesHeaderRow
public class HeaderRow extends AbstractRow
Represents a header row.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected ArrayList<String>
m_CellKeys
the cell keys of the row.-
Fields inherited from class adams.data.spreadsheet.AbstractRow
m_Cells, m_Owner
-
-
Constructor Summary
Constructors Constructor Description HeaderRow(SpreadSheet owner)
default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Cell
addCell(int columnIndex)
Adds a cell with the key of the cell in the header at the specified location.Cell
addCell(String cellKey)
Adds a cell with the given key to the list and returns the created object.void
assign(Row row)
Obtains copies of the cells from the other row, but not the owner.Collection<String>
cellKeys()
Returns a collection of all stored cell keys.Collection<Cell>
cells()
Returns all cells.void
clear()
Removes all cells.String
getCellKey(int columnIndex)
Returns the cell key with the given column index.HeaderRow
getClone(SpreadSheet owner)
Returns a clone of itself.boolean
hasCell(int columnIndex)
Returns whether the row alread contains the cell at the specified location.int
indexOf(Cell cell)
Returns the column this particular cell is in (must belong to this row!).int
indexOf(String cellKey)
Returns the index of the specified key.int
indexOfContent(String content)
Returns the index of the cell that has the specified content.Cell
insertCell(int columnIndex)
Inserts a cell at the specified location.void
mergeWith(Row other)
Merges its own data with the one provided by the specified row.Cell
newCell(Row owner)
Creates a new instance of a cell.Cell
removeCell(String cellKey)
Removes the cell at the specified index.protected String
uniqueKey(String key)
Ensures that the key is not yet present.-
Methods inherited from class adams.data.spreadsheet.AbstractRow
getCell, getCell, getCellCount, getContent, getOwner, hasCell, removeCell, removeMissing, setOwner, toString
-
-
-
-
Constructor Detail
-
HeaderRow
public HeaderRow(SpreadSheet owner)
default constructor.- Parameters:
owner
- the spreadsheet this row belongs to
-
-
Method Detail
-
assign
public void assign(Row row)
Obtains copies of the cells from the other row, but not the owner.- Specified by:
assign
in interfaceRow
- Overrides:
assign
in classAbstractRow
- Parameters:
row
- the row to get the cells from
-
getClone
public HeaderRow getClone(SpreadSheet owner)
Returns a clone of itself.- Parameters:
owner
- the new owner- Returns:
- the clone
-
clear
public void clear()
Removes all cells.- Specified by:
clear
in interfaceRow
- Overrides:
clear
in classAbstractRow
-
newCell
public Cell newCell(Row owner)
Creates a new instance of a cell.- Parameters:
owner
- the owner- Returns:
- the cell
-
hasCell
public boolean hasCell(int columnIndex)
Returns whether the row alread contains the cell at the specified location.- Parameters:
columnIndex
- the column index- Returns:
- true if the cell already exists
-
indexOf
public int indexOf(String cellKey)
Returns the index of the specified key.- Parameters:
cellKey
- the key to look for- Returns:
- the index of the cell, -1 if not found
-
indexOfContent
public int indexOfContent(String content)
Returns the index of the cell that has the specified content.- Parameters:
content
- the content to look for- Returns:
- the index of the cell, -1 if not found
-
addCell
public Cell addCell(int columnIndex)
Adds a cell with the key of the cell in the header at the specified location. If the cell already exists, it returns that instead of creating one.- Specified by:
addCell
in interfaceRow
- Specified by:
addCell
in classAbstractRow
- Parameters:
columnIndex
- the index of the column to create- Returns:
- the created cell or the already existing cell
-
addCell
public Cell addCell(String cellKey)
Adds a cell with the given key to the list and returns the created object. If the cell already exists, then this cell is returned instead and no new object created.- Specified by:
addCell
in interfaceRow
- Specified by:
addCell
in classAbstractRow
- Parameters:
cellKey
- the key for the cell to create- Returns:
- the created cell or the already existing cell
-
insertCell
public Cell insertCell(int columnIndex)
Inserts a cell at the specified location.- Parameters:
columnIndex
- the location of the new cell- Returns:
- the created cell
-
removeCell
public Cell removeCell(String cellKey)
Removes the cell at the specified index.- Specified by:
removeCell
in interfaceRow
- Overrides:
removeCell
in classAbstractRow
- Parameters:
cellKey
- the key of the cell to remove- Returns:
- the removed cell, null if non removed
-
getCellKey
public String getCellKey(int columnIndex)
Returns the cell key with the given column index.- Specified by:
getCellKey
in interfaceRow
- Specified by:
getCellKey
in classAbstractRow
- Parameters:
columnIndex
- the index of the column- Returns:
- the cell key, null if invalid index
-
cellKeys
public Collection<String> cellKeys()
Returns a collection of all stored cell keys.- Specified by:
cellKeys
in interfaceRow
- Specified by:
cellKeys
in classAbstractRow
- Returns:
- all cell keys (sorted according to columns)
-
cells
public Collection<Cell> cells()
Returns all cells.- Returns:
- the cells (sorted)
-
indexOf
public int indexOf(Cell cell)
Returns the column this particular cell is in (must belong to this row!).- Parameters:
cell
- the cell to get the column index of- Returns:
- the column index, -1 if not found
-
uniqueKey
protected String uniqueKey(String key)
Ensures that the key is not yet present. In case the key is already used it is made unique.- Parameters:
key
- the key to check- Returns:
- the potentially updated key
-
mergeWith
public void mergeWith(Row other)
Merges its own data with the one provided by the specified row.- Parameters:
other
- the row to merge with
-
-