public class FakeValuesService
extends java.lang.Object
Constructor and Description |
---|
FakeValuesService(java.util.Locale locale,
RandomService randomService)
Resolves YAML file using the most specific path first based on language and country code.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
bothify(java.lang.String string)
Applies both a
numerify(String) and a letterify(String)
over the incoming string. |
java.lang.String |
bothify(java.lang.String string,
boolean isUpper)
Applies both a
numerify(String) and a letterify(String,boolean)
over the incoming string. |
java.lang.String |
expression(java.lang.String expression,
Faker faker)
resolves an expression using the current faker.
|
protected java.util.Map |
fakerFromStream(java.io.InputStream stream,
java.lang.String localeName) |
java.lang.Object |
fetch(java.lang.String key)
Fetch a random value from an array item specified by the key
|
java.lang.Object |
fetchObject(java.lang.String key)
Return the object selected by the key from yaml file.
|
java.lang.String |
fetchString(java.lang.String key)
Same as
fetch(String) except this casts the result into a String. |
java.lang.String |
letterify(java.lang.String letterString)
Returns a string with the '?' characters in the parameter replaced with random alphabetic
characters.
|
java.lang.String |
letterify(java.lang.String letterString,
boolean isUpper)
Returns a string with the '?' characters in the parameter replaced with random alphabetic
characters.
|
protected java.util.List<java.util.Locale> |
localeChain(java.util.Locale from)
Convert the specified locale into a chain of locales used for message resolution.
|
java.lang.String |
numerify(java.lang.String numberString)
Returns a string with the '#' characters in the parameter replaced with random digits between 0-9 inclusive.
|
java.lang.String |
regexify(java.lang.String regex)
Generates a String that matches the given regular expression.
|
java.lang.String |
resolve(java.lang.String key,
java.lang.Object current,
Faker root)
Resolves a key to a method on an object.
|
protected java.lang.String |
resolveExpression(java.lang.String expression,
java.lang.Object current,
Faker root)
processes a expression in the style #{X.y} using the current objects as the 'current' location
within the yml file (or the
Faker object hierarchy as it were). |
java.lang.String |
safeFetch(java.lang.String key,
java.lang.String defaultIfNull)
Safely fetches a key.
|
public FakeValuesService(java.util.Locale locale, RandomService randomService)
Resolves YAML file using the most specific path first based on language and country code. 'en_US' would resolve in the following order:
Locale
instance. This is legacy behavior and not
condoned, but it will work.
locale
- randomService
- protected java.util.Map fakerFromStream(java.io.InputStream stream, java.lang.String localeName)
protected java.util.List<java.util.Locale> localeChain(java.util.Locale from)
Locale.FRANCE
(fr_FR) -> [ fr_FR, fr, en ]Locale
instancespublic java.lang.Object fetch(java.lang.String key)
key
- public java.lang.String fetchString(java.lang.String key)
fetch(String)
except this casts the result into a String.key
- public java.lang.String safeFetch(java.lang.String key, java.lang.String defaultIfNull)
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.
key
- the key to fetch from the YML structure.defaultIfNull
- the value to return if the fetched value is nullpublic java.lang.Object fetchObject(java.lang.String key)
key
- key contains path to an object. Path segment is separated by
dot. E.g. name.first_namepublic java.lang.String numerify(java.lang.String numberString)
numberString
- public java.lang.String bothify(java.lang.String string)
numerify(String)
and a letterify(String)
over the incoming string.string
- public java.lang.String bothify(java.lang.String string, boolean isUpper)
numerify(String)
and a letterify(String,boolean)
over the incoming string.string
- isUpper
- public java.lang.String regexify(java.lang.String regex)
public java.lang.String letterify(java.lang.String letterString)
letterString
- public java.lang.String letterify(java.lang.String letterString, boolean isUpper)
letterString
- isUpper
- specifies whether or not letters should be upper casepublic java.lang.String resolve(java.lang.String key, java.lang.Object current, Faker root)
public java.lang.String expression(java.lang.String expression, Faker faker)
expression
- faker
- protected java.lang.String resolveExpression(java.lang.String expression, java.lang.Object current, Faker root)
processes a expression in the style #{X.y} using the current objects as the 'current' location
within the yml file (or the Faker
object hierarchy as it were).
#{Address.streetName} would get resolved to Faker.address()
's Address.streetName()
#{address.street} would get resolved to the YAML > 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
Faker.address()
's Address.streetName()
.
Copyright © 2018. All Rights Reserved.