Class CsvGenerator
java.lang.Object
org.instancio.internal.generator.AbstractGenerator<String>
org.instancio.internal.generator.text.CsvGenerator
- All Implemented Interfaces:
Generator<String>,GeneratorSpec<String>,CsvGeneratorSpec,CsvSpec,NullableGeneratorSpec<String>,ValueSpec<String>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the public API method name of the generator spec.Specifies 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.nullable()Indicates thatnullvalue can be generated.rows(int rows) Number of rows to generate.rows(int min, int max) A range for the number of rows to generate.Specifies the value separator.protected StringtryGenerateNonNull(Random random) Makes the best effort to return a non-null value.A condition that must be satisfied to wrap a value.A string to wrap the values with, for example quotes.Methods inherited from class org.instancio.internal.generator.AbstractGenerator
generate, getContext, hints, isNullable, nullable
-
Constructor Details
-
CsvGenerator
public CsvGenerator() -
CsvGenerator
-
-
Method Details
-
apiMethod
Description copied from class:AbstractGeneratorReturns the public API method name of the generator spec. The returned name is used for reporting validation errors.- Specified by:
apiMethodin classAbstractGenerator<String>- Returns:
- spec name if defined, or
nullotherwise
-
column
Description copied from interface:CsvGeneratorSpecSpecifies 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:
columnin interfaceCsvGeneratorSpec- Specified by:
columnin interfaceCsvSpec- Parameters:
name- of the columngeneratorSpec- for generating values- Returns:
- spec builder
- See Also:
-
column
Description copied from interface:CsvGeneratorSpecSpecifies 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- Specified by:
columnin interfaceCsvSpec- Parameters:
name- of the columngenerator- for generating values- Returns:
- spec builder
- See Also:
-
rows
Description copied from interface:CsvGeneratorSpecNumber of rows to generate.- Specified by:
rowsin interfaceCsvGeneratorSpec- Specified by:
rowsin interfaceCsvSpec- Parameters:
rows- number of rows to generate- Returns:
- spec builder
- See Also:
-
rows
Description copied from interface:CsvGeneratorSpecA range for the number of rows to generate. A random number of rows within the given range will be generated.- Specified by:
rowsin interfaceCsvGeneratorSpec- Specified by:
rowsin interfaceCsvSpec- Parameters:
min- minimum number of rows (inclusive)max- maximum number of rows (inclusive)- Returns:
- spec builder
- See Also:
-
noHeader
Description copied from interface:CsvGeneratorSpecOmit CSV header from the output. The default is to include the header.- Specified by:
noHeaderin interfaceCsvGeneratorSpec- Specified by:
noHeaderin interfaceCsvSpec- Returns:
- spec builder
-
wrapWith
Description copied from interface:CsvGeneratorSpecA string to wrap the values with, for example quotes. The default isnull.- Specified by:
wrapWithin interfaceCsvGeneratorSpec- Specified by:
wrapWithin interfaceCsvSpec- Parameters:
wrapWith- a string to wrap the values with.- Returns:
- spec builder
- See Also:
-
wrapIf
Description copied from interface:CsvGeneratorSpecA 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:
wrapIfin interfaceCsvGeneratorSpec- Specified by:
wrapIfin interfaceCsvSpec- Parameters:
wrapIf- for wrapping a value- Returns:
- spec builder
- See Also:
-
separator
Description copied from interface:CsvGeneratorSpecSpecifies the value separator. The default is comma:','.- Specified by:
separatorin interfaceCsvGeneratorSpec- Specified by:
separatorin interfaceCsvSpec- Parameters:
separator- for separating values- Returns:
- spec builder
-
lineSeparator
Description copied from interface:CsvGeneratorSpecSpecifies the line separator. The default isSystem.lineSeparator().- Specified by:
lineSeparatorin interfaceCsvGeneratorSpec- Specified by:
lineSeparatorin interfaceCsvSpec- Parameters:
lineSeparator- for separating rows- Returns:
- spec builder
-
nullable
Description copied from interface:NullableGeneratorSpecIndicates thatnullvalue can be generated.- Specified by:
nullablein interfaceNullableGeneratorSpec<String>- Specified by:
nullablein interfaceValueSpec<String>- Overrides:
nullablein classAbstractGenerator<String>- Returns:
- spec builder
-
tryGenerateNonNull
Description copied from class:AbstractGeneratorMakes the best effort to return a non-null value. However, in certain cases this method will produce anull.- Specified by:
tryGenerateNonNullin classAbstractGenerator<String>- Parameters:
random- for generating the value- Returns:
- generated value, either a null or non-null
-