Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package cucumber.api;
import cucumber.runtime.CucumberException;
import cucumber.runtime.ParameterInfo;
import cucumber.runtime.table.DiffableRow;
import cucumber.runtime.table.TableDiffException;
import cucumber.runtime.table.TableDiffer;
import cucumber.runtime.table.TablePrinter;
import cucumber.runtime.xstream.LocalizedXStreams;
import gherkin.pickles.PickleCell;
import gherkin.pickles.PickleRow;
import gherkin.pickles.PickleTable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* Represents the data from a Gherkin DataTable. Cucumber will convert the table in Gherkin
* to a DataTable instance and pass it to a step definition.
*/
public class DataTable {
private final List> raw;
private final PickleTable pickleTable;
private final TableConverter tableConverter;
public static DataTable create(List> raw) {
return create(raw, Locale.getDefault(), null, new String[0]);
}
public static DataTable create(List> raw, String format, String... columnNames) {
return create(raw, Locale.getDefault(), format, columnNames);
}
public static DataTable create(List> raw, Locale locale, String... columnNames) {
return create(raw, locale, null, columnNames);
}
private static DataTable create(List> raw, Locale locale, String format, String... columnNames) {
ParameterInfo parameterInfo = new ParameterInfo(null, format, null, null);
TableConverter tableConverter = new cucumber.runtime.table.TableConverter(new LocalizedXStreams(Thread.currentThread().getContextClassLoader()).get(locale), parameterInfo);
return tableConverter.toTable(raw, columnNames);
}
/**
* Creates a new DataTable. This constructor should not be called by Cucumber users - it's used internally only.
*
* @param pickleTable the underlying table.
* @param tableConverter how to convert the rows.
*/
public DataTable(PickleTable pickleTable, TableConverter tableConverter) {
this.pickleTable = pickleTable;
this.tableConverter = tableConverter;
int columns = pickleTable.getRows().isEmpty() ? 0 : pickleTable.getRows().get(0).getCells().size();
List> raw = new ArrayList>();
for (PickleRow row : pickleTable.getRows()) {
List list = new ArrayList();
for (PickleCell cell : row.getCells()) {
list.add(cell.getValue());
}
if (columns != row.getCells().size()) {
throw new CucumberException(String.format("Table is unbalanced: expected %s column(s) but found %s.", columns, row.getCells().size()));
}
raw.add(Collections.unmodifiableList(list));
}
this.raw = Collections.unmodifiableList(raw);
}
private DataTable(PickleTable pickleTable, List> raw, TableConverter tableConverter) {
this.pickleTable = pickleTable;
this.tableConverter = tableConverter;
this.raw = Collections.unmodifiableList(raw);
}
/**
* @return a List of List of String.
*/
public List> raw() {
return this.raw;
}
/**
* Converts the table to a List of Map. The top row is used as keys in the maps,
* and the rows below are used as values.
*
* @param key type
* @param value type
* @param keyType key type
* @param valueType value type
*
* @return a List of Map.
*/
public List