Table¶
Definition¶
Extends¶
Extended By¶
None
Description¶
Represents a 2-dimensional data structure with a predefined set of uniquely named, ordered columns. It also has a variant number of rows (see Row).
Method Summary¶
Owner | Name | Return Type | Description |
---|---|---|---|
Table | constructor(title) | Object | Creates a new table given the title. |
Table | constructor(title, map_of_lists) | Object | Creates a new table given the title and a map of lists. |
Table | constructor(title, columnsDefition) | Object | Creates a new table given the title and the column definitions. |
Table | constructor(table) | Object | Copy constructor for creating a new table. |
Table | addColumn(columnName, columnType, DefaultValue) | Object | Adds a new columns with the specified name, type and default value. |
Table | addRow(params) | Row | Adds and returns the new row given an object that contains the row data. |
Table | addRow(list) | Row | Adds and returns the new row given a list of row data. |
Table | alterColumn(currentColumnName, newColumnName, newTypeOrNull) | String | Changes the column's name and/or type. Returns null on success or error message on failure. When changing the type, auto-casting will be used. |
Object | getClassName() | String | Returns the string name of this object's class type. |
Table | getColumnLocation(columnName) | Integer | Returns 0-indexed column position, or -1 if column does not exist in the table. |
Table | getColumnNameAt(columnPos) | String | Returns name of column, or null if the supplied index is outside of the column count. |
Table | getColumnNames() | List | Return a list of the names of the columns, ordered from left to right. |
Table | getColumnType(columnName) | String | Returns the type of a column, or null if column doesn't exist. |
Table | getColumnTypes() | Map | Returns a map of the name of the columns, ordered from left to right. |
Table | getColumnsCount() | Integer | Returns the number of columns in this table. |
Table | getRow(rowNum) | Row | Returns the row at the zero indexed location, or null. |
Table | getRows() | List | Return a list of rows in this table. |
Table | getRowsCount() | Integer | Returns the number of rows in this table. |
Table | getTitle() | String | Returns the title of this table, or null if no title. |
Table | getValue(rowNum, columnName) | Object | Returns the value associated with the given key and value. Returns null if column does not exist or row number is out of bounds. |
Table | insertRow(rowPosition, params) | Object | Inserts and returns the new row given its position and an object that contains the data. |
Table | insertRow(rowPosition, list) | Object | Inserts and returns the new row given its position and a list of data. |
Table | isEqual(tableToCompare, ignoreRowOrdering, ignoreColumnOrdering) | Boolean | Returns the boolean flag whether two tables are considered equivalent based on the method aruments. Note that if two tables have different row counts or different schemas (column name + column type), this method will return false immediately |
Table | iterator() | Iterator | Returns an iterator of Row objects. |
Table | query(amiSql) | Table | Runs the given amisql on this table. Use 'this' to reference this table in the amisql. Returns the resulting table. |
Table | removeColumn(columnName) | Boolean | Removes a column by specifying the its name. Returns true if the table changed as a result. |
Table | removeRow(rowPosition) | Object | Removes and returns the row given its index position. |
Table | setTitle(titleName) | Object | Sets the title of this table with the given string. |
Table | toCsv(includeColumnNames) | String | Returns a comma seperated values formatter string of this table. |
Table | toJson() | String | Returns a json of this table as a list of maps, where each map represents a row in the table. |
Table | toList(columnName) | List | Return a list of values for a particular column, or null if the column does not exist. Empty tables will return an empty list. |
Table | toSet(columnName) | Set | Returns a set of values for a particular column, or null if the column does not exist. Empty tables will return an empty set. |
Table | toString(rowDelim, colDelim, options) | String | Return a string representing this table. |
Method Definitions¶
constructor(title)¶
Table table = new Table(String title)
Description¶
Creates a new table given the title.
Parameter Definition¶
Name | Type | Description |
---|---|---|
title | String | title name |
constructor(title,map_of_lists)¶
Table table = new Table(String title, Map map_of_lists)
Description¶
Creates a new table given the title and a map of lists.
Parameter Definition¶
Name | Type | Description |
---|---|---|
title | String | title name |
map_of_lists | Map | Map of lists where key will be the column name and value is a list of values, all lists must be same length |
constructor(title,columnsDefition)¶
Table table = new Table(String title, String columnsDefition)
Description¶
Creates a new table given the title and the column definitions.
Parameter Definition¶
Name | Type | Description |
---|---|---|
title | String | title name |
columnsDefition | String | name type,name type,name type... |
constructor(table)¶
Table table = new Table(Table table)
Description¶
Copy constructor for creating a new table.
Parameter Definition¶
Name | Type | Description |
---|---|---|
table | Table | table to copy |
addColumn(columnName,columnType,DefaultValue)¶
Object Table::addColumn(String columnName, String columnType, Object DefaultValue)
Description¶
Adds a new columns with the specified name, type and default value.
Parameter Definition¶
Name | Type | Description |
---|---|---|
columnName | String | |
columnType | String | |
DefaultValue | Object | default value for existing columns or null |
addRow(params)¶
Row Table::addRow(Object ... params)
Description¶
Adds and returns the new row given an object that contains the row data.
Parameter Definition¶
Name | Type | Description |
---|---|---|
params | Object ... | object that contains the data |
addRow(list)¶
Description¶
Adds and returns the new row given a list of row data.
Parameter Definition¶
Name | Type | Description |
---|---|---|
list | List | list of params |
alterColumn(currentColumnName,newColumnName,newTypeOrNull)¶
String Table::alterColumn(String currentColumnName, String newColumnName, String newTypeOrNull)
Description¶
Changes the column's name and/or type. Returns null on success or error message on failure. When changing the type, auto-casting will be used.
Parameter Definition¶
Name | Type | Description |
---|---|---|
currentColumnName | String | name of existing column to alter |
newColumnName | String | the new name of the column |
newTypeOrNull | String | The type of the column, if null then the type is not changed |
getColumnLocation(columnName)¶
Integer Table::getColumnLocation(String columnName)
Description¶
Returns 0-indexed column position, or -1 if column does not exist in the table.
Parameter Definition¶
Name | Type | Description |
---|---|---|
columnName | String | column name |
getColumnNameAt(columnPos)¶
String Table::getColumnNameAt(Integer columnPos)
Description¶
Returns name of column, or null if the supplied index is outside of the column count.
Parameter Definition¶
Name | Type | Description |
---|---|---|
columnPos | Integer | zero column position |
getColumnNames()¶
Description¶
Return a list of the names of the columns, ordered from left to right.
getColumnType(columnName)¶
String Table::getColumnType(String columnName)
Description¶
Returns the type of a column, or null if column doesn't exist.
Parameter Definition¶
Name | Type | Description |
---|---|---|
columnName | String | name of the column to get the type for |
getColumnTypes()¶
Description¶
Returns a map of the name of the columns, ordered from left to right.
getColumnsCount()¶
Integer Table::getColumnsCount()
Description¶
Returns the number of columns in this table.
getRow(rowNum)¶
Row Table::getRow(Integer rowNum)
Description¶
Returns the row at the zero indexed location, or null.
Parameter Definition¶
Name | Type | Description |
---|---|---|
rowNum | Integer | zero-indexed row number, negative to start at end |
getRows()¶
Description¶
Return a list of rows in this table.
getRowsCount()¶
Description¶
Returns the number of rows in this table.
getTitle()¶
Description¶
Returns the title of this table, or null if no title.
getValue(rowNum,columnName)¶
Object Table::getValue(Integer rowNum, String columnName)
Description¶
Returns the value associated with the given key and value. Returns null if column does not exist or row number is out of bounds.
Parameter Definition¶
Name | Type | Description |
---|---|---|
rowNum | Integer | zero indexed row number |
columnName | String | name of column |
insertRow(rowPosition,params)¶
Object Table::insertRow(Integer rowPosition, Object ... params)
Description¶
Inserts and returns the new row given its position and an object that contains the data.
Parameter Definition¶
Name | Type | Description |
---|---|---|
rowPosition | Integer | 0 index row position |
params | Object ... | an object that contains the data |
insertRow(rowPosition,list)¶
Object Table::insertRow(Integer rowPosition, List list)
Description¶
Inserts and returns the new row given its position and a list of data.
Parameter Definition¶
Name | Type | Description |
---|---|---|
rowPosition | Integer | 0 index row position |
list | List | list of params |
isEqual(tableToCompare,ignoreRowOrdering,ignoreColumnOrdering)¶
Boolean Table::isEqual(Table tableToCompare, Boolean ignoreRowOrdering, Boolean ignoreColumnOrdering)
Description¶
Returns the boolean flag whether two tables are considered equivalent based on the method aruments. Note that if two tables have different row counts or different schemas (column name + column type), this method will return false immediately
Parameter Definition¶
Name | Type | Description |
---|---|---|
tableToCompare | Table | table to compare with |
ignoreRowOrdering | Boolean | whether to ignore row ordering |
ignoreColumnOrdering | Boolean | whether to ignore column ordering |
iterator()¶
Description¶
Returns an iterator of Row objects.
query(amiSql)¶
Table Table::query(String amiSql)
Description¶
Runs the given amisql on this table. Use 'this' to reference this table in the amisql. Returns the resulting table.
Parameter Definition¶
Name | Type | Description |
---|---|---|
amiSql | String | amiSql to run |
removeColumn(columnName)¶
Boolean Table::removeColumn(String columnName)
Description¶
Removes a column by specifying the its name. Returns true if the table changed as a result.
Parameter Definition¶
Name | Type | Description |
---|---|---|
columnName | String | name of column to remove |
removeRow(rowPosition)¶
Object Table::removeRow(Integer rowPosition)
Description¶
Removes and returns the row given its index position.
Parameter Definition¶
Name | Type | Description |
---|---|---|
rowPosition | Integer | 0-index row position |
setTitle(titleName)¶
Object Table::setTitle(String titleName)
Description¶
Sets the title of this table with the given string.
Parameter Definition¶
Name | Type | Description |
---|---|---|
titleName | String | new title name |
toCsv(includeColumnNames)¶
String Table::toCsv(Boolean includeColumnNames)
Description¶
Returns a comma seperated values formatter string of this table.
Parameter Definition¶
Name | Type | Description |
---|---|---|
includeColumnNames | Boolean | Should the csv's first row be the column names |
toJson()¶
Description¶
Returns a json of this table as a list of maps, where each map represents a row in the table.
toList(columnName)¶
List Table::toList(String columnName)
Description¶
Return a list of values for a particular column, or null if the column does not exist. Empty tables will return an empty list.
Parameter Definition¶
Name | Type | Description |
---|---|---|
columnName | String | name of column to get values for |
toSet(columnName)¶
Set Table::toSet(String columnName)
Description¶
Returns a set of values for a particular column, or null if the column does not exist. Empty tables will return an empty set.
Parameter Definition¶
Name | Type | Description |
---|---|---|
columnName | String | name of column to get values for |
toString(rowDelim,colDelim,options)¶
String Table::toString(String rowDelim, String colDelim, String ... options)
Description¶
Return a string representing this table.
Parameter Definition¶
Name | Type | Description |
---|---|---|
rowDelim | String | delimiter to seperate rows, default is line return |
colDelim | String | delimiter to seperate values, default is comma |
options | String ... | any combination of: INCLUDE_HEADER, INCLUDE_TYPES, INCLUDE_TITLE, SKIP_ROWS |