T - type of table records. Should be POJO class with at least one field annotated with
GSheetTable.public class Table<T> extends Object implements Iterable<T>
The table is defined by its header bounds (headers top row, left column, bottom row and right column) and the index of the last row (bottom row). If bottom row is not specified then table ends at the last row of the sheet.
The content of table is represented with list of records. Record is an instance of POJO class where some fields are
mapped to corresponding table columns using GSheetTable
annotations. Each record corresponds to specific row of the table and indexed (0-based) starting with the row right
below the header bottom row.
GSheetColumn,
GSheetCellStyle| Modifier | Constructor and Description |
|---|---|
protected |
Table(Sheet parent,
int headerTopRow,
int headerLeftCol,
int headerBottomRow,
int headerRightCol,
Class<T> recordType)
Creates a new instance of table that is defined by existing cells range on specified sheet.
|
protected |
Table(Sheet parent,
int topRow,
int leftCol,
List<T> records)
Builds a new table on the given sheet at position defined by
topRow and leftCol
(top-left cell of the table). |
| Modifier and Type | Method and Description |
|---|---|
void |
addRecord(T record)
Adds a new record at the end of this table.
|
void |
addRecords(List<T> records)
Adds list of records at the end of this table.
|
void |
clearCache()
Clears records cache.
|
T |
findRecord(Predicate<T> isSatisfy)
Iterates over all records starting from the first till the moment when
isSatisfy is return
true for some record. |
int |
findRecordIndex(Predicate<T> isSatisfy)
Iterates over all records starting from the first till the moment when
isSatisfy is return
true for some record. |
int |
getBottomRow()
Gets index of the last row of this table.
|
Map<String,Integer> |
getColumnNameToIndexMap()
Gets map that maps column titles to its ordering number (0-based).
|
int |
getHeaderBottomRow()
Gets index of the bottom row of this table header.
|
int |
getHeaderLeftCol()
Gets index of the left column of this table header.
|
int |
getHeaderRightCol()
Gets index of the right column of this table header.
|
int |
getHeaderTopRow()
Gets index of the top row of this table header.
|
T |
getRecord(int index)
Gets specific record by its index.
|
List<T> |
getRecords()
Gets full list of records that are contained in this table.
|
int |
getRecordsCount()
Gets amount of records that contained in this table.
|
Sheet |
getSheet()
Gets parent sheet.
|
int |
indexOf(T record)
Gets index of given record.
|
void |
insertRecord(InsertMethod method,
int recordIndex,
T record)
Inserts new record into this table at given position.
|
void |
insertRecord(InsertMethod method,
T relatedRecord,
T record)
Inserts new record into this table at given position.
|
void |
insertRecords(InsertMethod method,
int recordIndex,
List<T> records)
Inserts list of records into this table at given position.
|
void |
insertRecords(InsertMethod method,
T relatedRecord,
List<T> records)
Inserts list of records into this table at given position.
|
Iterator<T> |
iterator()
Gets an iterator of records contained in this table.
|
void |
removeRecord(T record)
Removes given record and corresponding row from this table.
|
void |
removeRecords(List<T> records)
Removes given records and corresponding rows from this table.
|
void |
setBottomRow(int bottomRowIndex)
Sets index of the last row of this table explicitly.
|
void |
setHeaderBottomRow(int bottomRowIndex)
Sets new index of the bottom row of this table header.
|
void |
setHeaderLeftCol(int leftColIndex)
Sets new index of the left column of this table header.
|
void |
setHeaderRightCol(int rightColIndex)
Sets new index of the right column of this table header.
|
void |
setHeaderTopRow(int topRowIndex)
Sets new index of the top row of this table header.
|
void |
trimLeadingAndTrailingSpaces()
Analyzes content of leading and trailing columns and if these columns are empty shifts indexes of left and
right columns to exclude them from this table bounds.
|
void |
updateRecord(T record)
Transfers changes that have been done within given record to corresponding row of the sheet.
|
void |
updateRecords(List<T> records)
Transfers changes that have been done within given records to corresponding rows of the sheet.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorprotected Table(Sheet parent, int topRow, int leftCol, List<T> records)
topRow and leftCol
(top-left cell of the table).parent - parent sheet where the table should be placed.topRow - 0-based index of row that defines top-left cell of the table.leftCol - 0-based index of column that defines top-left cell of the table.records - list of records to insert into the table after creation. Also this list provides information
about type of records with meta-information is necessary for table construction.
That's why this list should not be empty.protected Table(Sheet parent, int headerTopRow, int headerLeftCol, int headerBottomRow, int headerRightCol, Class<T> recordType)
parent - the parent sheet where this table is located.headerTopRow - 0-based index of table header top row.headerLeftCol - 0-based index of table left column.headerBottomRow - 0-based index of table header bottom row.headerRightCol - 0-based index of table right column.recordType - class instance of records that this table should works with.public Sheet getSheet()
public int getHeaderTopRow()
public void setHeaderTopRow(int topRowIndex)
topRowIndex - the new index of the top row to set.public int getHeaderLeftCol()
public void setHeaderLeftCol(int leftColIndex)
leftColIndex - the new index of the left column to set.public int getHeaderBottomRow()
public void setHeaderBottomRow(int bottomRowIndex)
bottomRowIndex - the new index of the bottom row to set.public int getHeaderRightCol()
public void setHeaderRightCol(int rightColIndex)
rightColIndex - the new index of the right column to set.public int getBottomRow()
If the bottom row is not specified explicitly this method returns the actual index of the last row of parent sheet.
public void setBottomRow(int bottomRowIndex)
It's necessary to use when the table ends earlier than the last row of the parent sheet. Once this bottom row index is specified it will be automatically corrected during adding, inserting or removing records.
bottomRowIndex - 0-based index of the row that should be the last row of this table.public Map<String,Integer> getColumnNameToIndexMap()
It's necessary to properly map table records to corresponding row data and vice versa.
public List<T> getRecords()
public T getRecord(int index)
Records are indexed starting with the row right below the header bottom row.
index - 0-based index of the record to get.null if record at such index is not exist.public T findRecord(Predicate<T> isSatisfy)
isSatisfy is return
true for some record.isSatisfy - lambda expression that accepts instance of each record and should return true
if the record satisfies to some condition.isSatisfy returned true or null
if there are no such records.public int findRecordIndex(Predicate<T> isSatisfy)
isSatisfy is return
true for some record.isSatisfy - lambda expression that accepts instance of each record and should return true
if the record satisfies to some condition.isSatisfy returned true or -1
if there are no such records.public int indexOf(T record)
record - instance of record to lookup.-1 if record does not belong to this table.public int getRecordsCount()
public void addRecord(T record)
The record will be converted to corresponding row data based on information specified within
GSheetColumn annotations. These annotations
also provide styling information that is applied after row adding.
record - the record to add.public void addRecords(List<T> records)
Each record will be converted to corresponding row data based on information specified within
GSheetColumn annotations. These annotations
also provide styling information that is applied after rows adding.
records - list of records to add.public void insertRecord(InsertMethod method, T relatedRecord, T record)
The record will be converted to corresponding row data based on information specified within
GSheetColumn annotations. These annotations
also provide styling information that is applied after row inserting.
method - defines position for insertion relatively to record specified by relatedRecord.relatedRecord - the record that identifies position for insertion.record - the record to insert.public void insertRecord(InsertMethod method, int recordIndex, T record)
The record will be converted to corresponding row data based on information specified within
GSheetColumn annotations. These annotations
also provide styling information that is applied after row inserting.
method - defines position for insertion relatively to record index specified by recordIndex.recordIndex - the index of record that identifies position for insertion.record - the record to insert.public void insertRecords(InsertMethod method, T relatedRecord, List<T> records)
Each record will be converted to corresponding row data based on information specified within
GSheetColumn annotations. These annotations
also provide styling information that is applied after rows inserting.
method - defines position for insertion relatively to record specified by relatedRecord.relatedRecord - the record that identifies position for insertion.records - list of records to insert.public void insertRecords(InsertMethod method, int recordIndex, List<T> records)
Each record will be converted to corresponding row data based on information specified within
GSheetColumn annotations. These annotations
also provide styling information that is applied after rows inserting.
method - defines position for insertion relatively to record index specified by recordIndex.recordIndex - the index of record that identifies position for insertion.records - list of records to insert.public void updateRecord(T record)
record - the record to update.public void updateRecords(List<T> records)
records - list of records to update.public void removeRecord(T record)
Do nothing if the record is null or does not belong to this table.
record - the record to remove.public void removeRecords(List<T> records)
records - list of records to remove. Do nothing if this list is null.public void clearCache()
public void trimLeadingAndTrailingSpaces()
Copyright © 2022. All rights reserved.