Package org.instancio.generator.specs
Interface CsvGeneratorSpec
- All Superinterfaces:
GeneratorSpec<String>
- All Known Subinterfaces:
CsvSpec
Generator spec for producing CSV.
- Since:
- 2.12.0
-
Method Summary
Modifier and TypeMethodDescriptionSpecifies the column name and the generator for producing the values.column
(String name, GeneratorSpec<?> generatorSpec) Specifies the column name and the generator spec for producing the values.lineSeparator
(String lineSeparator) Specifies the line separator.noHeader()
Omit CSV header from the output.rows
(int rows) Number of rows to generate.rows
(int minRows, int maxRows) A range for the number of rows to generate.Specifies the value separator.A condition that must be satisfied to wrap a value.A string to wrap the values with, for example quotes.
-
Method Details
-
column
Specifies the column name and the generator for producing the values.Example:
DataImport data = Instancio.of(DataImport.class) .generate(field(DataImport::getCsv), gen -> gen.text().csv() .column("productCode", random -> random.upperCaseAlphabetic(5)) .column("skuCode", new SkuCodeGenerator()) .column("quantity", random -> random.intRange(1, 100))) .create();
- Parameters:
name
- of the columngenerator
- for generating values- Returns:
- spec builder
- Since:
- 2.12.0
- See Also:
-
column
Specifies the column name and the generator spec for producing the values.This method can be used with
Gen
, for example:String csv = Gen.text().csv() .column("productCode", Gen.string().length(5)) .column("quantity", Gen.ints().range(1, 100)) .get();
- Parameters:
name
- of the columngeneratorSpec
- for generating values- Returns:
- spec builder
- Since:
- 2.12.0
- See Also:
-
rows
Number of rows to generate.- Parameters:
rows
- number of rows to generate- Returns:
- spec builder
- Since:
- 2.12.0
- See Also:
-
rows
A range for the number of rows to generate. A random number of rows within the given range will be generated.- Parameters:
minRows
- minimum number of rows (inclusive)maxRows
- maximum number of rows (inclusive)- Returns:
- spec builder
- Since:
- 2.12.0
- See Also:
-
noHeader
CsvGeneratorSpec noHeader()Omit CSV header from the output. The default is to include the header.- Returns:
- spec builder
- Since:
- 2.12.0
-
wrapWith
A string to wrap the values with, for example quotes. The default isnull
.- Parameters:
str
- a string to wrap the values with.- Returns:
- spec builder
- Since:
- 2.12.0
- See Also:
-
wrapIf
A condition that must be satisfied to wrap a value. IfwrapWith(String)
is specified, the default is to wrap all values.For example, to specify that only strings should be wrapped:
String csv = Gen.text().csv() .column("column1", Gen.string()) .column("column2", Gen.ints()) .wrapWith("\"") .wrapIf(value -> value instanceof String) .get() // Sample output: // // column1,column2 // "KJDTJZRCYY",2454 // "LUOQGNQUUJ",9125 // "FHRFTI",6809
- Parameters:
condition
- for wrapping a value- Returns:
- spec builder
- Since:
- 2.12.0
- See Also:
-
separator
Specifies the value separator. The default is comma:','
.- Parameters:
separator
- for separating values- Returns:
- spec builder
- Since:
- 2.12.0
-
lineSeparator
Specifies the line separator. The default isSystem.lineSeparator()
.- Parameters:
lineSeparator
- for separating rows- Returns:
- spec builder
- Since:
- 2.12.0
-