-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Allows adding paths to files with custom data.void
Allows adding urls of files with custom data.bothify
(String string, FakerContext context) Applies both anumerify(String, FakerContext)
and aletterify(String, FakerContext)
over the incoming string.bothify
(String input, FakerContext context, boolean isUpper) Applies both anumerify(String, FakerContext)
and aletterify(String, FakerContext, boolean)
over the incoming string.Generates csv based on input column expressions and number of lines.Generates csv based on input.examplify
(String example, FakerContext context) Generates a String by example.expression
(String expression, BaseFaker faker, FakerContext context) Resolves an expression using the current faker.fetch
(String key, FakerContext context) Fetch a random value from an array item specified by the keyfetchObject
(String key, FakerContext context) Return the object selected by the key from yaml file.fetchString
(String key, FakerContext context) Same asfetch(String, FakerContext)
except this casts the result into a String.fileExpression
(Path path, BaseFaker faker, FakerContext context) Resolves an expression in file using the current faker.Generates json based on input.Generates json based on input.letterify
(String letterString, FakerContext context) Returns a string with the '?' characters in the parameter replaced with random alphabetic characters.letterify
(String letterString, FakerContext context, boolean isUpper) Returns a string with the '?' characters in the parameter replaced with random alphabetic characters.numerify
(String numberString, FakerContext context) Returns a string with the '#' characters in the parameter replaced with random digits between 0-9 inclusive or random digits in the range from 1-9 when Ø (not zero) is used.static Class<?>
primitiveToWrapper
(Class<?> cls) regexify
(String regex, FakerContext context) Generates a String that matches the given regular expression.resolve
(String key, Object current, BaseFaker root, FakerContext context) Resolves a key to a method on an object or throws an exception.resolve
(String key, Object current, ProviderRegistration root, Supplier<String> exceptionMessage, FakerContext context) Resolves a key to a method on an object or throws an exception with specified message.resolve
(String key, AbstractProvider<?> provider, FakerContext context) protected String
resolveExpression
(String expression, Object current, ProviderRegistration root, FakerContext context) processes a expression in the style #{X.y} using the current objects as the 'current' location within the yml file (or theBaseFaker
object hierarchy as it were).safeFetch
(String key, FakerContext context, String defaultIfNull) Safely fetches a key.templatify
(String letterString, char char2replace, FakerContext context, String... options) Returns a string with the char2replace characters in the parameter replaced with random alphabetic characters from optionstemplatify
(String letterString, Map<Character, String[]> optionsMap, FakerContext context) Returns a string with the optionsMap.getKeys() characters in the parameter replaced with random alphabetic characters from corresponding optionsMap.values()void
updateFakeValuesInterfaceMap
(List<SingletonLocale> locales)
-
Field Details
-
MAP_STRING_OBJECT_SUPPLIER
-
MAP_STRING_STRING_SUPPLIER
-
DEFAULT_LOCALE
-
-
Constructor Details
-
FakeValuesService
public FakeValuesService()
-
-
Method Details
-
updateFakeValuesInterfaceMap
-
addPath
Allows adding paths to files with custom data. Data should be in YAML format.- Parameters:
locale
- the locale for which a path is going to be added.path
- path to a file with YAML structure- Throws:
IllegalArgumentException
- in case of invalid path
-
addUrl
Allows adding urls of files with custom data. Data should be in YAML format.- Parameters:
locale
- the locale for which an url is going to be added.url
- url of a file with YAML structure- Throws:
IllegalArgumentException
- in case of invalid url
-
fetch
Fetch a random value from an array item specified by the key -
fetchString
Same asfetch(String, FakerContext)
except this casts the result into a String. -
safeFetch
Safely fetches a key.If the value is null, it will return an empty string.
If it is a list, it will assume it is a list of strings and select a random value from it.
If the retrieved value is an slash encoded regular expression such as
/[a-b]/
then the regex will be converted to a regexify expression and returned (ex.#regexify '[a-b]'
)Otherwise it will just return the value as a string.
- Parameters:
key
- the key to fetch from the YML structure.defaultIfNull
- the value to return if the fetched value is null- Returns:
- see above
-
fetchObject
Return the object selected by the key from yaml file.- Parameters:
key
- key contains path to an object. Path segment is separated by dot. E.g. name.first_name
-
numerify
Returns a string with the '#' characters in the parameter replaced with random digits between 0-9 inclusive or random digits in the range from 1-9 when Ø (not zero) is used.For example, the string "ABC##EFG" could be replaced with a string like "ABC99EFG".
-
bothify
Applies both anumerify(String, FakerContext)
and aletterify(String, FakerContext)
over the incoming string. -
bothify
Applies both anumerify(String, FakerContext)
and aletterify(String, FakerContext, boolean)
over the incoming string. -
regexify
Generates a String that matches the given regular expression. -
examplify
Generates a String by example. The output string will have the same pattern as the input string. -
letterify
Returns a string with the '?' characters in the parameter replaced with random alphabetic characters.For example, the string "12??34" could be replaced with a string like "12AB34".
-
letterify
Returns a string with the '?' characters in the parameter replaced with random alphabetic characters.For example, the string "12??34" could be replaced with a string like "12AB34".
-
templatify
public String templatify(String letterString, char char2replace, FakerContext context, String... options) Returns a string with the char2replace characters in the parameter replaced with random alphabetic characters from options -
templatify
public String templatify(String letterString, Map<Character, String[]> optionsMap, FakerContext context) Returns a string with the optionsMap.getKeys() characters in the parameter replaced with random alphabetic characters from corresponding optionsMap.values() -
resolve
Resolves a key to a method on an object or throws an exception.#{hello} with result in a method call to current.hello();
#{Person.hello_someone} will result in a method call to person.helloSomeone();
-
resolve
-
resolve
public String resolve(String key, Object current, ProviderRegistration root, Supplier<String> exceptionMessage, FakerContext context) Resolves a key to a method on an object or throws an exception with specified message.#{hello} with result in a method call to current.hello();
#{Person.hello_someone} will result in a method call to person.helloSomeone();
-
expression
Resolves an expression using the current faker. -
fileExpression
Resolves an expression in file using the current faker. -
csv
Generates csv based on input column expressions and number of lines. This method uses default separator, quote and always prints header. -
csv
public String csv(String delimiter, char quote, boolean withHeader, int limit, String... columnExpressions) Generates csv based on input. -
json
Generates json based on input. -
jsona
Generates json based on input. -
resolveExpression
protected String resolveExpression(String expression, Object current, ProviderRegistration root, FakerContext context) processes a expression in the style #{X.y} using the current objects as the 'current' location within the yml file (or theBaseFaker
object hierarchy as it were).#{Address.streetName} would get resolved to
BaseProviders.address()
'sAddress.streetName()
#{address.street} would get resolved to the YAML like locale: faker: address: street: Combinations are supported as well: "#{x} #{y}"Recursive templates are supported. if "#{x}" resolves to "#{Address.streetName}" then "#{x}" resolves to
BaseProviders.address()
'sAddress.streetName()
. -
primitiveToWrapper
-