Class RegexConstraint

  • All Implemented Interfaces:
    Constraint

    public class RegexConstraint
    extends AbstractConstraint
    Constraint implementation that performs regular expression comparisons. Where possible, the type converter will be used to first convert the value to a String, so the evaluation will be against the value's String equivalent.

    The failure condition can be changed to occur either on a match or on a non-match by using the requiresMatch property. The default is true, i.e. failures will occur if the object value does not match the given expression.

    Author:
    Derek Hulley
    See Also:
    String.matches(java.lang.String), Pattern
    • Constructor Detail

      • RegexConstraint

        public RegexConstraint()
    • Method Detail

      • getType

        public String getType()
        Returns the 'type' of the constraint, this is the identifier given to constraint in the configuration.
        Specified by:
        getType in interface Constraint
        Overrides:
        getType in class AbstractConstraint
        Returns:
        The type
      • setExpression

        public void setExpression​(String expression)
        Set the regular expression used to evaluate String values
        Parameters:
        expression - regular expression similar to the String.matches(java.lang.String) argument
      • getRequiresMatch

        public boolean getRequiresMatch()
        Returns:
        Returns true if the value must match the regular expression or false if the value must not match the regular expression
      • setRequiresMatch

        public void setRequiresMatch​(boolean requiresMatch)
        Set whether the regular expression must be matched or not
        Parameters:
        requiresMatch - Set to true if the value must match the regular expression or false if the value must not match the regular expression
      • initialize

        public void initialize()
        Description copied from class: AbstractConstraint
        Initializes the constraint with appropriate values, which will depend on the implementation itself. This method can be implemented as a once-off, i.e. reinitialization does not have to be supported.

        Registers the constraint with the registry, if present. Call this method if you want the constraint to be auto-registered.

        Specified by:
        initialize in interface Constraint
        Overrides:
        initialize in class AbstractConstraint