Package net.datafaker.providers.base
Class Text
Generates random text in a flexible way.
- Since:
- 1.7.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class net.datafaker.providers.base.AbstractProvider
faker -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiontext()text(boolean includeDigit) text(int length) text(int minimumLength, int maximumLength) text(int minimumLength, int maximumLength, boolean includeUppercase) text(int minimumLength, int maximumLength, boolean includeUppercase, boolean includeSpecial) text(int minimumLength, int maximumLength, boolean includeUppercase, boolean includeSpecial, boolean includeDigit) For example, expressiontext(5, 15, true, false, truegenerates a random string of length 5 to 15 containing at least one upper case letter and at least one digit.text(Text.TextRuleConfig textRuleConfig) Allows to configure custom expected rules.Methods inherited from class net.datafaker.providers.base.AbstractProvider
equals, getFaker, hashCode, loadGenerators, resolve, resolve, toString
-
Field Details
-
EN_LOWERCASE
- See Also:
-
EN_UPPERCASE
- See Also:
-
DIGITS
- See Also:
-
DEFAULT_SPECIAL
- See Also:
-
-
Constructor Details
-
Text
-
-
Method Details
-
character
-
uppercaseCharacter
-
lowercaseCharacter
-
text
- Returns:
- A lowercase string of 20 to 80 characters long.
-
text
- Parameters:
includeDigit- if digits should be included- Returns:
- A lowercase string of 20 to 80 characters long.
-
text
- Parameters:
length- The length of the string to return- Returns:
- A lowercase string of exact length
-
text
- Parameters:
minimumLength- The minimum length (inclusive)maximumLength- The maximum length (inclusive)- Returns:
- A lowercase string between minimum and maximum length (inclusive)
-
text
-
text
public String text(int minimumLength, int maximumLength, boolean includeUppercase, boolean includeSpecial) -
text
public String text(int minimumLength, int maximumLength, boolean includeUppercase, boolean includeSpecial, boolean includeDigit) For example, expressiontext(5, 15, true, false, truegenerates a random string of length 5 to 15 containing at least one upper case letter and at least one digit.- Parameters:
minimumLength- The generated text will not be shorter than this lengthmaximumLength- The generated text will not be longer than this lengthincludeUppercase- is at least one uppercase letter requiredincludeSpecial- is at least one special symbol requiredincludeDigit- is at least one digit required- Returns:
- a random string withing given length interval
- Throws:
IllegalArgumentException- ifminimumLength > maximumLengthIllegalArgumentException- ifmaximumLengthis not enough to include the required symbols (upper case letter, special char, digit)- See Also:
-
text
Allows to configure custom expected rules. Example
This will generate a text with length 5 containing minimum 1 lower case and 1 upper case symbol from en locale and minimum 1 digit. Custom symbol sets are also possiblefaker.text().text(Text.TextSymbolsBuilder.builder() .len(5) .with(EN_LOWERCASE, 1) .with(EN_UPPERCASE, 1) .with(DIGITS, 1);
This will generate a string with length between 8 and 10. The string will contain min 3 lower case symbols from ru locale and minimum 5 symbols from the defined string varfinal String ruLowerCase = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; final String customSpecialSymbols = "!@#$%^*;'][{}"; final int ruCnt = 3; final int specSmbCnt = 5; final Text.TextRuleConfig config = Text.TextSymbolsBuilder.builder() .len(faker.number().numberBetween(ruCnt + specSmbCnt, Math.max(ruCnt + specSmbCnt, 10))) .with(ruLowerCase, ruCnt) .with(customSpecialSymbols, specSmbCnt).build(); final String text = faker.text().text(config);final String customSpecialSymbols = "!@#$%^*;'][{}";.
-