Class UsernameConfigurableStrategy

java.lang.Object
de.powerstat.validation.values.strategies.UsernameConfigurableStrategy
All Implemented Interfaces:
IUsernameStrategy
Direct Known Subclasses:
UsernameDefaultStrategy

public class UsernameConfigurableStrategy extends Object implements IUsernameStrategy
Configurable username validation strategy.
  • Field Details

  • Constructor Details

    • UsernameConfigurableStrategy

      protected UsernameConfigurableStrategy(int minLength, int maxLength, String regexp, UsernameConfigurableStrategy.HandleEMail emailHandling)
      Constructor.
      Parameters:
      minLength - Minimum allowed username length, must be >= 1
      maxLength - Maximum allowed username length, must be >= minLength and <= INTEGER.MAX_VALUE
      regexp - Regular expression for matching characters. Must start with ^ and end with $. Example: ^[@./_0-9a-zA-Z-]+$
      emailHandling - How email addresses as username should be handled: EMAIL_DENIED, EMAIL_REQUIRED or EMAIL_POSSIBLE
      Throws:
      IllegalArgumentException - If arguments are not as required
      NullPointerException - If regexp or emailHandling is null
  • Method Details

    • of

      public static IUsernameStrategy of(int minLength, int maxLength, String regexp, UsernameConfigurableStrategy.HandleEMail emailHandling)
      Username validation strategy factory.
      Parameters:
      minLength - Minimum allowed username length, must be >= 1
      maxLength - Maximum allowed username length, must be >= minLength and <= INTEGER.MAX_VALUE
      regexp - Regular expression for matching characters. Must start with ^ and end with $. Example: ^[@./_0-9a-zA-Z-]+$
      emailHandling - How email addresses as username should be handled: EMAIL_DENIED, EMAIL_REQUIRED or EMAIL_POSSIBLE
      Returns:
      UsernameStrategy object
      Throws:
      IllegalArgumentException - If arguments
      NullPointerException - If regexp or emailHandling is null
    • validationStrategy

      public boolean validationStrategy(String username)
      Validation strategy.
      Specified by:
      validationStrategy in interface IUsernameStrategy
      Parameters:
      username - Username
      Returns:
      true: if username is an email, false otherwise
      Throws:
      IllegalArgumentException - If the username does not match the configured parameters