-
Notifications
You must be signed in to change notification settings - Fork 858
/
Faker.java
655 lines (550 loc) · 16.3 KB
/
Faker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
package com.github.javafaker;
import com.github.javafaker.service.FakeValuesService;
import com.github.javafaker.service.RandomService;
import java.util.Locale;
import java.util.Random;
/**
* Provides utility methods for generating fake strings, such as names, phone
* numbers, addresses. generate random strings with given patterns
*
* @author ren
*/
public class Faker {
private final RandomService randomService;
private final FakeValuesService fakeValuesService;
private final Ancient ancient;
private final App app;
private final Artist artist;
private final Avatar avatar;
private final Aviation aviation;
private final Lorem lorem;
private final Music music;
private final Name name;
private final Number number;
private final Internet internet;
private final PhoneNumber phoneNumber;
private final Pokemon pokemon;
private final Address address;
private final Business business;
private final Book book;
private final ChuckNorris chuckNorris;
private final Color color;
private final Commerce commerce;
private final Country country;
private final Currency currency;
private final Company company;
private final Crypto crypto;
private final IdNumber idNumber;
private final Hacker hacker;
private final Options options;
private final Code code;
private final Finance finance;
private final Food food;
private final GameOfThrones gameOfThrones;
private final DateAndTime dateAndTime;
private final Demographic demographic;
private final Dog dog;
private final Educator educator;
private final ElderScrolls elderScrolls;
private final Shakespeare shakespeare;
private final SlackEmoji slackEmoji;
private final Space space;
private final Superhero superhero;
private final Bool bool;
private final Team team;
private final Beer beer;
private final University university;
private final Cat cat;
private final File file;
private final Stock stock;
private final LordOfTheRings lordOfTheRings;
private final Zelda zelda;
private final HarryPotter harryPotter;
private final RockBand rockBand;
private final Esports esports;
private final Friends friends;
private final Hipster hipster;
private final Job job;
private final TwinPeaks twinPeaks;
private final RickAndMorty rickAndMorty;
private final Yoda yoda;
private final Matz matz;
private final Witcher witcher;
private final DragonBall dragonBall;
private final FunnyName funnyName;
private final HitchhikersGuideToTheGalaxy hitchhikersGuideToTheGalaxy;
private final Hobbit hobbit;
private final HowIMetYourMother howIMetYourMother;
private final LeagueOfLegends leagueOfLegends;
private final Overwatch overwatch;
private final Robin robin;
private final StarTrek starTrek;
private final Weather weather;
private final Lebowski lebowski;
private final Medical medical;
private final Animal animal;
private final BackToTheFuture backToTheFuture;
private final PrincessBride princessBride;
private final Buffy buffy;
private final Relationships relationships;
private final Nation nation;
private final Dune dune;
private final AquaTeenHungerForce aquaTeenHungerForce;
private final ProgrammingLanguage programmingLanguage;
public Faker() {
this(Locale.ENGLISH);
}
public Faker(Locale locale) {
this(locale, (Random)null);
}
public Faker(Random random) {
this(Locale.ENGLISH, random);
}
public Faker(Locale locale, Random random) {
this(locale, new RandomService(random));
}
public Faker(Locale locale, RandomService randomService) {
this(new FakeValuesService(locale, randomService), randomService);
}
public Faker(FakeValuesService fakeValuesService, RandomService random) {
this.randomService = random;
this.fakeValuesService = fakeValuesService;
this.ancient = new Ancient(this);
this.app = new App(this);
this.artist = new Artist(this);
this.avatar = new Avatar(this);
this.aviation = new Aviation(this);
this.lorem = new Lorem(this);
this.music = new Music(this);
this.name = new Name(this);
this.number = new Number(this);
this.internet = new Internet(this);
this.phoneNumber = new PhoneNumber(this);
this.pokemon = new Pokemon(this);
this.address = new Address(this);
this.book = new Book(this);
this.business = new Business(this);
this.chuckNorris = new ChuckNorris(this);
this.color = new Color(this);
this.idNumber = new IdNumber(this);
this.hacker = new Hacker(this);
this.company = new Company(this);
this.crypto = new Crypto(this);
this.elderScrolls = new ElderScrolls(this);
this.commerce = new Commerce(this);
this.currency = new Currency(this);
this.options = new Options(this);
this.code = new Code(this);
this.file = new File(this);
this.finance = new Finance(this);
this.food = new Food(this);
this.gameOfThrones = new GameOfThrones(this);
this.dateAndTime = new DateAndTime(this);
this.demographic = new Demographic(this);
this.dog = new Dog(this);
this.educator = new Educator(this);
this.shakespeare = new Shakespeare(this);
this.slackEmoji = new SlackEmoji(this);
this.space = new Space(this);
this.superhero = new Superhero(this);
this.team = new Team(this);
this.bool = new Bool(this);
this.beer = new Beer(this);
this.university = new University(this);
this.cat = new Cat(this);
this.stock = new Stock(this);
this.lordOfTheRings = new LordOfTheRings(this);
this.zelda = new Zelda(this);
this.harryPotter = new HarryPotter(this);
this.rockBand = new RockBand(this);
this.esports = new Esports(this);
this.friends = new Friends(this);
this.hipster = new Hipster(this);
this.job = new Job(this);
this.twinPeaks = new TwinPeaks(this);
this.rickAndMorty = new RickAndMorty(this);
this.yoda = new Yoda(this);
this.matz = new Matz(this);
this.witcher = new Witcher(this);
this.dragonBall = new DragonBall(this);
this.funnyName = new FunnyName(this);
this.hitchhikersGuideToTheGalaxy = new HitchhikersGuideToTheGalaxy(this);
this.hobbit = new Hobbit(this);
this.howIMetYourMother = new HowIMetYourMother(this);
this.leagueOfLegends = new LeagueOfLegends(this);
this.overwatch = new Overwatch(this);
this.robin = new Robin(this);
this.starTrek = new StarTrek(this);
this.weather = new Weather(this);
this.lebowski = new Lebowski(this);
this.medical = new Medical(this);
this.country = new Country(this);
this.animal = new Animal(this);
this.backToTheFuture = new BackToTheFuture(this);
this.princessBride = new PrincessBride(this);
this.buffy = new Buffy(this);
this.relationships = new Relationships(this);
this.nation = new Nation(this);
this.dune = new Dune(this);
this.aquaTeenHungerForce = new AquaTeenHungerForce(this);
this.programmingLanguage = new ProgrammingLanguage(this);
}
/**
* Constructs Faker instance with default argument.
*
* @return {@link Faker#Faker()}
*/
public static Faker instance() {
return new Faker();
}
/**
* Constructs Faker instance with provided {@link Locale}.
*
* @param locale - {@link Locale}
* @return {@link Faker#Faker(Locale)}
*/
public static Faker instance(Locale locale) {
return new Faker(locale);
}
/**
* Constructs Faker instance with provided {@link Random}.
*
* @param random - {@link Random}
* @return {@link Faker#Faker(Random)}
*/
public static Faker instance(Random random) {
return new Faker(random);
}
/**
* Constructs Faker instance with provided {@link Locale} and {@link Random}.
*
* @param locale - {@link Locale}
* @param random - {@link Random}
* @return {@link Faker#Faker(Locale, Random)}
*/
public static Faker instance(Locale locale, Random random) {
return new Faker(locale, random);
}
/**
* Returns a string with the '#' characters in the parameter replaced with random digits between 0-9 inclusive.
* <p>
* For example, the string "ABC##EFG" could be replaced with a string like "ABC99EFG".
*
* @param numberString
* @return
*/
public String numerify(String numberString) {
return fakeValuesService.numerify(numberString);
}
/**
* Returns a string with the '?' characters in the parameter replaced with random alphabetic
* characters.
* <p>
* For example, the string "12??34" could be replaced with a string like "12AB34".
*
* @param letterString
* @return
*/
public String letterify(String letterString) {
return fakeValuesService.letterify(letterString);
}
/**
* Returns a string with the '?' characters in the parameter replaced with random alphabetic
* characters.
* <p>
* For example, the string "12??34" could be replaced with a string like "12AB34".
*
* @param letterString
* @param isUpper
* @return
*/
public String letterify(String letterString, boolean isUpper) {
return fakeValuesService.letterify(letterString, isUpper);
}
/**
* Applies both a {@link #numerify(String)} and a {@link #letterify(String)}
* over the incoming string.
*
* @param string
* @return
*/
public String bothify(String string) {
return fakeValuesService.bothify(string);
}
/**
* Applies both a {@link #numerify(String)} and a {@link #letterify(String)}
* over the incoming string.
*
* @param string
* @param isUpper
* @return
*/
public String bothify(String string, boolean isUpper) {
return fakeValuesService.bothify(string, isUpper);
}
/**
* Generates a String that matches the given regular expression.
*/
public String regexify(String regex) {
return fakeValuesService.regexify(regex);
}
public RandomService random() {
return this.randomService;
}
public Currency currency() {
return currency;
}
FakeValuesService fakeValuesService() {
return this.fakeValuesService;
}
public Ancient ancient() {
return ancient;
}
public App app() {
return app;
}
public Artist artist() {
return artist;
}
public Avatar avatar() {
return avatar;
}
public Aviation aviation() {
return aviation;
}
public Music music() {
return music;
}
public Name name() {
return name;
}
public Number number() {
return number;
}
public Internet internet() {
return internet;
}
public PhoneNumber phoneNumber() {
return phoneNumber;
}
public Pokemon pokemon() {
return pokemon;
}
public Lorem lorem() {
return lorem;
}
public Address address() {
return address;
}
public Book book() {
return book;
}
public Buffy buffy() {
return buffy;
}
public Business business() {
return business;
}
public ChuckNorris chuckNorris() {
return chuckNorris;
}
public Color color() {
return color;
}
public Commerce commerce() {
return commerce;
}
public Company company() {
return company;
}
public Crypto crypto() {
return crypto;
}
public Hacker hacker() {
return hacker;
}
public IdNumber idNumber() {
return idNumber;
}
public Options options() {
return options;
}
public Code code() {
return code;
}
public File file() {
return file;
}
public Finance finance() {
return finance;
}
public Food food() {
return food;
}
public ElderScrolls elderScrolls() {
return elderScrolls;
}
public GameOfThrones gameOfThrones() {
return gameOfThrones;
}
public DateAndTime date() {
return dateAndTime;
}
public Demographic demographic() {
return demographic;
}
public Dog dog() {
return dog;
}
public Educator educator() {
return educator;
}
public SlackEmoji slackEmoji() {
return slackEmoji;
}
public Shakespeare shakespeare() {
return shakespeare;
}
public Space space() {
return space;
}
public Superhero superhero() {
return superhero;
}
public Bool bool() {
return bool;
}
public Team team() {
return team;
}
public Beer beer() {
return beer;
}
public University university() {
return university;
}
public Cat cat() {
return cat;
}
public Stock stock() {
return stock;
}
public LordOfTheRings lordOfTheRings() {
return lordOfTheRings;
}
public Zelda zelda() {
return zelda;
}
public HarryPotter harryPotter() {
return harryPotter;
}
public RockBand rockBand() {
return rockBand;
}
public Esports esports() {
return esports;
}
public Friends friends() {
return friends;
}
public Hipster hipster() {
return hipster;
}
public Job job() {
return job;
}
public TwinPeaks twinPeaks() {
return twinPeaks;
}
public RickAndMorty rickAndMorty() {
return rickAndMorty;
}
public Yoda yoda() {
return yoda;
}
public Matz matz() {
return matz;
}
public Witcher witcher() {
return witcher;
}
public DragonBall dragonBall() {
return dragonBall;
}
public FunnyName funnyName() {
return funnyName;
}
public HitchhikersGuideToTheGalaxy hitchhikersGuideToTheGalaxy() {
return hitchhikersGuideToTheGalaxy;
}
public Hobbit hobbit() {
return hobbit;
}
public HowIMetYourMother howIMetYourMother() {
return howIMetYourMother;
}
public LeagueOfLegends leagueOfLegends() {
return leagueOfLegends;
}
public Overwatch overwatch() {
return overwatch;
}
public Robin robin() {
return robin;
}
public StarTrek starTrek() {
return starTrek;
}
public Weather weather() {
return weather;
}
public Lebowski lebowski() {
return lebowski;
}
public Medical medical(){return medical;}
public Country country(){ return country;}
public Animal animal(){ return animal; }
public BackToTheFuture backToTheFuture() {
return backToTheFuture;
}
public PrincessBride princessBride() {
return princessBride;
}
public Relationships relationships() {
return relationships;
}
public Nation nation() {
return nation;
}
public Dune dune() {
return dune;
}
public AquaTeenHungerForce aquaTeenHungerForce() {
return aquaTeenHungerForce;
}
public ProgrammingLanguage programmingLanguage() {
return programmingLanguage;
}
public String resolve(String key) {
return this.fakeValuesService.resolve(key, this, this);
}
/**
* Allows the evaluation of native YML expressions to allow you to build your own.
* <p>
* The following are valid expressions:
* <ul>
* <li>#{regexify '(a|b){2,3}'}</li>
* <li>#{regexify '\\.\\*\\?\\+'}</li>
* <li>#{bothify '????','false'}</li>
* <li>#{Name.first_name} #{Name.first_name} #{Name.last_name}</li>
* <li>#{number.number_between '1','10'}</li>
* </ul>
*
* @param expression (see examples above)
* @return the evaluated string expression
* @throws RuntimeException if unable to evaluate the expression
*/
public String expression(String expression) {
return this.fakeValuesService.expression(expression, this);
}
}