Package org.instancio.generators
Interface TextGenerators
- All Known Subinterfaces:
TextSpecs
public interface TextGenerators
Contains built-in text generators.
- Since:
- 1.1.9
-
Method Summary
Modifier and TypeMethodDescriptioncsv()Generates CSV.Generates "Lorem ipsum" text.Generates a random string based on the specified pattern template.uuid()Generates aUUIDvalue as a string.word()Generates random words.wordTemplate(String template) Generates strings based on the specified template.
-
Method Details
-
csv
Generates CSV.- Returns:
- CSV generator
- Since:
- 2.12.0
-
loremIpsum
LoremIpsumGeneratorSpec loremIpsum()Generates "Lorem ipsum" text.- Returns:
- lorem ipsum text generator
- Since:
- 1.5.3
-
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"- Parameters:
pattern- to generate- Returns:
- string pattern generator
- Since:
- 1.1.9
-
uuid
UUIDStringGeneratorSpec uuid()Generates aUUIDvalue as a string. By default, the generated string is formatted asUUID.toString().- Returns:
UUIDstring generator- Since:
- 1.5.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]]- Returns:
- word generator spec
- Since:
- 5.1.0
- See Also:
-
wordTemplate
Generates strings based on the specified template.The template can include placeholders representing different parts of speech, such as:
${adjective}produces a random adjective${adverb}produces a random adverb${noun}produces a random noun${verb}produces a random verb
These placeholders will be dynamically replaced with randomly generated words matching their respective categories. For example:
record Company(String website) {} List<Company> companies = Instancio.ofList(Company.class) .size(3) .generate(field(Company::website), gen -> gen.text().wordTemplate("${adjective}-${noun}.com")) .create(); // Sample output: [[Company[website=global-bidder.com], Company[website=independent-beat.com], Company[website=promotional-clock.com]]The placeholders are case-sensitive and support three case styles for the output, for example:
${noun}- Outputs a lowercase word (e.g., "cat").${Noun}- Outputs a capitalised word (e.g., "Cat").${NOUN}- Outputs an uppercase word (e.g., "CAT").
Note: The behavior for mixed-case placeholders, such as
${NoUn}, is undefined. Avoid using such placeholders to ensure consistent results.- Parameters:
template- the template from which to generate strings- Returns:
- word template generator spec
- Since:
- 5.2.0
- See Also:
-