Package jmri.jmrit.logixng
Interface Table
-
- All Known Subinterfaces:
AnonymousTable
,NamedTable
- All Known Implementing Classes:
AbstractNamedTable
,DefaultAnonymousTable
,DefaultCsvNamedTable
,DefaultInternalNamedTable
public interface Table
Represent a Table. A table is a two dimensional array where the rows and columns may have names.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Table.ColumnNotFoundException
static class
Table.CsvType
The available types of CSV from which to load a table The default is TABBED, as that was previously the only choice TABBED results in parsing the CSV file with tabs as the delimiters COMMA uses csvFormat of RFC-4180, which is the standard Comma Seperated Value format, but does not allow empty linesstatic class
Table.RowNotFoundException
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.lang.Object
getCell(int row)
Get the value of a cell.java.lang.Object
getCell(int row, int column)
Get the value of a cell.default java.lang.Object
getCell(java.lang.String row)
Get the value of a cell.default java.lang.Object
getCell(java.lang.String row, java.lang.String column)
Get the value of a cell.int
getColumnNumber(java.lang.String columnName)
Get the row number by name of row.default Table.CsvType
getCsvType()
int
getRowNumber(java.lang.String rowName)
Get the row number by name of row.default boolean
isCsvTypeSupported()
int
numColumns()
Get the number of columns in the table.int
numRows()
Get the number of rows in the table.void
setCell(java.lang.Object value, int row, int column)
Get the value of a cell.default void
setCell(java.lang.Object value, java.lang.String row)
Set the value of a cell.default void
setCell(java.lang.Object value, java.lang.String row, java.lang.String column)
Set the value of a cell.default void
setCsvType(Table.CsvType csvType)
void
storeTableAsCSV(java.io.File file)
Store the table to a CSV file.void
storeTableAsCSV(java.io.File file, java.lang.String systemName, java.lang.String userName)
Store the table to a CSV file.
-
-
-
Method Detail
-
getCell
@CheckReturnValue default java.lang.Object getCell(int row)
Get the value of a cell. If the table has both rows and columns, the value of the first column will be returned.- Parameters:
row
- the row of the cell or null if all rows should be returned- Returns:
- the value of the cell
-
getCell
@CheckReturnValue java.lang.Object getCell(int row, int column)
Get the value of a cell.- Parameters:
row
- the row of the cellcolumn
- the column of the cell- Returns:
- the value of the cell
-
getCell
@CheckReturnValue default java.lang.Object getCell(@Nonnull java.lang.String row) throws Table.RowNotFoundException
Get the value of a cell. If the table has both rows and columns, the value of the first column will be returned.- Parameters:
row
- the row of the cell or null if all rows should be returned- Returns:
- the value of the cell
- Throws:
Table.RowNotFoundException
- if the row is not found
-
getCell
default java.lang.Object getCell(@Nonnull java.lang.String row, @Nonnull java.lang.String column) throws Table.RowNotFoundException, Table.ColumnNotFoundException
Get the value of a cell.- Parameters:
row
- the row of the cell. If this string is a name of a row, that row is used. If it's not a name of a row, but an integer value, that index is used, where row 0 is the name of the row.column
- the column of the cell. If this string is a name of a column, that column is used. If it's not a name of a column, but an integer value, that index is used, where column 0 is the name of the column.- Returns:
- the value of the cell
- Throws:
Table.RowNotFoundException
- if the row is not foundTable.ColumnNotFoundException
- if the column is not found
-
setCell
@CheckReturnValue void setCell(java.lang.Object value, int row, int column)
Get the value of a cell.- Parameters:
value
- the new value of the cellrow
- the row of the cellcolumn
- the column of the cell
-
setCell
default void setCell(java.lang.Object value, java.lang.String row) throws Table.RowNotFoundException
Set the value of a cell. If the table has both rows and columns, the value of the first column will be returned.- Parameters:
value
- the new value of the cellrow
- the row of the cell- Throws:
Table.RowNotFoundException
- if the row is not found
-
setCell
default void setCell(java.lang.Object value, java.lang.String row, java.lang.String column) throws Table.RowNotFoundException, Table.ColumnNotFoundException
Set the value of a cell.- Parameters:
value
- the new value of the cellrow
- the row of the cell. If this string is a name of a row, that row is used. If it's not a name of a row, but an integer value, that index is used, where row 0 is the name of the row.column
- the column of the cell. If this string is a name of a column, that column is used. If it's not a name of a column, but an integer value, that index is used, where column 0 is the name of the column.- Throws:
Table.RowNotFoundException
- if the row is not foundTable.ColumnNotFoundException
- if the column is not found
-
numRows
int numRows()
Get the number of rows in the table.- Returns:
- the number of rows
-
numColumns
int numColumns()
Get the number of columns in the table.- Returns:
- the number of columns
-
getRowNumber
int getRowNumber(java.lang.String rowName) throws Table.RowNotFoundException
Get the row number by name of row.- Parameters:
rowName
- the name of the row. If there is no row with this name, and rowName is a positive integer, that row number will be returned.- Returns:
- the row number
- Throws:
Table.RowNotFoundException
- if the row is not found
-
getColumnNumber
int getColumnNumber(java.lang.String columnName) throws Table.ColumnNotFoundException
Get the row number by name of row.- Parameters:
columnName
- the name of the column. If there is no column with this name, and columnName is a positive integer, that column number will be returned.- Returns:
- the column number
- Throws:
Table.ColumnNotFoundException
- if the column is not found
-
isCsvTypeSupported
default boolean isCsvTypeSupported()
-
setCsvType
default void setCsvType(Table.CsvType csvType)
-
getCsvType
default Table.CsvType getCsvType()
-
storeTableAsCSV
void storeTableAsCSV(@Nonnull java.io.File file) throws java.io.FileNotFoundException
Store the table to a CSV file.- Parameters:
file
- the CSV file- Throws:
java.io.FileNotFoundException
- if file not found
-
storeTableAsCSV
void storeTableAsCSV(@Nonnull java.io.File file, @CheckForNull java.lang.String systemName, @CheckForNull java.lang.String userName) throws java.io.FileNotFoundException
Store the table to a CSV file. If system name and/or user name is not null, these values are used instead of the tables own system name and user name. If no system name and user name is given and the table is anonymous, no system name and user name is stored in the file.- Parameters:
file
- the CSV filesystemName
- the system name of the tableuserName
- the user name of the table- Throws:
java.io.FileNotFoundException
- if file not found
-
-