Class Anonymizer.EmailAnonymizer

Enclosing class:
Anonymizer

public class Anonymizer.EmailAnonymizer extends Anonymizer.AbstractAnonymizer<String,Anonymizer.EmailAnonymizer>
Used to obfuscate a fields containing string values which respect the email format. If the context doesn't contain the field assigned to this instance, all the method of this class will not change the context.
  • Field Details

    • _pattern

      protected final Pattern _pattern
  • Constructor Details

    • EmailAnonymizer

      protected EmailAnonymizer(String field)
  • Method Details

    • addPrefix

      public Anonymizer.EmailAnonymizer addPrefix(String prefix)
      Add a prefix to the current field's value. Pay attention to call this method after the anonymize, otherwise the prefixed value will be overwritten. For example, we assume that anonymizeUsername(RandomToken.LOWERCASE) set the value "abc@domain.com". If we call this method after the anonymize
      anonymizeUsername(RandomToken.LOWERCASE).addPrefix("UNKNOWN_")
      into the context we will find the value "UNKNOWN_abc@domain.com". If we call the same methods but in the reverse order
      addPrefix("UNKNOWN_").anonymizeUsername(RandomToken.LOWERCASE)
      the context will be update with the value "abc@domain.com"; that's why the second method has overwritten the changes made by the first one.
      Parameters:
      prefix - string that will be appended before the current value
      Returns:
      a reference of this object.
      Throws:
      IllegalArgumentException - if the prefix contains characters not allowed by the email standard format.
    • anonymizeUsername

      public Anonymizer.EmailAnonymizer anonymizeUsername(String alphabet)
      Set a random string as username part (the string preceding the @ character) of the value field assigned to this instance. The length of the generated string will be the same as the original username part.
      Parameters:
      alphabet - String containing the characters that will be used to generate the random username. Typically you can use these predefined set of alphabet:
      Returns:
      a reference of this object.
      Throws:
      overit.geocall.asserts.AssertsException - if the alphabet is null or empty.
      IllegalArgumentException - if the alphabet contains characters not allowed by the email standard format.
    • anonymizeUsername

      public Anonymizer.EmailAnonymizer anonymizeUsername(String alphabet, int size)
      Set a random string as username part (the string preceding the @ character) of the value field assigned to this instance. The length of the generated string will be the same as the one specified by the size parameter.
      Parameters:
      alphabet - String containing the characters that will be used to generate the random username. Typically you can use these predefined set of alphabet:
      size - positive number indicating length of the generated username.
      Returns:
      a reference of this object.
      Throws:
      overit.geocall.asserts.AssertsException - if the alphabet is null or empty, or if the size is negative.
      IllegalArgumentException - if the alphabet contains characters not allowed by the email standard format.
    • anonymizeDomain

      public Anonymizer.EmailAnonymizer anonymizeDomain(String alphabet)
      Set a random string as domain part (the string following the @ character) of the value field assigned to this instance. The length of the generated string will be the same as the original domain part. Note that the domain part will not include the TOP LEVEL DOMAIN (the very last part of the email address, between the last dot character and the end of the email)
      Parameters:
      alphabet - String containing the characters that will be used to generate the random domain. Typically you can use these predefined set of alphabet:
      Returns:
      a reference of this object.
      Throws:
      overit.geocall.asserts.AssertsException - if the alphabet is null or empty.
      IllegalArgumentException - if the alphabet contains characters not allowed by the email standard format.
    • anonymizeDomain

      public Anonymizer.EmailAnonymizer anonymizeDomain(String alphabet, int size)
      Set a random string as domain part (the string following the @ character) of the value field assigned to this instance. The length of the generated string will be the same as the one specified by the size parameter. Note that the domain part will not include the TOP LEVEL DOMAIN (the very last part of the email address, between the last dot character and the end of the email)
      Parameters:
      alphabet - String containing the characters that will be used to generate the random domain. Typically you can use these predefined set of alphabet:
      size - positive number indicating length of the generated domain.
      Returns:
      a reference of this object.
      Throws:
      overit.geocall.asserts.AssertsException - if the alphabet is null or empty, or if the size is negative.
      IllegalArgumentException - if the alphabet contains characters not allowed by the email standard format.
    • anonymizeTLDomain

      public Anonymizer.EmailAnonymizer anonymizeTLDomain(String... candidates)
      Set a random string as top level domain part (the string following the @ character) of the value field assigned to this instance. The length of the generated string will be the same as the original domain part. Note that the top level domain part is the very last part of the email address, between the last dot character and the end of the email and will not include the DOMAIN. For example, given these email addresses:
      1. user@domain.com
      2. user@localhost
      3. user@domain.subdomain.org
      theirs top level domains are:
      1. com
      2. localhost
      3. org
      Parameters:
      candidates - list of the top level domains among which will be randomly chosen the one that will be replace the original.
      Returns:
      a reference of this object.
      Throws:
      overit.geocall.asserts.AssertsException - if the candidates is null.
      IllegalArgumentException - if the candidates contains characters not allowed by the email standard format.
    • getRandomString

      protected String getRandomString(String currentValue, String alphabet, Integer size)
    • getUsername

      protected String getUsername()
    • setUsername

      protected void setUsername(String username)
    • getDomain

      protected String getDomain()
    • setDomain

      protected void setDomain(String domain)
    • getTLDomain

      protected String getTLDomain()
    • setTLDomain

      protected void setTLDomain(String tld)
    • getEmailParts

      protected String[] getEmailParts()
    • validate

      protected void validate(String value)
      Overrides:
      validate in class Anonymizer.AbstractAnonymizer<String,Anonymizer.EmailAnonymizer>