Package org.instancio.generator.specs
Interface CsvSpec
- All Superinterfaces:
CsvGeneratorSpec
,GeneratorSpec<String>
,ValueSpec<String>
- All Known Implementing Classes:
CsvGenerator
Spec for generating 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
Description copied from interface:CsvGeneratorSpec
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();
- Specified by:
column
in interfaceCsvGeneratorSpec
- Parameters:
name
- of the columngenerator
- for generating values- Returns:
- spec builder
- See Also:
-
column
Description copied from interface:CsvGeneratorSpec
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();
- Specified by:
column
in interfaceCsvGeneratorSpec
- Parameters:
name
- of the columngeneratorSpec
- for generating values- Returns:
- spec builder
- See Also:
-
rows
Description copied from interface:CsvGeneratorSpec
Number of rows to generate.- Specified by:
rows
in interfaceCsvGeneratorSpec
- Parameters:
rows
- number of rows to generate- Returns:
- spec builder
- See Also:
-
rows
Description copied from interface:CsvGeneratorSpec
A range for the number of rows to generate. A random number of rows within the given range will be generated.- Specified by:
rows
in interfaceCsvGeneratorSpec
- Parameters:
minRows
- minimum number of rows (inclusive)maxRows
- maximum number of rows (inclusive)- Returns:
- spec builder
- See Also:
-
noHeader
CsvSpec noHeader()Description copied from interface:CsvGeneratorSpec
Omit CSV header from the output. The default is to include the header.- Specified by:
noHeader
in interfaceCsvGeneratorSpec
- Returns:
- spec builder
-
wrapWith
Description copied from interface:CsvGeneratorSpec
A string to wrap the values with, for example quotes. The default isnull
.- Specified by:
wrapWith
in interfaceCsvGeneratorSpec
- Parameters:
wrapWith
- a string to wrap the values with.- Returns:
- spec builder
- See Also:
-
wrapIf
Description copied from interface:CsvGeneratorSpec
A condition that must be satisfied to wrap a value. IfCsvGeneratorSpec.wrapWith(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
- Specified by:
wrapIf
in interfaceCsvGeneratorSpec
- Parameters:
condition
- for wrapping a value- Returns:
- spec builder
- See Also:
-
separator
Description copied from interface:CsvGeneratorSpec
Specifies the value separator. The default is comma:','
.- Specified by:
separator
in interfaceCsvGeneratorSpec
- Parameters:
separator
- for separating values- Returns:
- spec builder
-
lineSeparator
Description copied from interface:CsvGeneratorSpec
Specifies the line separator. The default isSystem.lineSeparator()
.- Specified by:
lineSeparator
in interfaceCsvGeneratorSpec
- Parameters:
lineSeparator
- for separating rows- Returns:
- spec builder
-