Class PersonBuilder

java.lang.Object
rs.baselib.test.PersonBuilder
All Implemented Interfaces:
Builder<PersonBuilder.Person>

public class PersonBuilder extends Object implements Builder<PersonBuilder.Person>
Provides a way to generate personal information (see PersonBuilder.Person randomly.
Author:
ralph
  • Constructor Details

    • PersonBuilder

      public PersonBuilder()
      Constructor.
  • Method Details

    • withGenders

      public PersonBuilder withGenders(Collection<String> genders)
      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

      public PersonBuilder withoutGenders()
      Build the persons without genders.
      Returns:
      this builder for method chaining
    • withFirstNames

      public PersonBuilder withFirstNames(Collection<String> firstNames)
      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

      public PersonBuilder withoutFirstNames()
      Build persons without first names.
      Returns:
      this builder for method chaining
    • withFirstNames

      public PersonBuilder withFirstNames(String firstNamesFilename) throws IOException
      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

      public PersonBuilder withFirstNames(File firstNamesFile) throws IOException
      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

      public PersonBuilder withFirstNames(URL firstNamesUrl) throws IOException
      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

      public PersonBuilder withLastNames(Collection<String> lastNames)
      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

      public PersonBuilder withoutLastNames()
      Build persons without last names.
      Returns:
      this builder for method chaining
    • withLastNames

      public PersonBuilder withLastNames(String lastNamesFilename) throws IOException
      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

      public PersonBuilder withLastNames(File lastNamesFile) throws IOException
      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

      public PersonBuilder withLastNames(URL lastNamesUrl) throws IOException
      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

      public PersonBuilder withMinAge(int minAge)
      Generate person with this minimum age (inclusive, default is 18).
      Parameters:
      minAge - - minimum age to be produced
      Returns:
      this builder for method chaining
    • withMaxAge

      public PersonBuilder withMaxAge(int maxAge)
      Generate person with this maximum age (exclusive, default is 70).
      Parameters:
      maxAge - - maximum age to be produced
      Returns:
      this builder for method chaining
    • build

      public PersonBuilder.Person build()
      Build the previously configured object.
      Specified by:
      build in interface Builder<PersonBuilder.Person>
      Returns:
      the built object
    • loadUrlList

      protected static List<String> loadUrlList(URL url) throws IOException
      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