Class ValidatorSettings

java.lang.Object
com.codingchili.core.configuration.system.ValidatorSettings

public class ValidatorSettings extends Object
Contains settings for validating strings with regexes, length and field names.
  • Constructor Details

    • ValidatorSettings

      public ValidatorSettings(String name)
      Creates a new settings object with no field validation enabled by default.
      Parameters:
      name - the name of the ruleset.
  • Method Details

    • getName

      public String getName()
      Returns:
      the name of the ruleset.
    • getRegex

      public List<RegexComponent> getRegex()
      Returns:
      a list of regexes to apply for the matching fields.
    • setRegex

      public ValidatorSettings setRegex(List<RegexComponent> regex)
      Parameters:
      regex - a list of regular expressions to apply on matching fields.
      Returns:
      fluent.
    • getKeys

      public Set<String> getKeys()
      Returns:
      a list of field names for which validation is to be enabled. if empty - all fields are validated.
    • setKeys

      public void setKeys(Set<String> keys)
      Parameters:
      keys - a list of fields that will be validated, if empty then all fields are validated.
    • getMinLength

      public int getMinLength()
      Returns:
      the minimum length of the input.
    • setMinLength

      public void setMinLength(int minLength)
      Parameters:
      minLength - the minimum length of the input.
    • getMaxLength

      public int getMaxLength()
      Returns:
      the maximum length of the input.
    • setMaxLength

      public void setMaxLength(int maxLength)
      Parameters:
      maxLength - the maximum length of the input.
    • addKey

      public ValidatorSettings addKey(String key)
      Parameters:
      key - specifies that this key needs validation, when called validation for all fields not listed are disabled. The keys does not consider the object hierarchy, this is a plain field name.
      Returns:
      fluent.
    • addKeys

      public ValidatorSettings addKeys(String... keys)
      Parameters:
      keys - a list of keys to add, see addKey(String).
      Returns:
      fluent.
    • length

      public ValidatorSettings length(int min, int max)
      Parameters:
      min - the minimum length of the field being validated.
      max - the maximum length of the field being validated.
      Returns:
      fluent.
    • addRegex

      public ValidatorSettings addRegex(RegexAction action, String expression)
      Parameters:
      action - addRegex(RegexAction, String, String)
      expression - the regular expression configuration used to match input.
      Returns:
      fluent.
    • addRegex

      public ValidatorSettings addRegex(RegexAction action, String expression, String substitution)
      Parameters:
      action - the action to take when the expression matches the input.
      expression - the regular expression configuration used to match input.
      substitution - used when RegexAction.SUBSTITUTE is set.
      Returns:
      fluent.
    • isFieldValidated

      public boolean isFieldValidated(String field)
      Parameters:
      field - the field to check if validation should be performed.
      Returns:
      true if the field needs validation, if it's added to the checked keys or if the fieldset is empty.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object