Package adams.data.spreadsheet
Interface SpreadSheet
-
- All Superinterfaces:
CloneHandler<SpreadSheet>
,LocaleSupporter
,Mergeable<SpreadSheet>
,Serializable
- All Known Subinterfaces:
Dataset
- All Known Implementing Classes:
DatasetView
,DefaultDataset
,DefaultSpreadSheet
,InstancesView
,SpreadSheetView
public interface SpreadSheet extends Serializable, CloneHandler<SpreadSheet>, LocaleSupporter, Mergeable<SpreadSheet>
Represents a generic spreadsheet object.- Version:
- $Revision: 12570 $
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMMENT
the line comment start.static String
MISSING_VALUE
the default missing value.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addComment(String comment)
Adds the comment to the internal list of comments.void
addComment(List<String> comment)
Adds the comments to the internal list of comments.DataRow
addRow()
Appends a row to the spreadsheet.DataRow
addRow(String rowKey)
Adds a row with the given key to the list and returns the created object.void
assign(SpreadSheet sheet)
Clears this spreadsheet and copies all the data from the given one.void
calculate()
Triggers all formula cells to recalculate their values.void
clear()
Removes all cells, but leaves comments.String
equalsHeader(SpreadSheet other)
Compares the header of this spreadsheet with the other one.Cell
getCell(int rowIndex, int columnIndex)
Returns the corresponding cell or null if not found.int
getCellIndex(String cellKey)
Returns the cell index of the specified cell (in the header row).String
getCellPosition(String rowKey, String cellKey)
Returns the position of the cell or null if not found.List<String>
getCellValues(int colIndex)
Returns the unique string values of the specified column.List<String>
getCellValues(String colKey)
Returns the unique string values of the specified column.SpreadSheet
getClone()
Returns a clone of itself.int
getColumnCount()
Returns the number of columns.String
getColumnName(int colIndex)
Returns the name of the specified column.List<String>
getColumnNames()
Returns a list of the names of all columns (i.e., the content the header row cells).List<String>
getComments()
Returns the comments.Cell.ContentType
getContentType(int columnIndex)
Returns the pure content type of the given column, if available.Collection<Cell.ContentType>
getContentTypes(int columnIndex)
Returns the all content types of the given column, if available.Class
getDataRowClass()
Returns the class used for rows.DateFormat
getDateFormat()
Returns the date formatter.DateFormat
getDateTimeFormat()
Returns the date/time formatter.DateFormat
getDateTimeMsecFormat()
Returns the date/time msec formatter.SpreadSheet
getHeader()
Returns the a spreadsheet with the same header and comments.HeaderRow
getHeaderRow()
Returns the header row.Locale
getLocale()
Returns the current locale.String
getName()
Returns the name of the spreadsheet.NumberFormat
getNumberFormat()
Returns the number formatter.DataRow
getRow(int rowIndex)
Returns the row at the specified index.DataRow
getRow(String rowKey)
Returns the row associated with the given row key, null if not found.int
getRowCount()
Returns the number of rows currently stored.int
getRowIndex(String rowKey)
Returns the row index of the specified row.String
getRowKey(int rowIndex)
Returns the row key at the specified index.SharedStringsTable
getSharedStringsTable()
Returns the table for shared strings.DateFormat
getTimeFormat()
Returns the time formatter.DateFormat
getTimeMsecFormat()
Returns the time/msec formatter.TimeZone
getTimeZone()
Returns the currently used timezone.boolean
hasCell(int rowIndex, int columnIndex)
Checks whether the cell with the given indices already exists.boolean
hasName()
Returns whether the spreadsheet has a name.boolean
hasRow(int rowIndex)
Returns whether the spreadsheet already contains the row with the given index.boolean
hasRow(String rowKey)
Returns whether the spreadsheet already contains the row with the given key.void
insertColumn(int columnIndex, String header)
Inserts a column at the specified location.void
insertColumn(int columnIndex, String header, String initial)
Inserts a column at the specified location.void
insertColumn(int columnIndex, String header, String initial, boolean forceString)
Inserts a column at the specified location.DataRow
insertRow(int index)
Inserts a row at the specified location.boolean
isContentType(int columnIndex, Cell.ContentType type)
Checks whether the given column is of the specific content type or not.boolean
isDateLenient()
Returns whether the parsing of dates is lenient or not.boolean
isDateTimeLenient()
Returns whether the parsing of date/times is lenient or not.boolean
isDateTimeMsecLenient()
Returns whether the parsing of date/time msecs is lenient or not.boolean
isNumeric(int columnIndex)
Checks whether the given column is numeric or not.boolean
isNumeric(int columnIndex, boolean allowMissing)
Checks whether the given column is numeric or not.boolean
isTimeLenient()
Returns whether the parsing of times is lenient or not.boolean
isTimeMsecLenient()
Returns whether the parsing of times/msec is lenient or not.void
mergeWith(SpreadSheet other)
Puts the content of the provided spreadsheet on the right.Cell
newCell()
Creates a new cell.SpreadSheet
newInstance()
Returns a new instance.boolean
removeColumn(int columnIndex)
Removes the specified column.boolean
removeColumn(String columnKey)
Removes the specified column.boolean
removeMissing()
Removes all cells marked "missing".Row
removeRow(int rowIndex)
Removes the specified row.Row
removeRow(String rowKey)
Removes the specified row.Collection<String>
rowKeys()
Returns a collection of all row keys.Collection<DataRow>
rows()
Returns all rows.void
setDataRowClass(Class cls)
Sets the default data row class to use.void
setDateLenient(boolean value)
Sets whether parsing of dates is to be lenient or not.void
setDateTimeLenient(boolean value)
Sets whether parsing of date/times is to be lenient or not.void
setDateTimeMsecLenient(boolean value)
Sets whether parsing of date/time mses is to be lenient or not.void
setLocale(Locale value)
Sets the locale.void
setName(String value)
Sets the name of the spreadsheet.void
setTimeLenient(boolean value)
Sets whether parsing of times is to be lenient or not.void
setTimeMsecLenient(boolean value)
Sets whether parsing of times/msec is to be lenient or not.void
setTimeZone(TimeZone value)
Sets the timezone to use.void
sort(int index, boolean asc)
Sorts the rows based on the values in the specified column.void
sort(RowComparator comp)
Sorts the rows using the given comparator.void
sort(RowComparator comp, boolean unique)
Sorts the rows using the given comparator.void
sortRowKeys()
Sorts the rows according to the row keys.void
sortRowKeys(Comparator<String> comp)
Sorts the rows according to the row keys.Object[][]
toMatrix()
Returns the spreadsheet as matrix, with the header as the first row.String
toString()
Returns the spreadsheet as string, i.e., CSV formatted.SpreadSheet
toView(int[] rows, int[] columns)
Creates a view of the spreadsheet with the specified rows/columns.
-
-
-
Field Detail
-
COMMENT
static final String COMMENT
the line comment start.- See Also:
- Constant Field Values
-
MISSING_VALUE
static final String MISSING_VALUE
the default missing value.- See Also:
- Constant Field Values
-
-
Method Detail
-
assign
void assign(SpreadSheet sheet)
Clears this spreadsheet and copies all the data from the given one.- Parameters:
sheet
- the data to copy
-
setDataRowClass
void setDataRowClass(Class cls)
Sets the default data row class to use. Must implementDataRow
.- Parameters:
cls
- the class, null resets it to the default one- Throws:
IllegalArgumentException
- if class does not implementDataRow
-
getDataRowClass
Class getDataRowClass()
Returns the class used for rows.- Returns:
- the class
-
newInstance
SpreadSheet newInstance()
Returns a new instance.- Returns:
- the new instance, null if failed to create new instance
-
getClone
SpreadSheet getClone()
Returns a clone of itself.- Specified by:
getClone
in interfaceCloneHandler<SpreadSheet>
- Returns:
- the clone
-
getHeader
SpreadSheet getHeader()
Returns the a spreadsheet with the same header and comments.- Returns:
- the spreadsheet
-
getDateFormat
DateFormat getDateFormat()
Returns the date formatter.- Returns:
- the formatter
- See Also:
DateUtils.getDateFormatter()
-
getDateTimeFormat
DateFormat getDateTimeFormat()
Returns the date/time formatter.- Returns:
- the formatter
- See Also:
DateUtils.getTimestampFormatter()
-
getDateTimeMsecFormat
DateFormat getDateTimeMsecFormat()
Returns the date/time msec formatter.- Returns:
- the formatter
- See Also:
DateUtils.getTimestampFormatterMsecs()
-
getTimeFormat
DateFormat getTimeFormat()
Returns the time formatter.- Returns:
- the formatter
- See Also:
DateUtils.getTimeFormatter()
-
getTimeMsecFormat
DateFormat getTimeMsecFormat()
Returns the time/msec formatter.- Returns:
- the formatter
- See Also:
DateUtils.getTimeFormatterMsecs()
-
getNumberFormat
NumberFormat getNumberFormat()
Returns the number formatter.- Returns:
- the formatter
-
setName
void setName(String value)
Sets the name of the spreadsheet.- Parameters:
value
- the name
-
getName
String getName()
Returns the name of the spreadsheet.- Returns:
- the name, can be null
-
hasName
boolean hasName()
Returns whether the spreadsheet has a name.- Returns:
- true if the spreadsheet is named
-
addComment
void addComment(String comment)
Adds the comment to the internal list of comments. If the comment contains newlines, then it gets automatically split into multiple lines and added one by one.- Parameters:
comment
- the comment to add
-
addComment
void addComment(List<String> comment)
Adds the comments to the internal list of comments.- Parameters:
comment
- the comment to add
-
clear
void clear()
Removes all cells, but leaves comments.
-
getHeaderRow
HeaderRow getHeaderRow()
Returns the header row.- Returns:
- the row
-
getColumnName
String getColumnName(int colIndex)
Returns the name of the specified column.- Parameters:
colIndex
- the index of the column- Returns:
- the name of the column
-
getColumnNames
List<String> getColumnNames()
Returns a list of the names of all columns (i.e., the content the header row cells).- Returns:
- the names of the columns
-
hasRow
boolean hasRow(int rowIndex)
Returns whether the spreadsheet already contains the row with the given index.- Parameters:
rowIndex
- the index to look for- Returns:
- true if the row already exists
-
hasRow
boolean hasRow(String rowKey)
Returns whether the spreadsheet already contains the row with the given key.- Parameters:
rowKey
- the key to look for- Returns:
- true if the row already exists
-
newCell
Cell newCell()
Creates a new cell.- Returns:
- the new instance, null in case of an instantiation error
-
addRow
DataRow addRow()
Appends a row to the spreadsheet.- Returns:
- the created row
-
addRow
DataRow addRow(String rowKey)
Adds a row with the given key to the list and returns the created object. If the row already exists, then this row is returned instead and no new object created.- Parameters:
rowKey
- the key for the row to create- Returns:
- the created row or the already existing row
-
insertRow
DataRow insertRow(int index)
Inserts a row at the specified location.- Parameters:
index
- the index where to insert the row- Returns:
- the created row
-
removeRow
Row removeRow(int rowIndex)
Removes the specified row.- Parameters:
rowIndex
- the row to remove- Returns:
- the row that was removed, null if none removed
-
removeRow
Row removeRow(String rowKey)
Removes the specified row.- Parameters:
rowKey
- the row to remove- Returns:
- the row that was removed, null if none removed
-
insertColumn
void insertColumn(int columnIndex, String header)
Inserts a column at the specified location.- Parameters:
columnIndex
- the position of the columnheader
- the name of the column
-
insertColumn
void insertColumn(int columnIndex, String header, String initial)
Inserts a column at the specified location.- Parameters:
columnIndex
- the position of the columnheader
- the name of the columninitial
- the initial value for the cells, "null" for missing values (in that case no cells are added)
-
insertColumn
void insertColumn(int columnIndex, String header, String initial, boolean forceString)
Inserts a column at the specified location.- Parameters:
columnIndex
- the position of the columnheader
- the name of the columninitial
- the initial value for the cells, "null" for missing values (in that case no cells are added)forceString
- whether to enforce the value to be set as string
-
removeColumn
boolean removeColumn(int columnIndex)
Removes the specified column.- Parameters:
columnIndex
- the column to remove- Returns:
- true if removed
-
removeColumn
boolean removeColumn(String columnKey)
Removes the specified column.- Parameters:
columnKey
- the column to remove- Returns:
- true if removed
-
getRow
DataRow getRow(String rowKey)
Returns the row associated with the given row key, null if not found.- Parameters:
rowKey
- the key of the row to retrieve- Returns:
- the row or null if not found
-
getRow
DataRow getRow(int rowIndex)
Returns the row at the specified index.- Parameters:
rowIndex
- the 0-based index of the row to retrieve- Returns:
- the row
-
getRowKey
String getRowKey(int rowIndex)
Returns the row key at the specified index.- Parameters:
rowIndex
- the 0-based index of the row key to retrieve- Returns:
- the row key
-
getRowIndex
int getRowIndex(String rowKey)
Returns the row index of the specified row.- Parameters:
rowKey
- the row identifier- Returns:
- the 0-based row index, -1 if not found
-
getCellIndex
int getCellIndex(String cellKey)
Returns the cell index of the specified cell (in the header row).- Parameters:
cellKey
- the cell identifier- Returns:
- the 0-based column index, -1 if not found
-
hasCell
boolean hasCell(int rowIndex, int columnIndex)
Checks whether the cell with the given indices already exists.- Parameters:
rowIndex
- the index of the row to look forcolumnIndex
- the index of the cell in the row to look for- Returns:
- true if the cell exists
-
getCell
Cell getCell(int rowIndex, int columnIndex)
Returns the corresponding cell or null if not found.- Parameters:
rowIndex
- the index of the row the cell is incolumnIndex
- the column of the cell to retrieve- Returns:
- the cell or null if not found
-
getCellPosition
String getCellPosition(String rowKey, String cellKey)
Returns the position of the cell or null if not found. A position is a combination of a number of letters (for the column) and number (for the row).- Parameters:
rowKey
- the key of the row the cell is incellKey
- the key of the cell to retrieve- Returns:
- the position string or null if not found
-
rowKeys
Collection<String> rowKeys()
Returns a collection of all row keys.- Returns:
- the row keys
-
rows
Collection<DataRow> rows()
Returns all rows.- Returns:
- the rows
-
sortRowKeys
void sortRowKeys()
Sorts the rows according to the row keys.- See Also:
rowKeys()
-
sortRowKeys
void sortRowKeys(Comparator<String> comp)
Sorts the rows according to the row keys.- Parameters:
comp
- the comparator to use- See Also:
rowKeys()
-
sort
void sort(int index, boolean asc)
Sorts the rows based on the values in the specified column.
NB: the row keys will change!- Parameters:
index
- the index (0-based) of the column to sort onasc
- wether sorting is ascending or descending- See Also:
sort(RowComparator)
-
sort
void sort(RowComparator comp)
Sorts the rows using the given comparator.
NB: the row keys will change!- Parameters:
comp
- the row comparator to use
-
sort
void sort(RowComparator comp, boolean unique)
Sorts the rows using the given comparator.
NB: the row keys will change!- Parameters:
comp
- the row comparator to useunique
- whether to drop any duplicate rows (based on row comparator)
-
getColumnCount
int getColumnCount()
Returns the number of columns.- Returns:
- the number of columns
-
getRowCount
int getRowCount()
Returns the number of rows currently stored.- Returns:
- the number of rows
-
isNumeric
boolean isNumeric(int columnIndex)
Checks whether the given column is numeric or not. Does not accept missing values.- Parameters:
columnIndex
- the index of the column to check- Returns:
- true if purely numeric
- See Also:
getContentTypes(int)
-
isNumeric
boolean isNumeric(int columnIndex, boolean allowMissing)
Checks whether the given column is numeric or not. Can accept missing values.- Parameters:
columnIndex
- the index of the column to check- Returns:
- true if purely numeric
- See Also:
getContentTypes(int)
-
isContentType
boolean isContentType(int columnIndex, Cell.ContentType type)
Checks whether the given column is of the specific content type or not.- Parameters:
columnIndex
- the index of the column to checktype
- the content type to check- Returns:
- true if column purely consists of this content type
- See Also:
getContentType(int)
-
getContentType
Cell.ContentType getContentType(int columnIndex)
Returns the pure content type of the given column, if available.- Parameters:
columnIndex
- the index of the column to check- Returns:
- the content type that this column consists of solely, null if mixed
-
getContentTypes
Collection<Cell.ContentType> getContentTypes(int columnIndex)
Returns the all content types of the given column, if available.- Parameters:
columnIndex
- the index of the column to check- Returns:
- the content types that this column consists of
-
getCellValues
List<String> getCellValues(String colKey)
Returns the unique string values of the specified column. The returned list is sorted.- Parameters:
colKey
- the column to retrieve the values for- Returns:
- the sorted, list of unique values
-
getCellValues
List<String> getCellValues(int colIndex)
Returns the unique string values of the specified column. The returned list is sorted.- Parameters:
colIndex
- the column to retrieve the values for- Returns:
- the sorted, list of unique values
-
equalsHeader
String equalsHeader(SpreadSheet other)
Compares the header of this spreadsheet with the other one.- Parameters:
other
- the other spreadsheet to compare with- Returns:
- null if equal, otherwise details what differs
-
toString
String toString()
Returns the spreadsheet as string, i.e., CSV formatted.
-
toMatrix
Object[][] toMatrix()
Returns the spreadsheet as matrix, with the header as the first row. Missing values are represented as null values.- Returns:
- the row-wise matrix
-
removeMissing
boolean removeMissing()
Removes all cells marked "missing".- Returns:
- true if any cell was removed
-
getSharedStringsTable
SharedStringsTable getSharedStringsTable()
Returns the table for shared strings.- Returns:
- the table
-
setDateLenient
void setDateLenient(boolean value)
Sets whether parsing of dates is to be lenient or not.- Parameters:
value
- if true lenient parsing is used, otherwise not- See Also:
DateFormat.setLenient(boolean)
-
isDateLenient
boolean isDateLenient()
Returns whether the parsing of dates is lenient or not.- Returns:
- true if parsing is lenient
- See Also:
DateFormat.isLenient()
-
setDateTimeLenient
void setDateTimeLenient(boolean value)
Sets whether parsing of date/times is to be lenient or not.- Parameters:
value
- if true lenient parsing is used, otherwise not- See Also:
DateFormat.setLenient(boolean)
-
isDateTimeLenient
boolean isDateTimeLenient()
Returns whether the parsing of date/times is lenient or not.- Returns:
- true if parsing is lenient
- See Also:
DateFormat.isLenient()
-
setDateTimeMsecLenient
void setDateTimeMsecLenient(boolean value)
Sets whether parsing of date/time mses is to be lenient or not.- Parameters:
value
- if true lenient parsing is used, otherwise not- See Also:
DateFormat.setLenient(boolean)
-
isDateTimeMsecLenient
boolean isDateTimeMsecLenient()
Returns whether the parsing of date/time msecs is lenient or not.- Returns:
- true if parsing is lenient
- See Also:
DateFormat.isLenient()
-
setTimeLenient
void setTimeLenient(boolean value)
Sets whether parsing of times is to be lenient or not.- Parameters:
value
- if true lenient parsing is used, otherwise not
-
isTimeLenient
boolean isTimeLenient()
Returns whether the parsing of times is lenient or not.- Returns:
- true if parsing is lenient
-
setTimeMsecLenient
void setTimeMsecLenient(boolean value)
Sets whether parsing of times/msec is to be lenient or not.- Parameters:
value
- if true lenient parsing is used, otherwise not
-
isTimeMsecLenient
boolean isTimeMsecLenient()
Returns whether the parsing of times/msec is lenient or not.- Returns:
- true if parsing is lenient
-
setTimeZone
void setTimeZone(TimeZone value)
Sets the timezone to use.- Parameters:
value
- the new timezone- See Also:
DateFormat.setTimeZone(TimeZone)
-
getTimeZone
TimeZone getTimeZone()
Returns the currently used timezone.- Returns:
- the current timezone
- See Also:
DateFormat.getTimeZone()
-
setLocale
void setLocale(Locale value)
Sets the locale. Used in formatting/parsing numbers.- Specified by:
setLocale
in interfaceLocaleSupporter
- Parameters:
value
- the locale to use
-
getLocale
Locale getLocale()
Returns the current locale.- Specified by:
getLocale
in interfaceLocaleSupporter
- Returns:
- the locale
-
calculate
void calculate()
Triggers all formula cells to recalculate their values.
-
mergeWith
void mergeWith(SpreadSheet other)
Puts the content of the provided spreadsheet on the right.- Specified by:
mergeWith
in interfaceMergeable<SpreadSheet>
- Parameters:
other
- the spreadsheet to merge with
-
toView
SpreadSheet toView(int[] rows, int[] columns)
Creates a view of the spreadsheet with the specified rows/columns.- Parameters:
columns
- the columns to use, null for allrows
- the rows to use, null for all
-
-