Module de.powerstat.validation
Class UsernameConfigurableStrategy
java.lang.Object
de.powerstat.validation.values.strategies.UsernameConfigurableStrategy
- All Implemented Interfaces:
IUsernameStrategy
- Direct Known Subclasses:
UsernameDefaultStrategy
Configurable username validation strategy.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum for handling of email addresses. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Map<NTuple4<Integer,Integer, String, UsernameConfigurableStrategy.HandleEMail>, UsernameConfigurableStrategy> Cache for singletons.private final UsernameConfigurableStrategy.HandleEMailEMail handling.private final intMaximum allowed username length.private final intMinimum allowed username length.private final StringRegular expression for matching allowed characters. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedUsernameConfigurableStrategy(int minLength, int maxLength, String regexp, UsernameConfigurableStrategy.HandleEMail emailHandling) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic IUsernameStrategyof(int minLength, int maxLength, String regexp, UsernameConfigurableStrategy.HandleEMail emailHandling) Username validation strategy factory.booleanvalidationStrategy(String username) Validation strategy.
-
Field Details
-
CACHE
private static final Map<NTuple4<Integer,Integer, CACHEString, UsernameConfigurableStrategy.HandleEMail>, UsernameConfigurableStrategy> Cache for singletons. -
minLength
private final int minLengthMinimum allowed username length. -
maxLength
private final int maxLengthMaximum allowed username length. -
regexp
Regular expression for matching allowed characters. -
emailHandling
EMail handling. Could be EMAIL_DENIED, EMAIL_REQUIRED or EMAIL_POSSIBLE
-
-
Constructor Details
-
UsernameConfigurableStrategy
protected UsernameConfigurableStrategy(int minLength, int maxLength, String regexp, UsernameConfigurableStrategy.HandleEMail emailHandling) Constructor.- Parameters:
minLength- Minimum allowed username length, must be >= 1maxLength- Maximum allowed username length, must be >= minLength and <= INTEGER.MAX_VALUEregexp- 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 requiredNullPointerException- 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 >= 1maxLength- Maximum allowed username length, must be >= minLength and <= INTEGER.MAX_VALUEregexp- 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 argumentsNullPointerException- If regexp or emailHandling is null
-
validationStrategy
Validation strategy.- Specified by:
validationStrategyin interfaceIUsernameStrategy- Parameters:
username- Username- Returns:
- true: if username is an email, false otherwise
- Throws:
IllegalArgumentException- If the username does not match the configured parameters
-