Package org.instancio.generator.specs
Interface CsvSpec
- All Superinterfaces:
CsvGeneratorSpec,GeneratorSpec<String>,Supplier<String>,ValueSpec<String>
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.Specifies the delimiter used to separate 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.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();- Specified by:
columnin interfaceCsvGeneratorSpec- Parameters:
name- of the columngenerator- for generating values- Returns:
- spec builder
- See Also:
-
column
Specifies the column name and the generator spec for producing the values.This method can be used with
Instancio.gen(), for example:String csv = Instancio.gen().text().csv() .column("productCode", Instancio.gen().string().length(5)) .column("quantity", Instancio.gen().ints().range(1, 100)) .get();- Specified by:
columnin interfaceCsvGeneratorSpec- Parameters:
name- of the columngeneratorSpec- for generating values- Returns:
- spec builder
- See Also:
-
rows
Number of rows to generate.- Specified by:
rowsin interfaceCsvGeneratorSpec- Parameters:
rows- number of rows to generate- Returns:
- spec builder
- See Also:
-
rows
A range for the number of rows to generate. A random number of rows within the given range will be generated.- Specified by:
rowsin interfaceCsvGeneratorSpec- Parameters:
minRows- minimum number of rows (inclusive)maxRows- maximum number of rows (inclusive)- Returns:
- spec builder
- See Also:
-
noHeader
CsvSpec noHeader()Omit CSV header from the output. The default is to include the header.- Specified by:
noHeaderin interfaceCsvGeneratorSpec- Returns:
- spec builder
-
wrapWith
A string to wrap the values with, for example quotes. The default isnull.- Specified by:
wrapWithin interfaceCsvGeneratorSpec- Parameters:
wrapWith- a string to wrap the values with.- Returns:
- spec builder
- See Also:
-
wrapIf
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 = Instancio.gen().text().csv() .column("column1", Instancio.gen().string()) .column("column2", Instancio.gen().ints()) .wrapWith("\"") .wrapIf(value -> value instanceof String) .get() // Sample output: // // column1,column2 // "KJDTJZRCYY",2454 // "LUOQGNQUUJ",9125 // "FHRFTI",6809- Specified by:
wrapIfin interfaceCsvGeneratorSpec- Parameters:
condition- for wrapping a value- Returns:
- spec builder
- See Also:
-
delimiter
Specifies the delimiter used to separate values. The default delimiter is a comma (',').- Specified by:
delimiterin interfaceCsvGeneratorSpec- Parameters:
delimiter- the character used to separate values- Returns:
- spec builder
- Since:
- 5.0.0
-
lineSeparator
Specifies the line separator. The default isSystem.lineSeparator().- Specified by:
lineSeparatorin interfaceCsvGeneratorSpec- Parameters:
lineSeparator- for separating rows- Returns:
- spec builder
-