diff --git a/pom.xml b/pom.xml index 7405ca6..5464af8 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ org.spacious-team table-wrapper-api - 2022.2 + 2022.4 jar Table Wrapper API @@ -56,14 +56,14 @@ org.projectlombok lombok - 1.18.18 + 1.18.22 provided true org.slf4j slf4j-api - 1.7.30 + 1.7.36 provided diff --git a/src/main/java/org/spacious_team/table_wrapper/api/AbstractTable.java b/src/main/java/org/spacious_team/table_wrapper/api/AbstractTable.java index de00cc3..e6ed686 100644 --- a/src/main/java/org/spacious_team/table_wrapper/api/AbstractTable.java +++ b/src/main/java/org/spacious_team/table_wrapper/api/AbstractTable.java @@ -231,6 +231,16 @@ public TableRow next() { @Override public TableRow findRow(Object value) { TableCellAddress address = reportPage.find(value); + return getMutableTableRow(address); + } + + @Override + public TableRow findRowByPrefix(String prefix) { + TableCellAddress address = reportPage.findByPrefix(prefix); + return getMutableTableRow(address); + } + + private MutableTableRow getMutableTableRow(TableCellAddress address) { if (tableRange.contains(address)) { MutableTableRow tableRow = new MutableTableRow<>(this, getCellDataAccessObject()); tableRow.setRow(reportPage.getRow(address.getRow())); diff --git a/src/main/java/org/spacious_team/table_wrapper/api/MutableTableRow.java b/src/main/java/org/spacious_team/table_wrapper/api/MutableTableRow.java index 5c8f345..d5dc9e3 100644 --- a/src/main/java/org/spacious_team/table_wrapper/api/MutableTableRow.java +++ b/src/main/java/org/spacious_team/table_wrapper/api/MutableTableRow.java @@ -65,8 +65,8 @@ public int getLastCellNum() { } @Override - public boolean rowContains(Object value) { - return row.rowContains(value); + public boolean rowContains(Object expected) { + return row.rowContains(expected); } @Override diff --git a/src/main/java/org/spacious_team/table_wrapper/api/ReportPage.java b/src/main/java/org/spacious_team/table_wrapper/api/ReportPage.java index 2453f68..16192fb 100644 --- a/src/main/java/org/spacious_team/table_wrapper/api/ReportPage.java +++ b/src/main/java/org/spacious_team/table_wrapper/api/ReportPage.java @@ -18,64 +18,149 @@ package org.spacious_team.table_wrapper.api; -import java.util.function.BiPredicate; +import java.util.function.Predicate; -public interface ReportPage { +import static org.spacious_team.table_wrapper.api.ReportPageHelper.getCellStringValueIgnoreCasePrefixPredicate; - BiPredicate CELL_STRING_STARTS_WITH = (cell, searchingValue) -> - searchingValue != null && cell.trim().toLowerCase().startsWith(searchingValue.toString().trim().toLowerCase()); +public interface ReportPage { /** - * @return table table cell address or {@link TableCellAddress#NOT_FOUND} + * Finds cell address containing exact value. + * + * @return cell address or {@link TableCellAddress#NOT_FOUND} */ default TableCellAddress find(Object value) { return find(value, 0); } /** - * @return table table cell address or {@link TableCellAddress#NOT_FOUND} + * Finds cell address containing exact value. + * + * @param startRow search rows start from this + * @return cell address or {@link TableCellAddress#NOT_FOUND} */ default TableCellAddress find(Object value, int startRow) { return find(value, startRow, Integer.MAX_VALUE); } /** + * Finds cell address containing exact value. + * * @param startRow search rows start from this * @param endRow search rows excluding this, can handle values greater than real rows count - * @return table table cell address or {@link TableCellAddress#NOT_FOUND} + * @return cell address or {@link TableCellAddress#NOT_FOUND} */ default TableCellAddress find(Object value, int startRow, int endRow) { - return find(value, startRow, endRow, ReportPage.CELL_STRING_STARTS_WITH); + return find(value, startRow, endRow, 0, Integer.MAX_VALUE); + } + + /** + * Finds cell address containing exact value. + * + * @param value searching value + * @param startRow search rows start from this + * @param endRow search rows excluding this, can handle values greater than real rows count + * @param startColumn search columns start from this + * @param endColumn search columns excluding this, can handle values greater than real columns count + * @return cell address or {@link TableCellAddress#NOT_FOUND} + */ + TableCellAddress find(Object value, int startRow, int endRow, int startColumn, int endColumn); + + /** + * Finds cell by predicate. + * + * @param cellValuePredicate predicate for testing cell value + * @return cell address or {@link TableCellAddress#NOT_FOUND} + */ + default TableCellAddress find(Predicate cellValuePredicate) { + return find(0, cellValuePredicate); } /** - * @param startRow search rows start from this - * @param endRow search rows excluding this, can handle values greater than real rows count - * @param stringPredicate cell and value comparing bi-predicate if cell value type is string - * @return table table cell address or {@link TableCellAddress#NOT_FOUND} + * Finds cell by predicate. + * + * @param startRow search rows start from this + * @return cell address or {@link TableCellAddress#NOT_FOUND} */ - default TableCellAddress find(Object value, int startRow, int endRow, BiPredicate stringPredicate) { - return find(value, startRow, endRow, 0, Integer.MAX_VALUE, stringPredicate); + default TableCellAddress find(int startRow, Predicate cellValuePredicate) { + return find(startRow, Integer.MAX_VALUE, cellValuePredicate); } /** - * @param value searching value + * Finds cell by predicate. + * + * @param startRow search rows start from this + * @param endRow search rows excluding this, can handle values greater than real rows count + * @return cell address or {@link TableCellAddress#NOT_FOUND} + */ + default TableCellAddress find(int startRow, int endRow, Predicate cellValuePredicate) { + return find(startRow, endRow, 0, Integer.MAX_VALUE, cellValuePredicate); + } + + /** + * Finds cell by predicate. + * + * @param startRow search rows start from this + * @param endRow search rows excluding this, can handle values greater than real rows count + * @param startColumn search columns start from this + * @param endColumn search columns excluding this, can handle values greater than real columns count + * @param cellValuePredicate predicate for testing cell value + * @return cell address or {@link TableCellAddress#NOT_FOUND} + */ + TableCellAddress find(int startRow, int endRow, + int startColumn, int endColumn, + Predicate cellValuePredicate); + + /** + * Finds cell address staring with value (ignore case, trims leading spaces). + * + * @return cell address or {@link TableCellAddress#NOT_FOUND} + */ + default TableCellAddress findByPrefix(String prefix) { + return findByPrefix(prefix, 0); + } + + /** + * Finds cell address staring with value (ignore case, trims leading spaces). + * + * @param startRow search rows start from this + * @return cell address or {@link TableCellAddress#NOT_FOUND} + */ + default TableCellAddress findByPrefix(String prefix, int startRow) { + return findByPrefix(prefix, startRow, Integer.MAX_VALUE); + } + + /** + * Finds cell address staring with value (ignore case, trims leading spaces). + * + * @param startRow search rows start from this + * @param endRow search rows excluding this, can handle values greater than real rows count + * @return cell address or {@link TableCellAddress#NOT_FOUND} + */ + default TableCellAddress findByPrefix(String prefix, int startRow, int endRow) { + return findByPrefix(prefix, startRow, endRow, 0, Integer.MAX_VALUE); + } + + /** + * Finds cell address staring with value (ignore case, trims leading spaces). + * * @param startRow search rows start from this * @param endRow search rows excluding this, can handle values greater than real rows count * @param startColumn search columns start from this * @param endColumn search columns excluding this, can handle values greater than real columns count - * @return table table cell address or {@link TableCellAddress#NOT_FOUND} + * @return cell address or {@link TableCellAddress#NOT_FOUND} */ - TableCellAddress find(Object value, int startRow, int endRow, - int startColumn, int endColumn, - BiPredicate stringPredicate); - + default TableCellAddress findByPrefix(String prefix, int startRow, int endRow, int startColumn, int endColumn) { + return prefix == null ? + TableCellAddress.NOT_FOUND : + find(startRow, endRow, startColumn, endColumn, getCellStringValueIgnoreCasePrefixPredicate(prefix)); + } /** * For vertical table of key-value records (table with two columns), search and return value for requested key. */ - default Object getNextColumnValue(String firstColumnValue) { - TableCellAddress address = find(firstColumnValue); + default Object getNextColumnValue(String firstColumnValuePrefix) { + TableCellAddress address = findByPrefix(firstColumnValuePrefix); for (TableCell cell : getRow(address.getRow())) { if (cell != null && cell.getColumnIndex() > address.getColumn()) { Object value = cell.getValue(); @@ -103,15 +188,33 @@ default TableCell getCell(TableCellAddress address) { } /** - * Returns table range, table ends with predefined string in one of the row cells. + * Returns table range. Table's first row starts with 'firstRowPrefix' prefix in one of the cells + * and table ends with predefined prefix in one of the last row cells. */ - default TableCellRange getTableCellRange(String tableName, int headersRowCount, String tableFooterString) { - TableCellAddress startAddress = find(tableName); + default TableCellRange getTableCellRange(String firstRowPrefix, int headersRowCount, String lastRowPrefix) { + if (firstRowPrefix == null || lastRowPrefix == null) { + return TableCellRange.EMPTY_RANGE; + } + return getTableCellRange( + getCellStringValueIgnoreCasePrefixPredicate(firstRowPrefix), + headersRowCount, + getCellStringValueIgnoreCasePrefixPredicate(lastRowPrefix)); + } + + /** + * Returns table range. First and last row will be found by predicate. + */ + default TableCellRange getTableCellRange(Predicate firstRowFinder, + int headersRowCount, + Predicate lastRowFinder) { + if (firstRowFinder == null || lastRowFinder == null) { + return TableCellRange.EMPTY_RANGE; + } + TableCellAddress startAddress = find(firstRowFinder); if (startAddress.equals(TableCellAddress.NOT_FOUND)) { return TableCellRange.EMPTY_RANGE; } - TableCellAddress endAddress = find(tableFooterString, startAddress.getRow() + headersRowCount + 1, - getLastRowNum(), ReportPage.CELL_STRING_STARTS_WITH); + TableCellAddress endAddress = find(startAddress.getRow() + headersRowCount + 1, lastRowFinder); if (endAddress.equals(TableCellAddress.NOT_FOUND)) { return TableCellRange.EMPTY_RANGE; } @@ -123,10 +226,26 @@ default TableCellRange getTableCellRange(String tableName, int headersRowCount, } /** - * Returns table range, table ends with empty row or last row of report page. + * Returns table range. First row starts with 'firstRowPrefix' prefix in one of the cells, + * range ends with empty row or last row of report page. */ - default TableCellRange getTableCellRange(String tableName, int headersRowCount) { - TableCellAddress startAddress = find(tableName); + default TableCellRange getTableCellRange(String firstRowPrefix, int headersRowCount) { + if (firstRowPrefix == null) { + return TableCellRange.EMPTY_RANGE; + } + return getTableCellRange( + getCellStringValueIgnoreCasePrefixPredicate(firstRowPrefix), + headersRowCount); + } + + /** + * Returns table range. First row will be found by predicate, range ends with empty row or last row of report page. + */ + default TableCellRange getTableCellRange(Predicate firstRowFinder, int headersRowCount) { + if (firstRowFinder == null) { + return TableCellRange.EMPTY_RANGE; + } + TableCellAddress startAddress = find(firstRowFinder); if (startAddress.equals(TableCellAddress.NOT_FOUND)) { return TableCellRange.EMPTY_RANGE; } @@ -148,7 +267,7 @@ default TableCellRange getTableCellRange(String tableName, int headersRowCount) /** * Returns zero-based index of empty row. - * This implementation generates a huge amount of garbage. May be override for improve performance. + * This implementation generates a huge amount of garbage. May be overridden for improve performance. * * @param startRow first row for check * @return index of first empty row or -1 if not found @@ -203,6 +322,34 @@ default Table create(String tableName, .create(this, tableName, headerDescription, headersRowCount); } + default Table create(Predicate tableNameFinder, + Predicate tableFooterFinder, + Class headerDescription) { + return TableFactoryRegistry.get(this) + .create(this, tableNameFinder, tableFooterFinder, headerDescription); + } + + default Table create(Predicate tableNameFinder, + Class headerDescription) { + return TableFactoryRegistry.get(this) + .create(this, tableNameFinder, headerDescription); + } + + default Table create(Predicate tableNameFinder, + Predicate tableFooterFinder, + Class headerDescription, + int headersRowCount) { + return TableFactoryRegistry.get(this) + .create(this, tableNameFinder, tableFooterFinder, headerDescription, headersRowCount); + } + + default Table create(Predicate tableNameFinder, + Class headerDescription, + int headersRowCount) { + return TableFactoryRegistry.get(this) + .create(this, tableNameFinder, headerDescription, headersRowCount); + } + default Table createNameless(String firstLineText, String lastRowString, Class headerDescription) { @@ -210,6 +357,12 @@ default Table createNameless(String firstLineText, .createNameless(this, firstLineText, lastRowString, headerDescription); } + default Table createNameless(String firstLineText, + Class headerDescription) { + return TableFactoryRegistry.get(this) + .createNameless(this, firstLineText, headerDescription); + } + default Table createNameless(String providedTableName, String firstLineText, String lastRowString, @@ -219,17 +372,41 @@ default Table createNameless(String providedTableName, .createNameless(this, providedTableName, firstLineText, lastRowString, headerDescription, headersRowCount); } - default Table createNameless(String firstLineText, + default Table createNameless(String providedTableName, + String firstLineText, + Class headerDescription, + int headersRowCount) { + return TableFactoryRegistry.get(this) + .createNameless(this, providedTableName, firstLineText, headerDescription, headersRowCount); + } + + default Table createNameless(Predicate firstLineFinder, + Predicate lastRowFinder, Class headerDescription) { return TableFactoryRegistry.get(this) - .createNameless(this, firstLineText, headerDescription); + .createNameless(this, firstLineFinder, lastRowFinder, headerDescription); + } + + default Table createNameless(Predicate firstLineFinder, + Class headerDescription) { + return TableFactoryRegistry.get(this) + .createNameless(this, firstLineFinder, headerDescription); } default Table createNameless(String providedTableName, - String firstLineText, + Predicate firstLineFinder, + Predicate lastRowFinder, Class headerDescription, int headersRowCount) { return TableFactoryRegistry.get(this) - .createNameless(this, providedTableName, firstLineText, headerDescription, headersRowCount); + .createNameless(this, providedTableName, firstLineFinder, lastRowFinder, headerDescription, headersRowCount); + } + + default Table createNameless(String providedTableName, + Predicate firstLineFinder, + Class headerDescription, + int headersRowCount) { + return TableFactoryRegistry.get(this) + .createNameless(this, providedTableName, firstLineFinder, headerDescription, headersRowCount); } } diff --git a/src/main/java/org/spacious_team/table_wrapper/api/ReportPageHelper.java b/src/main/java/org/spacious_team/table_wrapper/api/ReportPageHelper.java new file mode 100644 index 0000000..772c854 --- /dev/null +++ b/src/main/java/org/spacious_team/table_wrapper/api/ReportPageHelper.java @@ -0,0 +1,30 @@ +/* + * Table Wrapper API + * Copyright (C) 2022 Vitalii Ananev + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.spacious_team.table_wrapper.api; + +import java.util.function.Predicate; + +class ReportPageHelper { + + static Predicate getCellStringValueIgnoreCasePrefixPredicate(String prefix) { + String lowercasePrefix = prefix.trim().toLowerCase(); + return (cell) -> (cell instanceof String) && + ((String) cell).trim().toLowerCase().startsWith(lowercasePrefix); + } +} diff --git a/src/main/java/org/spacious_team/table_wrapper/api/ReportPageRow.java b/src/main/java/org/spacious_team/table_wrapper/api/ReportPageRow.java index 3b713a4..9320901 100644 --- a/src/main/java/org/spacious_team/table_wrapper/api/ReportPageRow.java +++ b/src/main/java/org/spacious_team/table_wrapper/api/ReportPageRow.java @@ -41,5 +41,9 @@ public interface ReportPageRow extends Iterable { */ int getLastCellNum(); - boolean rowContains(Object value); + /** + * @param expected searching value + * @return true if any cell of this row has exact value, false otherwise + */ + boolean rowContains(Object expected); } \ No newline at end of file diff --git a/src/main/java/org/spacious_team/table_wrapper/api/Table.java b/src/main/java/org/spacious_team/table_wrapper/api/Table.java index 5f81543..204c5ea 100644 --- a/src/main/java/org/spacious_team/table_wrapper/api/Table.java +++ b/src/main/java/org/spacious_team/table_wrapper/api/Table.java @@ -58,10 +58,15 @@ List getDataCollection(Object report, Function> r Stream stream(); /** - * @return row containing given value or null if not found + * @return row containing cell with exact value or null if not found */ TableRow findRow(Object value); + /** + * @return row containing cell starting with prefix or null if not found + */ + TableRow findRowByPrefix(String prefix); + Map getHeaderDescription(); /** diff --git a/src/main/java/org/spacious_team/table_wrapper/api/TableFactory.java b/src/main/java/org/spacious_team/table_wrapper/api/TableFactory.java index d1247f6..d29790f 100644 --- a/src/main/java/org/spacious_team/table_wrapper/api/TableFactory.java +++ b/src/main/java/org/spacious_team/table_wrapper/api/TableFactory.java @@ -18,6 +18,8 @@ package org.spacious_team.table_wrapper.api; +import java.util.function.Predicate; + public interface TableFactory { boolean canHandle(ReportPage reportPage); @@ -25,8 +27,9 @@ public interface TableFactory { /** * Creates table which starts with name followed by header and ends with row containing cell with text starting with * given string. - * @param tableName table name's row contains cell which starts with given text - * @param lastRowString table last row contains cell which starts with given text + * + * @param tableName table name's row should contain cell which starts with given text + * @param lastRowString table's last row should contain cell which starts with given text */ default Table create(ReportPage reportPage, String tableName, @@ -37,7 +40,8 @@ default Table create(ReportPage reportPage, /** * Creates table which starts with name followed by header and ends with empty row or last row of report page. - * @param tableName table name's row contains cell which starts with given text + * + * @param tableName table name's row should contain cell which starts with given text */ default Table create(ReportPage reportPage, String tableName, @@ -48,29 +52,112 @@ default Table create(ReportPage reportPage, /** * Creates table which starts with name followed by header and ends with row containing cell with text starting with * given string. - * @param tableName table name's row contains cell which starts with given text - * @param lastRowString table last row contains cell which starts with given text + * + * @param tableName table name's row should contain cell which starts with given text + * @param lastRowString table's last row should contain cell which starts with given text */ - Table create(ReportPage reportPage, - String tableName, - String lastRowString, - Class headerDescription, - int headersRowCount); + default Table create(ReportPage reportPage, + String tableName, + String lastRowString, + Class headerDescription, + int headersRowCount) { + return create(reportPage, + tableName, + reportPage.getTableCellRange(tableName, headersRowCount, lastRowString), + headerDescription, + headersRowCount); + } /** * Creates table which starts with name followed by header and ends with empty row or last row of report page. - * @param tableName table name's row contains cell which starts with given text + * + * @param tableName table name's row should contain cell which starts with given text */ - Table create(ReportPage reportPage, - String tableName, - Class headerDescription, - int headersRowCount); + default Table create(ReportPage reportPage, + String tableName, + Class headerDescription, + int headersRowCount) { + return create(reportPage, + tableName, + reportPage.getTableCellRange(tableName, headersRowCount), + headerDescription, + headersRowCount); + } + + /** + * Creates table. Table name containing row and last row will be found by predicate. + * + * @param tableNameFinder table name containing row should contain cell satisfying predicate + * @param lastRowFinder table's last row should contain cell satisfying predicate + */ + default Table create(ReportPage reportPage, + Predicate tableNameFinder, + Predicate lastRowFinder, + Class headerDescription) { + return create(reportPage, tableNameFinder, lastRowFinder, headerDescription, 1); + } + + /** + * Creates table. Table name containing row will be found by predicate, table ends by empty row + * or last row of report page. + * + * @param tableNameFinder table name containing row should contain cell satisfying predicate + */ + default Table create(ReportPage reportPage, + Predicate tableNameFinder, + Class headerDescription) { + return create(reportPage, tableNameFinder, headerDescription, 1); + } + + /** + * Creates table. Table name containing row and last row will be found by predicate. + * + * @param tableNameFinder table name containing row should contain cell satisfying predicate + * @param lastRowFinder table's last row should contain cell satisfying predicate + */ + default Table create(ReportPage reportPage, + Predicate tableNameFinder, + Predicate lastRowFinder, + Class headerDescription, + int headersRowCount) { + String tableName = ""; + TableCellRange range = reportPage.getTableCellRange(tableNameFinder, headersRowCount, lastRowFinder); + if (!range.equals(TableCellRange.EMPTY_RANGE)) { + TableCellAddress tableNameCell = + reportPage.find(range.getFirstRow(), range.getFirstRow() + 1, tableNameFinder); + tableName = tableNameCell.equals(TableCellAddress.NOT_FOUND) ? "" : + reportPage.getCell(tableNameCell).getStringValue(); + } + return create(reportPage, tableName, range, headerDescription, headersRowCount); + } + + /** + * Creates table. Table name containing row will be found by predicate, table ends by empty row + * or last row of report page. + * + * @param tableNameFinder table name containing row should contain cell satisfying predicate + */ + default Table create(ReportPage reportPage, + Predicate tableNameFinder, + Class headerDescription, + int headersRowCount) { + String tableName = ""; + TableCellRange range = reportPage.getTableCellRange(tableNameFinder, headersRowCount); + if (!range.equals(TableCellRange.EMPTY_RANGE)) { + TableCellAddress tableNameCell = + reportPage.find(range.getFirstRow(), range.getFirstRow() + 1, tableNameFinder); + tableName = tableNameCell.equals(TableCellAddress.NOT_FOUND) ? "" : + reportPage.getCell(tableNameCell).getStringValue(); + } + return create(reportPage, tableName, range, headerDescription, headersRowCount); + } /** * Creates table without name which starts with header and ends with row containing cell with text starting with * given string. - * @param firstRowString table first row contains cell which starts with given text - * @param lastRowString table last row contains cell which starts with given text + * + * @param firstRowString table first row should contain cell which starts with given text + * @param lastRowString table's last row should contain cell which starts with given text */ default Table createNameless(ReportPage reportPage, String firstRowString, @@ -80,37 +167,127 @@ default Table createNameless(ReportPage reportPage, } /** - * Creates table without name which starts with header and ends with row containing cell with text starting with - * given string. + * Creates table without name which starts with header and ends with empty row or last row of report page. + * + * @param firstRowString table first row should contain cell which starts with given text + */ + default Table createNameless(ReportPage reportPage, + String firstRowString, + Class headerDescription) { + return createNameless(reportPage, "undefined", firstRowString, headerDescription, 1); + } + + /** + * Creates table with predefined name which starts with header and ends with row containing cell with text starting + * with given string. + * * @param providedTableName predefined (not existing in reportPage) table name - * @param firstRowString table first row contains cell which starts with given text - * @param lastRowString table last row contains cell which starts with given text + * @param firstRowString table first row should contain cell which starts with given text + * @param lastRowString table's last row should contain cell which starts with given text */ - Table createNameless(ReportPage reportPage, - String providedTableName, - String firstRowString, - String lastRowString, - Class headerDescription, - int headersRowCount); + default Table createNameless(ReportPage reportPage, + String providedTableName, + String firstRowString, + String lastRowString, + Class headerDescription, + int headersRowCount) { + return create(reportPage, + providedTableName, + reportPage.getTableCellRange(firstRowString, headersRowCount, lastRowString) + .addRowsToTop(1), // add fantom first line for provided table name + headerDescription, + headersRowCount); + } /** - * Creates table without name which starts with header and ends with empty row or last row of report page. - * @param firstRowString table first row contains cell which starts with given text + * Creates table with predefined name which starts with header and ends with empty row or last row of report page. + * + * @param providedTableName predefined (not existing in reportPage) table name + * @param firstRowString table first row should contain cell which starts with given text */ default Table createNameless(ReportPage reportPage, + String providedTableName, String firstRowString, + Class headerDescription, + int headersRowCount) { + return create(reportPage, + providedTableName, + reportPage.getTableCellRange(firstRowString, headersRowCount) + .addRowsToTop(1), // add fantom first line for provided table name + headerDescription, + headersRowCount); + } + + /** + * Creates table without name. Table first and last row will be found by predicate. + * + * @param firstRowFinder table first row should contain cell satisfying predicate + * @param lastRowFinder table's last row should contain cell satisfying predicate + */ + default Table createNameless(ReportPage reportPage, + Predicate firstRowFinder, + Predicate lastRowFinder, Class headerDescription) { - return createNameless(reportPage, "undefined", firstRowString, headerDescription, 1); + return createNameless(reportPage, "undefined", firstRowFinder, lastRowFinder, headerDescription, 1); } /** - * Creates table without name which starts with header and ends with empty row or last row of report page. + * Creates table without name. Table first row will be found by predicate, table ends by empty row + * or last row of report page. + * + * @param firstRowFinder table first row should contain cell satisfying predicate + */ + default Table createNameless(ReportPage reportPage, + Predicate firstRowFinder, + Class headerDescription) { + return createNameless(reportPage, "undefined", firstRowFinder, headerDescription, 1); + } + + /** + * Creates table with predefined name. Table first and last row will be found by predicate. + * * @param providedTableName predefined (not existing in reportPage) table name - * @param firstRowString table first row contains cell which starts with given text + * @param firstRowFinder table first row should contain cell satisfying predicate + * @param lastRowFinder table's last row should contain cell satisfying predicate */ - Table createNameless(ReportPage reportPage, - String providedTableName, - String firstRowString, - Class headerDescription, - int headersRowCount); + default Table createNameless(ReportPage reportPage, + String providedTableName, + Predicate firstRowFinder, + Predicate lastRowFinder, + Class headerDescription, + int headersRowCount) { + return create(reportPage, + providedTableName, + reportPage.getTableCellRange(firstRowFinder, headersRowCount, lastRowFinder) + .addRowsToTop(1), // add fantom first line for provided table name + headerDescription, + headersRowCount); + } + + /** + * Creates table with predefined name. Table first row will be found by predicate, table ends by empty row + * or last row of report page. + * + * @param providedTableName predefined (not existing in reportPage) table name + * @param firstRowFinder table first row should contain cell satisfying predicate + */ + default Table createNameless(ReportPage reportPage, + String providedTableName, + Predicate firstRowFinder, + Class headerDescription, + int headersRowCount) { + return create(reportPage, + providedTableName, + reportPage.getTableCellRange(firstRowFinder, headersRowCount) + .addRowsToTop(1), // add fantom first line for provided table name + headerDescription, + headersRowCount); + } + + + Table create(ReportPage reportPage, + String tableName, + TableCellRange tableRange, + Class headerDescription, + int headersRowCount); } diff --git a/src/main/java/org/spacious_team/table_wrapper/api/TableRow.java b/src/main/java/org/spacious_team/table_wrapper/api/TableRow.java index caea255..e50c724 100644 --- a/src/main/java/org/spacious_team/table_wrapper/api/TableRow.java +++ b/src/main/java/org/spacious_team/table_wrapper/api/TableRow.java @@ -47,6 +47,7 @@ public interface TableRow extends ReportPageRow, Cloneable { * @throws RuntimeException if can't extract Double value */ double getDoubleCellValue(TableColumnDescription column); + /** * @throws RuntimeException if can't extract BigDecimal value */