How to use extractColumnNames method of org.testingisdocumenting.webtau.data.table.TableData class

Best Webtau code snippet using org.testingisdocumenting.webtau.data.table.TableData.extractColumnNames

Source:TableData.java Github

copy

Full Screen

...34 private final Map<CompositeKey, Record> rowsByKey;35 private final Map<CompositeKey, Integer> rowIdxByKey;36 private final TableDataHeader header;37 public TableData(List<?> columnNamesAndOptionalValues) {38 this(new TableDataHeader(extractColumnNames(columnNamesAndOptionalValues.stream()).stream()));39 populateValues(columnNamesAndOptionalValues.stream());40 }41 public TableData(Stream<?> columnNamesAndOptionalValues) {42 this(columnNamesAndOptionalValues.collect(toList()));43 }44 public TableData(TableDataHeader header) {45 this.header = header;46 this.rows = new ArrayList<>();47 this.rowsByKey = new HashMap<>();48 this.rowIdxByKey = new HashMap<>();49 }50 public TableDataHeader getHeader() {51 return header;52 }53 public boolean isEmpty() {54 return rows.isEmpty();55 }56 public Set<CompositeKey> keySet() {57 return rowsByKey.keySet();58 }59 public Integer findRowIdxByKey(CompositeKey key) {60 return rowIdxByKey.get(key);61 }62 /**63 * create new table data with the data of a current one but with new key columns.64 * can be used to validate new key columns uniqueness65 * @param keyColumns new key columns66 * @return new table data with updated key columns67 */68 public TableData withNewKeyColumns(String... keyColumns) {69 TableDataHeader newHeader = new TableDataHeader(header.getNamesStream(), Arrays.stream(keyColumns));70 TableData withNewHeader = new TableData(newHeader);71 for (Record originalRow : rows) {72 withNewHeader.addRow(newHeader.createRecord(originalRow.valuesStream()));73 }74 return withNewHeader;75 }76 /**77 * @param values row values combined in one vararg78 * @return populate table data instance79 */80 public TableData values(Object... values) {81 int numberOfRows = header.size() == 0 ? 0 : values.length / header.size();82 int numberOfExtraValues = header.size() == 0 ? 0 : values.length % header.size();83 if (numberOfExtraValues != 0) {84 int startIdxOfExtraValues = numberOfRows * header.size();85 throw new IllegalArgumentException("unfinished row idx " + numberOfRows + ", header: " + header + "\nvalues so far: " +86 Arrays.stream(values).skip(startIdxOfExtraValues).map(Object::toString).87 collect(joining(", ")));88 }89 int total = numberOfRows * header.size();90 for (int i = 0; i < total; i += header.size()) {91 addRow(Arrays.stream(values).skip(i).limit(header.size()));92 }93 return this;94 }95 public Record row(int rowIdx) {96 validateRowIdx(rowIdx);97 return rows.get(rowIdx);98 }99 public Record find(CompositeKey key) {100 return rowsByKey.get(key);101 }102 public void addRow(List<Object> values) {103 addRow(values.stream());104 }105 public void addRow(Stream<Object> values) {106 Record record = new Record(header, values);107 if (record.hasMultiValues()) {108 record.unwrapMultiValues().forEach(this::addRow);109 } else {110 addRow(record);111 }112 }113 public void addRow(Record record) {114 if (header != record.getHeader()) {115 throw new RuntimeException("incompatible headers. current getHeader: " + header + ", new record one: " + record.getHeader());116 }117 int rowIdx = rows.size();118 CompositeKey key = getOrBuildKey(rowIdx, record);119 Record existing = rowsByKey.put(key, record);120 if (existing != null) {121 throw new IllegalArgumentException("duplicate entry found with key: " + key +122 "\n" + existing +123 "\n" + record);124 }125 Record previous = rows.isEmpty() ? null : rows.get(rows.size() - 1);126 Record withEvaluatedGenerators = record.evaluateValueGenerators(previous, rows.size());127 rowIdxByKey.put(key, rowIdx);128 rows.add(withEvaluatedGenerators);129 }130 public <T, R> TableData map(TableDataCellMapFunction<T, R> mapper) {131 TableData mapped = new TableData(header);132 int rowIdx = 0;133 for (Record originalRow : rows) {134 mapped.addRow(mapRow(rowIdx, originalRow, mapper));135 rowIdx++;136 }137 return mapped;138 }139 public TableData replace(Object before, Object after) {140 return map(((rowIdx, colIdx, columnName, v) -> v.equals(before) ? after : v));141 }142 public <T, R> Stream<R> mapColumn(String columnName, Function<T, R> mapper) {143 int idx = header.columnIdxByName(columnName);144 return rows.stream().map(r -> mapper.apply(r.get(idx)));145 }146 private <T, R> Stream<Object> mapRow(int rowIdx, Record originalRow, TableDataCellMapFunction<T, R> mapper) {147 return header.getColumnIdxStream()148 .mapToObj(idx -> mapper.apply(rowIdx, idx, header.columnNameByIdx(idx), originalRow.get(idx)));149 }150 public Stream<Record> rowsStream() {151 return rows.stream();152 }153 public List<Map<String, ?>> toListOfMaps() {154 return rows.stream().map(Record::toMap).collect(toList());155 }156 public String toJson() {157 return JsonUtils.serializePrettyPrint(toListOfMaps());158 }159 @Override160 public Iterator<Record> iterator() {161 return rows.iterator();162 }163 public int numberOfRows() {164 return rows.size();165 }166 private void validateRowIdx(int rowIdx) {167 if (rowIdx < 0 || rowIdx >= numberOfRows())168 throw new IllegalArgumentException("rowIdx is out of range: [0, " + (numberOfRows() - 1) + "]");169 }170 private CompositeKey getOrBuildKey(int rowIdx, Record row) {171 if (header.hasKeyColumns()) {172 return row.getKey();173 }174 return new CompositeKey(Stream.of(rowIdx));175 }176 private void populateValues(Stream<?> columnNameAndValues) {177 values(columnNameAndValues.skip(header.size() + 1).toArray());178 }179 @Override180 public String toString() {181 return TableDataRenderer.renderTable(this);182 }183 private static List<String> extractColumnNames(Stream<?> columnNameAndValues) {184 List<String> result = new ArrayList<>();185 Iterator<?> iterator = columnNameAndValues.iterator();186 while (iterator.hasNext()) {187 Object nameOrValue = iterator.next();188 if (nameOrValue instanceof TableDataUnderscore) {189 break;190 }191 result.add(nameOrValue.toString());192 }193 return result;194 }195 @Override196 public void prettyPrint(ConsoleOutput console) {197 console.out(PrettyPrintTableRenderer.render(this));...

Full Screen

Full Screen

extractColumnNames

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.data.table.TableData2import org.testingisdocumenting.webtau.data.table.TableDataHeader3TableData table = TableData.create(4 TableDataHeader.header("id", "name", "age"),5table.extractColumnNames()6TableData table = TableData.create(7 TableDataHeader.header("id", "name", "age"),8table.extractColumnNames()9TableData table = TableData.create(10 TableDataHeader.header("id", "name", "age"),11table.extractColumnNames()12TableData table = TableData.create(13 TableDataHeader.header("id", "name", "age"),14table.extractColumnNames()15TableData table = TableData.create(16 TableDataHeader.header("id", "name", "age"),17table.extractColumnNames()18TableData table = TableData.create(19 TableDataHeader.header("id", "name", "age"),20table.extractColumnNames()21TableData table = TableData.create(22 TableDataHeader.header("id", "name", "age"),23table.extractColumnNames()24TableData table = TableData.create(25 TableDataHeader.header("id", "name", "age"),26table.extractColumnNames()

Full Screen

Full Screen

extractColumnNames

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.data.table.TableData2import org.testingisdocumenting.webtau.utils.TableUtils3TableData table = TableData.create(4List<String> columnNames = table.extractColumnNames()5TableData newTable = TableUtils.createTable(table, columnNames)6newTable.should.have.columns.size(2)7newTable.should.have.rows.size(3)8newTable.should.equal(table)9newTable.should.equal(table, ["1", "2"])

Full Screen

Full Screen

extractColumnNames

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.data.table.TableData2import org.testingisdocumenting.webtau.data.table.TableData3TableData tableData = TableData.create()4 .columns("name", "age")5 .row("John", 25)6 .row("Jane", 30)7TableData newTableData = TableData.create()8 .columns(tableData.extractColumnNames())9 .rows(tableData.extractRows())10TableData tableData = TableData.create()11 .columns("name", "age")12 .row("John", 25)13 .row("Jane", 30)14TableData newTableData = TableData.create()15 .columns(tableData.extractColumnNames())16 .rows(tableData.extractRows())17TableData tableData = TableData.create()18 .columns("name", "age")19 .row("John", 25)20 .row("Jane", 30)21TableData newTableData = TableData.create()22 .columns(tableData.extractColumnNames())23 .rows(tableData.extractRows())24TableData tableData = TableData.create()25 .columns("name", "age")26 .row("John", 25)27 .row("Jane", 30)28TableData newTableData = TableData.create()29 .columns(tableData.extractColumnNames())30 .rows(tableData.extractRows())31TableData tableData = TableData.create()32 .columns("name", "age")33 .row("John", 25)34 .row("Jane", 30)35TableData newTableData = TableData.create()36 .columns(tableData.extractColumnNames())37 .rows(tableData.extractRows())38TableData tableData = TableData.create()39 .columns("name", "age")40 .row("John", 25)41 .row("Jane", 30)42TableData newTableData = TableData.create()43 .columns(tableData.extractColumnNames())44 .rows(tableData.extractRows())

Full Screen

Full Screen

extractColumnNames

Using AI Code Generation

copy

Full Screen

1TableData table = TableData.create(2 3, "Jack", 20);3List<String> columnNames = table.extractColumnNames();4String firstColumnName = columnNames.get(0);5TableData table = TableData.create(6 3, "Jack", 20);7List<String> columnNames = table.extractColumnNames();8String firstColumnName = columnNames.get(0);9TableData table = TableData.create(

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful