Interface TextSpecs

All Superinterfaces:
TextGenerators

public interface TextSpecs extends TextGenerators
Provides text generators.
Since:
5.0.0
  • Method Details

    • csv

      Generates CSV.
      Specified by:
      csv in interface TextGenerators
      Returns:
      CSV generator
      Since:
      5.0.0
    • loremIpsum

      LoremIpsumSpec loremIpsum()
      Generates "Lorem ipsum" text.
      Specified by:
      loremIpsum in interface TextGenerators
      Returns:
      lorem ipsum text generator
      Since:
      5.0.0
    • pattern

      TextPatternSpec pattern(String pattern)
      Generates a random string based on the specified pattern template. The template supports the following hashtags:
      • #a - alphanumeric character [a-z, A-Z, 0-9]
      • #c - lower case character [a-z]
      • #C - upper case character [A-Z]
      • #d - digit [0-9]
      • ## - hash symbol escape

      Examples:

      
         "#a#a#a" -> "k4W"
         "#d#d#d-#d#d#d-#d#d#d" -> "123-45-67"
         "Foo: #C#c#c" -> "Foo: Xyz"
         "###d#d#d" -> "#123"
       
      Specified by:
      pattern in interface TextGenerators
      Parameters:
      pattern - to generate
      Returns:
      string pattern generator
      Since:
      5.0.0
    • uuid

      Generates a UUID value as a string. By default, the generated string is formatted as UUID.toString().
      Specified by:
      uuid in interface TextGenerators
      Returns:
      UUID string generator
      Since:
      5.0.0
    • word

      Generates random words. This spec generates various word classes, including nouns, verbs, adjectives, and adverbs.

      Example:

      
       record Example(String word) {}
      
       Example example = Instancio.of(Example.class)
           .generate(field(Example::word), gen -> gen.text().word().noun())
           .create();
      
       // Sample output: Example[word=achievement]
       

      You can construct phrases or sentences using a Supplier:

      
       record Company(String website) {}
      
       Supplier<String> websiteSupplier = () -> String.format(
           "https://www.%s-%s.com",
           Instancio.gen().text().word().adjective().get(),
           Instancio.gen().text().word().noun().get());
      
       List<Company> companies = Instancio.ofList(Company.class)
           .size(3)
           .supply(field(Company::website), websiteSupplier)
           .create();
      
       // Sample output:
       [[Company[website=https://www.global-bidder.com],
         Company[website=https://www.independent-beat.com],
         Company[website=https://www.promotional-clock.com]]
       
      Specified by:
      word in interface TextGenerators
      Returns:
      word generator spec
      Since:
      5.1.0