Package rs.baselib.test
Class PersonBuilder
java.lang.Object
rs.baselib.test.PersonBuilder
- All Implemented Interfaces:
Builder<PersonBuilder.Person>
Provides a way to generate personal information (see
PersonBuilder.Person
randomly.- Author:
- ralph
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Information about a random, fictious person. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build the previously configured object.loadUrlList
(URL url) Load a list of string from a URL.withFirstNames
(File firstNamesFile) Use the first names from this file (one name per line).withFirstNames
(String firstNamesFilename) Use the first names from this file (one name per line).withFirstNames
(URL firstNamesUrl) Use the first names from this URL (one name per line).withFirstNames
(Collection<String> firstNames) Use these first names when building a person.withGenders
(Collection<String> genders) Build the persons with the given set of genders.withLastNames
(File lastNamesFile) Use the last names from this file (one name per line).withLastNames
(String lastNamesFilename) Use the last names from this file (one name per line).withLastNames
(URL lastNamesUrl) Use the last names from this URL (one name per line).withLastNames
(Collection<String> lastNames) Use these last names when building a person.withMaxAge
(int maxAge) Generate person with this maximum age (exclusive, default is 70).withMinAge
(int minAge) Generate person with this minimum age (inclusive, default is 18).Build persons without first names.Build the persons without genders.Build persons without last names.
-
Constructor Details
-
PersonBuilder
public PersonBuilder()Constructor.
-
-
Method Details
-
withGenders
Build the persons with the given set of genders.Default set is { "MALE", "FEMALE", "DIVERSE" }.
- Parameters:
genders
- - list of genders to randomly pick from (null
will leave gender blank)- Returns:
- this builder for method chaining
-
withoutGenders
Build the persons without genders.- Returns:
- this builder for method chaining
-
withFirstNames
Use these first names when building a person.- Parameters:
firstNames
- - list of names to randomly pick from (null
will leave first names blank)- Returns:
- this builder for method chaining
-
withoutFirstNames
Build persons without first names.- Returns:
- this builder for method chaining
-
withFirstNames
Use the first names from this file (one name per line).- Parameters:
firstNamesFilename
- - filename of file- Returns:
- this builder for method chaining
- Throws:
IOException
- - when the content cannot be loaded
-
withFirstNames
Use the first names from this file (one name per line).- Parameters:
firstNamesFile
- - file object- Returns:
- this builder for method chaining
- Throws:
IOException
- - when the content cannot be loaded
-
withFirstNames
Use the first names from this URL (one name per line).- Parameters:
firstNamesUrl
- - URL to load from- Returns:
- this builder for method chaining
- Throws:
IOException
- - when the content cannot be loaded
-
withLastNames
Use these last names when building a person.- Parameters:
lastNames
- - list of names to randomly pick from (null
will leave last name blank)- Returns:
- this builder for method chaining
-
withoutLastNames
Build persons without last names.- Returns:
- this builder for method chaining
-
withLastNames
Use the last names from this file (one name per line).- Parameters:
lastNamesFilename
- - filename of file to load from- Returns:
- this builder for method chaining
- Throws:
IOException
- - when the content cannot be loaded
-
withLastNames
Use the last names from this file (one name per line).- Parameters:
lastNamesFile
- - file object- Returns:
- this builder for method chaining
- Throws:
IOException
- - when the content cannot be loaded
-
withLastNames
Use the last names from this URL (one name per line).- Parameters:
lastNamesUrl
- - URL to load from- Returns:
- this builder for method chaining
- Throws:
IOException
- - when the content cannot be loaded
-
withMinAge
Generate person with this minimum age (inclusive, default is 18).- Parameters:
minAge
- - minimum age to be produced- Returns:
- this builder for method chaining
-
withMaxAge
Generate person with this maximum age (exclusive, default is 70).- Parameters:
maxAge
- - maximum age to be produced- Returns:
- this builder for method chaining
-
build
Build the previously configured object.- Specified by:
build
in interfaceBuilder<PersonBuilder.Person>
- Returns:
- the built object
-
loadUrlList
Load a list of string from a URL.- Parameters:
url
- - URL to be loaded from- Returns:
- the collection of strings loaded
- Throws:
IOException
- - when the content cannot be loaded
-