cucumber.api
Class DataTable

java.lang.Object
  extended by cucumber.api.DataTable

public class DataTable
extends Object

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.


Constructor Summary
DataTable(List<gherkin.formatter.model.DataTableRow> gherkinRows, cucumber.runtime.table.TableConverter tableConverter)
          Creates a new DataTable.
 
Method Summary
<T> List<T>
asList(Type type)
          Converts the table to a List of objects.
 List<Map<String,String>> asMaps()
          Converts the table to a List of Map.
 List<List<String>> cells(int firstRow)
           
<T> T
convert(Type type)
           
static DataTable create(List<?> raw)
           
static DataTable create(List<?> raw, Locale locale, String... columnNames)
           
static DataTable create(List<?> raw, String format, String... columnNames)
           
 void diff(DataTable other)
          Diffs this table with other.
 void diff(List<?> other)
          Diffs this table with other, which can be a List&lt;List&lt;String&gt;&gt; or a List&lt;YourType&gt;.
 List<cucumber.runtime.table.DiffableRow> diffableRows()
           
 boolean equals(Object o)
           
 List<String> flatten()
           
 List<gherkin.formatter.model.DataTableRow> getGherkinRows()
          Internal method.
 cucumber.runtime.table.TableConverter getTableConverter()
           
 int hashCode()
           
 List<List<String>> raw()
          Converts the table to a 2D array.
 List<String> topCells()
           
 String toString()
           
 DataTable toTable(List<?> raw, String... columnNames)
          Creates another table using the same Locale and Format that was used to create this table.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataTable

public DataTable(List<gherkin.formatter.model.DataTableRow> gherkinRows,
                 cucumber.runtime.table.TableConverter tableConverter)
Creates a new DataTable. This constructor should not be called by Cucumber users - it's used internally only.

Parameters:
gherkinRows - the underlying rows.
tableConverter - how to convert the rows.
Method Detail

create

public static DataTable create(List<?> raw)

create

public static DataTable create(List<?> raw,
                               String format,
                               String... columnNames)

create

public static DataTable create(List<?> raw,
                               Locale locale,
                               String... columnNames)

raw

public List<List<String>> raw()
Converts the table to a 2D array.

Returns:
a List of List of String.

convert

public <T> T convert(Type type)

asMaps

public List<Map<String,String>> asMaps()
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.

Returns:
a List of Map.

asList

public <T> List<T> asList(Type type)
Converts the table to a List of objects. The top row is used to identifies the fields/properties of the objects.

Backends that support generic types can declare a parameter as a List of a type, and Cucumber will do the conversion automatically.

Type Parameters:
T - the type of each object
Parameters:
type - the type of the result (should be a List generic type)
Returns:
a list of objects

topCells

public List<String> topCells()

cells

public List<List<String>> cells(int firstRow)

toTable

public DataTable toTable(List<?> raw,
                         String... columnNames)
Creates another table using the same Locale and Format that was used to create this table.

Parameters:
raw - a list of objects
columnNames - optional explicit header columns
Returns:
a new table

diff

public void diff(List<?> other)
          throws cucumber.runtime.table.TableDiffException
Diffs this table with other, which can be a List&lt;List&lt;String&gt;&gt; or a List&lt;YourType&gt;.

Parameters:
other - the other table to diff with.
Throws:
cucumber.runtime.table.TableDiffException - if the tables are different.

diff

public void diff(DataTable other)
          throws cucumber.runtime.table.TableDiffException
Diffs this table with other.

Parameters:
other - the other table to diff with.
Throws:
cucumber.runtime.table.TableDiffException - if the tables are different.

getGherkinRows

public List<gherkin.formatter.model.DataTableRow> getGherkinRows()
Internal method. Do not use.

Returns:
a list of raw rows.

toString

public String toString()
Overrides:
toString in class Object

diffableRows

public List<cucumber.runtime.table.DiffableRow> diffableRows()

getTableConverter

public cucumber.runtime.table.TableConverter getTableConverter()

flatten

public List<String> flatten()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2013. All Rights Reserved.