cucumber.table
Class DataTable

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

public class DataTable
extends Object

A DataTable represents the data in a table following a step in Gherkin. 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, 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.
<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 dateFormat, String... columnNames)
           
 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<String> flatten()
           
 List<gherkin.formatter.model.DataTableRow> getGherkinRows()
          Internal method.
 List<List<String>> raw()
          Converts the table to a 2D array.
 String toString()
           
 DataTable toTable(List<?> raw, String... columnNames)
          Creates another table using the same Locale and DateFormat that was used to create this table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataTable

public DataTable(List<gherkin.formatter.model.DataTableRow> gherkinRows,
                 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 dateFormat,
                               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

toTable

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

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

diff

public void diff(List<?> other)
          throws 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:
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

flatten

public List<String> flatten()


Copyright © 2012. All Rights Reserved.