Interface StringSpec
- All Superinterfaces:
GeneratorSpec<String>,NullableGeneratorSpec<String>,StringGeneratorSpec,Supplier<String>,ValueSpec<String>
String values.- Since:
- 2.6.0
-
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 aStringGeneratorSpec.unicode(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 aStringGeneratorSpec.unicode(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 aStringGeneratorSpec.unicode(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 aStringGeneratorSpec.unicode(UnicodeBlock...)string.Generates a string that consists of characters[A-Za-z].nullable()Specifies that anullvalue can be generatedGenerates 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
Description copied from interface:StringGeneratorSpecSpecifies the prefix to prepend to generated strings.- Specified by:
prefixin interfaceStringGeneratorSpec- Parameters:
prefix- for generated strings- Returns:
- spec builder
-
suffix
Description copied from interface:StringGeneratorSpecSpecifies the suffix to append to generated strings.- Specified by:
suffixin interfaceStringGeneratorSpec- Parameters:
suffix- for generated strings- Returns:
- spec builder
-
nullable
StringSpec nullable()Description copied from interface:ValueSpecSpecifies that anullvalue can be generated- Specified by:
nullablein interfaceNullableGeneratorSpec<String>- Specified by:
nullablein interfaceStringGeneratorSpec- Specified by:
nullablein interfaceValueSpec<String>- Returns:
- spec builder reference
-
allowEmpty
StringSpec allowEmpty()Description copied from interface:StringGeneratorSpecIndicates that an empty string can be generated.- Specified by:
allowEmptyin interfaceStringGeneratorSpec- Returns:
- spec builder
-
allowEmpty
Description copied from interface:StringGeneratorSpecIndicates if empty string can be generated.- Specified by:
allowEmptyin interfaceStringGeneratorSpec- Parameters:
isAllowed- iftrue, empty strings can be generated- Returns:
- spec builder
-
length
Description copied from interface:StringGeneratorSpecSpecifies the length of the string to generate as returned byString.length(), or the number of code points when generating aStringGeneratorSpec.unicode(UnicodeBlock...)string.This method has no effect if
StringGeneratorSpec.numericSequence()is specified.- Specified by:
lengthin interfaceStringGeneratorSpec- Parameters:
length- exact length to generate- Returns:
- spec builder
-
length
Description copied from interface:StringGeneratorSpecSpecifies the length of the string to generate as returned byString.length(), or the number of code points when generating aStringGeneratorSpec.unicode(UnicodeBlock...)string.This method has no effect if
StringGeneratorSpec.numericSequence()is specified.- Specified by:
lengthin interfaceStringGeneratorSpec- Parameters:
minLength- minimum length (inclusive)maxLength- maximum length (inclusive)- Returns:
- spec builder
-
minLength
Description copied from interface:StringGeneratorSpecSpecifies the minimum length of the string to generate as returned byString.length(), or the number of code points when generating aStringGeneratorSpec.unicode(UnicodeBlock...)string.This method has no effect if
StringGeneratorSpec.numericSequence()is specified.- Specified by:
minLengthin interfaceStringGeneratorSpec- Parameters:
length- minimum length (inclusive)- Returns:
- spec builder
-
maxLength
Description copied from interface:StringGeneratorSpecSpecifies the maximum length of the string to generate as returned byString.length(), or the number of code points when generating aStringGeneratorSpec.unicode(UnicodeBlock...)string.This method has no effect if
StringGeneratorSpec.numericSequence()is specified.- Specified by:
maxLengthin interfaceStringGeneratorSpec- Parameters:
length- maximum length (inclusive)- Returns:
- spec builder
-
lowerCase
StringSpec lowerCase()Description copied from interface:StringGeneratorSpecGenerates a lowercase string that consists of characters[a-z].Note: this method has no effect when used with any of the following methods:
- Specified by:
lowerCasein interfaceStringGeneratorSpec- Returns:
- spec builder
-
upperCase
StringSpec upperCase()Description copied from interface:StringGeneratorSpecGenerates an uppercase string that consists of characters[A-Z].Note: this method has no effect when used with any of the following methods:
- Specified by:
upperCasein interfaceStringGeneratorSpec- Returns:
- spec builder
-
mixedCase
StringSpec mixedCase()Description copied from interface:StringGeneratorSpecGenerates a string that consists of characters[A-Za-z].Note: this method has no effect when used with any of the following methods:
- Specified by:
mixedCasein interfaceStringGeneratorSpec- Returns:
- spec builder
-
alphaNumeric
StringSpec alphaNumeric()Description copied from interface:StringGeneratorSpecGenerates an alphanumeric string, uppercase by default, that consists of characters[0-9A-Z].The equivalent
Keys.STRING_TYPEsetting isStringType.ALPHANUMERIC.- Specified by:
alphaNumericin interfaceStringGeneratorSpec- Returns:
- spec builder
- See Also:
-
digits
StringSpec digits()Description copied from interface:StringGeneratorSpecGenerates a string that consists of digits[0-9].The equivalent
Keys.STRING_TYPEsetting isStringType.DIGITS.- Specified by:
digitsin interfaceStringGeneratorSpec- Returns:
- spec builder
-
hex
StringSpec hex()Generates a hexadecimal string, uppercase by default, that consists of characters[0-9A-F]The equivalent
Keys.STRING_TYPEsetting isStringType.HEX.- Specified by:
hexin interfaceStringGeneratorSpec- Returns:
- spec builder
- Since:
- 2.11.0
- See Also:
-
numericSequence
StringSpec numericSequence()Generates a string sequence that starts from"1"and increments by one.The equivalent
Keys.STRING_TYPEsetting isStringType.NUMERIC_SEQUENCE.- Specified by:
numericSequencein interfaceStringGeneratorSpec- 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.- Specified by:
unicodein interfaceStringGeneratorSpec- 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
-