Interface StringGeneratorSpec
- All Superinterfaces:
GeneratorSpec<String>,NullableGeneratorSpec<String>
- All Known Subinterfaces:
StringSpec
- Since:
- 1.0.1
-
Method Summary
Modifier and TypeMethodDescriptionIndicates that an empty string can be generated.allowEmpty(boolean isAllowed) Indicates if empty string can be generated.Generates an alphanumeric string, uppercase by default, that consists of characters[0-9A-Z].digits()Generates a string that consists of digits[0-9].hex()Generates a hexadecimal string, uppercase by default, that consists of characters[0-9A-F]length(int length) Specifies the length of the string to generate as returned byString.length(), or the number of code points when generating aunicode(UnicodeBlock...)string.length(int minLength, int maxLength) Specifies the length of the string to generate as returned byString.length(), or the number of code points when generating aunicode(UnicodeBlock...)string.Generates a lowercase string that consists of characters[a-z].maxLength(int length) Specifies the maximum length of the string to generate as returned byString.length(), or the number of code points when generating aunicode(UnicodeBlock...)string.minLength(int length) Specifies the minimum length of the string to generate as returned byString.length(), or the number of code points when generating aunicode(UnicodeBlock...)string.Generates a string that consists of characters[A-Za-z].nullable()Indicates thatnullvalue can be generated.Generates a string sequence that starts from"1"and increments by one.Specifies the prefix to prepend to generated strings.Specifies the suffix to append to generated strings.unicode(Character.UnicodeBlock... blocks) Generates a Unicode string that consists of random code points excluding the following character types:Character.PRIVATE_USECharacter.SURROGATECharacter.UNASSIGNEDGenerates an uppercase string that consists of characters[A-Z].
-
Method Details
-
prefix
Specifies the prefix to prepend to generated strings.- Parameters:
prefix- for generated strings- Returns:
- spec builder
- Since:
- 1.0.1
-
suffix
Specifies the suffix to append to generated strings.- Parameters:
suffix- for generated strings- Returns:
- spec builder
- Since:
- 2.7.0
-
allowEmpty
StringGeneratorSpec allowEmpty()Indicates that an empty string can be generated.- Returns:
- spec builder
- Since:
- 1.0.1
-
allowEmpty
Indicates if empty string can be generated.- Parameters:
isAllowed- iftrue, empty strings can be generated- Returns:
- spec builder
- Since:
- 2.7.0
-
length
Specifies the length of the string to generate as returned byString.length(), or the number of code points when generating aunicode(UnicodeBlock...)string.This method has no effect if
numericSequence()is specified.- Parameters:
length- exact length to generate- Returns:
- spec builder
-
length
Specifies the length of the string to generate as returned byString.length(), or the number of code points when generating aunicode(UnicodeBlock...)string.This method has no effect if
numericSequence()is specified.- Parameters:
minLength- minimum length (inclusive)maxLength- maximum length (inclusive)- Returns:
- spec builder
-
minLength
Specifies the minimum length of the string to generate as returned byString.length(), or the number of code points when generating aunicode(UnicodeBlock...)string.This method has no effect if
numericSequence()is specified.- Parameters:
length- minimum length (inclusive)- Returns:
- spec builder
- Since:
- 1.0.1
-
maxLength
Specifies the maximum length of the string to generate as returned byString.length(), or the number of code points when generating aunicode(UnicodeBlock...)string.This method has no effect if
numericSequence()is specified.- Parameters:
length- maximum length (inclusive)- Returns:
- spec builder
- Since:
- 1.0.1
-
lowerCase
StringGeneratorSpec lowerCase()Generates a lowercase string that consists of characters[a-z].Note: this method has no effect when used with any of the following methods:
- Returns:
- spec builder
-
upperCase
StringGeneratorSpec upperCase()Generates an uppercase string that consists of characters[A-Z].Note: this method has no effect when used with any of the following methods:
- Returns:
- spec builder
-
mixedCase
StringGeneratorSpec mixedCase()Generates a string that consists of characters[A-Za-z].Note: this method has no effect when used with any of the following methods:
- Returns:
- spec builder
-
alphaNumeric
StringGeneratorSpec alphaNumeric()Generates an alphanumeric string, uppercase by default, that consists of characters[0-9A-Z].The equivalent
Keys.STRING_TYPEsetting isStringType.ALPHANUMERIC.- Returns:
- spec builder
- See Also:
-
digits
StringGeneratorSpec digits()Generates a string that consists of digits[0-9].The equivalent
Keys.STRING_TYPEsetting isStringType.DIGITS.- Returns:
- spec builder
-
hex
StringGeneratorSpec hex()Generates a hexadecimal string, uppercase by default, that consists of characters[0-9A-F]The equivalent
Keys.STRING_TYPEsetting isStringType.HEX.- Returns:
- spec builder
- Since:
- 2.11.0
- See Also:
-
numericSequence
Generates a string sequence that starts from"1"and increments by one.The equivalent
Keys.STRING_TYPEsetting isStringType.NUMERIC_SEQUENCE.- Returns:
- spec builder
- Since:
- 4.7.0
-
unicode
Generates a Unicode string that consists of random code points excluding the following character types:This method accepts an optional vararg of
Character.UnicodeBlockobjects. If nounicodeBlocksare specified, code points will be generated from the range[0..0x3FFFF], for example:Comment comment = Instancio.of(Comment.class) .generate(field(Comment::getText), gen -> gen.string().unicode().length(10)) .create(); // Sample output: // Comment[text="𪬨鉢𓉰埗ᮓ웝𤈱恼棭騜"]If
unicodeBlocksare specified, code points will be chosen from the given Unicode blocks:Character.UnicodeBlock[] blocks = { Character.UnicodeBlock.EMOTICONS, Character.UnicodeBlock.CYRILLIC }; Comment comment = Instancio.of(Comment.class) .generate(field(Comment::getText), gen -> gen.string().length(10).unicode(blocks)) .create(); // Sample output: // Comment[text="ф😬😅😟фҖӝ😲ЭӍ"]The equivalent
Keys.STRING_TYPEsetting isStringType.UNICODE.- Parameters:
blocks- Unicode blocks to use when generating strings, or no argument to generate code points from random blocks- Returns:
- spec builder
- Since:
- 4.7.0
-
nullable
StringGeneratorSpec nullable()Indicates thatnullvalue can be generated.- Specified by:
nullablein interfaceNullableGeneratorSpec<String>- Returns:
- spec builder
-