Class BaseFaker
- All Implemented Interfaces:
BaseProviders
,ProviderRegistration
- Direct Known Subclasses:
EntertainmentFaker
,Faker
,FoodFaker
,SportFaker
,VideoGameFaker
- Author:
- ren
-
Constructor Summary
ConstructorDescriptionBaseFaker
(Locale locale, RandomService randomService) BaseFaker
(FakeValuesService fakeValuesService, FakerContext context) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Allows to add paths to files with custom data.void
Allows to add urls of files with custom data.Applies both anumerify(String)
and aletterify(String)
over the incoming string.Applies both anumerify(String)
and aletterify(String)
over the incoming string.<T> FakeSequence.Builder<T>
final <T> FakeSequence.Builder<T>
collection
(Supplier<T>... suppliers) final <T> FakeSequence.Builder<T>
collection
(List<Supplier<T>> suppliers) Returns a string with generated csv based number of lines and column expressions.Returns a string with generated csv based number of lines and column expressions.<T> T
<T> T
<T> T
Generates a String by example.expression
(String expression) Allows the evaluation of native YML expressions to allow you to build your own.final <B extends ProviderRegistration>
BgetFaker()
static Method
getMethod
(AbstractProvider<?> ap, String methodName) static <PR extends ProviderRegistration,
AP extends AbstractProvider<PR>>
APgetProvider
(Class<AP> clazz, Function<PR, AP> valueSupplier, PR faker) static AbstractProvider<?>
getProvider
(String className, FakerContext context) Returns a string with the '?' characters in the parameter replaced with random alphabetic characters.Returns a string with the '?' characters in the parameter replaced with random alphabetic characters.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 <T> T
static <T> T
random()
Generates a String that matches the given regular expression.<T> FakeSequence.Builder<T>
stream()
final <T> FakeSequence.Builder<T>
final <T> FakeSequence.Builder<T>
templatify
(String string, char char2replace, String... options) Returns a string with the char2replace characters in the parameter replaced with random option from available options.templatify
(String string, Map<Character, String[]> optionsMap) Returns a string with the characters in the keys of optionsMap parameter replaced with random option from values.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.datafaker.providers.base.BaseProviders
address, ancient, animal, app, appliance, artist, australia, aviation, aws, azure, barcode, bloodtype, book, bool, brand, business, camera, cannabis, cat, chiquito, cnpj, code, coin, color, commerce, community, company, compass, computer, construction, cosmere, country, cpf, cryptoCoin, cultureSeries, currency, date, dcComics, demographic, device, disease, dog, domain, drivingLicense, drone, dungeonsAndDragons, duration, educator, electricalComponents, emoji, famousLastWords, file, finance, funnyName, garmentSize, gender, greekPhilosopher, hacker, hashing, hipster, hobby, hololive, horse, house, idNumber, industrySegments, internet, job, kpop, locality, lorem, marketing, matz, mbti, measurement, medical, military, money, mood, mountain, mountaineering, music, name, nation, natoPhoneticAlphabet, nigeria, number, olympicSport, passport, phoneNumber, photography, programmingLanguage, relationships, restaurant, robin, rockBand, science, shakespeare, sip, size, slackEmoji, space, stock, subscription, superhero, team, text, time, transport, twitter, unique, university, vehicle, verb, weather, yoda, zodiac
Methods inherited from interface net.datafaker.providers.base.ProviderRegistration
getProvider, options
-
Constructor Details
-
BaseFaker
public BaseFaker() -
BaseFaker
-
BaseFaker
-
BaseFaker
-
BaseFaker
-
BaseFaker
-
-
Method Details
-
getContext
- Specified by:
getContext
in interfaceProviderRegistration
-
doWith
-
doWith
-
doWith
-
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" and the string "Ø##" with a value like "149".
- Specified by:
numerify
in interfaceProviderRegistration
- Parameters:
numberString
- Template for string generation- Returns:
- Generated 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".
- Specified by:
letterify
in interfaceProviderRegistration
- Parameters:
letterString
- Template for string generation- Returns:
- Generated 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".
- Specified by:
letterify
in interfaceProviderRegistration
-
bothify
Applies both anumerify(String)
and aletterify(String)
over the incoming string.- Specified by:
bothify
in interfaceProviderRegistration
-
bothify
Applies both anumerify(String)
and aletterify(String)
over the incoming string.- Specified by:
bothify
in interfaceProviderRegistration
-
regexify
Generates a String that matches the given regular expression.- Specified by:
regexify
in interfaceProviderRegistration
-
examplify
Generates a String by example. The output string will have the same pattern as the input string.For example: "AAA" becomes "KRA" "abc" becomes "uio" "948" becomes "345" "A19c" becomes "Z20d"
- Specified by:
examplify
in interfaceProviderRegistration
- Parameters:
example
- The input string- Returns:
- The output string based on the input pattern
-
templatify
Returns a string with the char2replace characters in the parameter replaced with random option from available options.For example, the string "ABC??EFG" could be replaced with a string like "ABCtestтестEFG" if passed options are new String[]{"test", "тест"}.
- Specified by:
templatify
in interfaceProviderRegistration
- Parameters:
string
- Template for string generationchar2replace
- Char to replaceoptions
- Options to use while filling the template- Returns:
- Generated string
-
templatify
Returns a string with the characters in the keys of optionsMap parameter replaced with random option from values.For example, the string "ABC$$EFG" could be replaced with a string like "ABCtestтестEFG" if passed for key '$' there is value new String[]{"test", "тест"} in optionsMap
- Specified by:
templatify
in interfaceProviderRegistration
- Parameters:
string
- Template for string generationoptionsMap
- Map with replacement rules- Returns:
- Generated string
-
csv
Returns a string with generated csv based number of lines and column expressions. This method will use comma as default delimiter, always prints header and double quote as default quote.For example, it could generate "name_column","last_name_column" "Sabrina","Kihn"
for expression
faker.expression("#{csv '1','name_column','#{Name.first_name}','last_name_column','#{Name.last_name}'}");
- Specified by:
csv
in interfaceProviderRegistration
- Parameters:
limit
- Number of linescolumnExpressions
- Even number of expressions. The odd numbers args are used for columns names, and even for column values.- Returns:
- Generated string
-
csv
public String csv(String separator, char quote, boolean withHeader, int limit, String... columnExpressions) Returns a string with generated csv based number of lines and column expressions.For example, it could generate "Thad" ### "Crist" "Kathryne" ### "Wuckert" "Sybil" ### "Connelly"
for expression
faker.expression("#{csv ' ### ','"','false','3','name_column','#{Name.first_name}','last_name_column','#{Name.last_name}'}");
- Specified by:
csv
in interfaceProviderRegistration
- Parameters:
separator
- Delimiter to usequote
- Quote to usewithHeader
- Print header or notlimit
- Number of linescolumnExpressions
- Even number of expressions. The odd numbers args are used for columns names, and even for column values.- Returns:
- Generated string
-
json
- Specified by:
json
in interfaceProviderRegistration
-
jsona
- Specified by:
jsona
in interfaceProviderRegistration
-
random
- Specified by:
random
in interfaceProviderRegistration
-
fakeValuesService
- Specified by:
fakeValuesService
in interfaceProviderRegistration
-
addPath
Allows to add paths to files with custom data. Data should be in YAML format.- Specified by:
addPath
in interfaceProviderRegistration
- 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 to add urls of files with custom data. Data should be in YAML format.- Specified by:
addUrl
in interfaceProviderRegistration
- 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
-
populate
-
populate
-
getProvider
public static <PR extends ProviderRegistration,AP extends AbstractProvider<PR>> AP getProvider(Class<AP> clazz, Function<PR, AP> valueSupplier, PR faker) -
collection
- Returns:
- builder to build
FakeCollection
-
collection
-
collection
-
stream
- Returns:
- builder to build
FakeStream
-
stream
-
stream
-
resolve
- Specified by:
resolve
in interfaceProviderRegistration
-
resolve
- Specified by:
resolve
in interfaceProviderRegistration
-
expression
Allows the evaluation of native YML expressions to allow you to build your own.The following are valid expressions:
- #{regexify '(a|b){2,3}'}
- #{regexify '\\.\\*\\?\\+'}
- #{bothify '????','false'}
- #{Name.first_name} #{Name.first_name} #{Name.last_name}
- #{number.number_between '1','10'}
- Specified by:
expression
in interfaceProviderRegistration
- Parameters:
expression
- (see examples above)- Returns:
- the evaluated string expression
- Throws:
RuntimeException
- if unable to evaluate the expression
-
getFaker
- Specified by:
getFaker
in interfaceProviderRegistration
-
getProvider
-
getMethod
-