Interface CsvGeneratorSpec

All Superinterfaces:
GeneratorSpec<String>
All Known Subinterfaces:
CsvSpec

@ExperimentalApi public interface CsvGeneratorSpec extends GeneratorSpec<String>
Generator spec for producing CSV.
Since:
2.12.0
  • Method Details

    • column

      CsvGeneratorSpec column(String name, Generator<?> generator)
      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 column
      generator - for generating values
      Returns:
      spec builder
      Since:
      2.12.0
      See Also:
    • column

      CsvGeneratorSpec column(String name, GeneratorSpec<?> generatorSpec)
      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 column
      generatorSpec - for generating values
      Returns:
      spec builder
      Since:
      2.12.0
      See Also:
    • rows

      CsvGeneratorSpec rows(int rows)
      Number of rows to generate.
      Parameters:
      rows - number of rows to generate
      Returns:
      spec builder
      Since:
      2.12.0
      See Also:
    • rows

      CsvGeneratorSpec rows(int minRows, int maxRows)
      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

      CsvGeneratorSpec wrapWith(String str)
      A string to wrap the values with, for example quotes. The default is null.
      Parameters:
      str - a string to wrap the values with.
      Returns:
      spec builder
      Since:
      2.12.0
      See Also:
    • wrapIf

      CsvGeneratorSpec wrapIf(Predicate<Object> condition)
      A condition that must be satisfied to wrap a value. If 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
       
      Parameters:
      condition - for wrapping a value
      Returns:
      spec builder
      Since:
      2.12.0
      See Also:
    • separator

      CsvGeneratorSpec separator(String separator)
      Specifies the value separator. The default is comma: ','.
      Parameters:
      separator - for separating values
      Returns:
      spec builder
      Since:
      2.12.0
    • lineSeparator

      CsvGeneratorSpec lineSeparator(String lineSeparator)
      Specifies the line separator. The default is System.lineSeparator().
      Parameters:
      lineSeparator - for separating rows
      Returns:
      spec builder
      Since:
      2.12.0