Class AbstractGroupValidator

java.lang.Object
ch.tocco.nice2.validate.api.validators.AbstractValidator
ch.tocco.nice2.validate.api.validators.AbstractGroupValidator
All Implemented Interfaces:
GroupValidator, Validator, Cloneable, Iterable<Validator>
Direct Known Subclasses:
AndGroupValidatorImpl

public abstract class AbstractGroupValidator extends AbstractValidator implements GroupValidator
A group that can contain validators and groups recursively.
  • Field Details

    • validators

      protected List<Validator> validators
      Validators and Groups.

      Mostly in the order that ERROR level validators come before WARN come before INFO. It seems easier atm to work with just one simple list.

  • Constructor Details

    • AbstractGroupValidator

      public AbstractGroupValidator()
  • Method Details

    • addValidator

      public void addValidator(Validator validator)
      Description copied from interface: GroupValidator
      Adds a validator to the group.
      Specified by:
      addValidator in interface GroupValidator
      Parameters:
      validator - validator, non-null
    • removeValidator

      public void removeValidator(Validator validator)
      Description copied from interface: GroupValidator
      Remove a validator to the group.
      Specified by:
      removeValidator in interface GroupValidator
      Parameters:
      validator - validator, non-null
    • addValidator

      public void addValidator(Validator validator, boolean respectLevelOrder)
      Description copied from interface: GroupValidator
      Adds a validator to the group in the right position.

      Validators of error level ERROR need to come before WARN need to come before INFO. The xml model reader makes sure the validators are given in the right order. But once manual customization, as well as merging comes in, this is required.

      Specified by:
      addValidator in interface GroupValidator
    • mergeInValidatorByType

      public boolean mergeInValidatorByType(Validator validator, Validator.MergeMode mode)
      Description copied from interface: GroupValidator
      Tells an existing validator of that type (with same level and no conditions) to merge in the attributes of the given one, or adds the passed validator if no such is here yet.
      Specified by:
      mergeInValidatorByType in interface GroupValidator
      Parameters:
      validator - The validator to merge in.
      mode - .
      Returns:
      true if it was merged, false if it was added
    • hasValidators

      public boolean hasValidators()
      Specified by:
      hasValidators in interface GroupValidator
      Returns:
      Tells if this group has any validators.
    • getValidators

      public List<Validator> getValidators()
      Description copied from interface: GroupValidator
      Returns a list with the validators in this group.
      Specified by:
      getValidators in interface GroupValidator
      Returns:
      list may be empty
    • findChild

      @Nullable public @Nullable Validator findChild(String name)
      Description copied from interface: GroupValidator
      Finds a child validator, either a direct child or somewhere down the hierarchy, with the given name path.

      If you are looking for a direct child then specify the name, eg "myLengthValidator".
      If you're looking for one down in a group then use the path, eg "myAndGroup.myLengthConditionalGroup.myLengthValidator".

      Specified by:
      findChild in interface GroupValidator
    • canMergeConstraints

      public boolean canMergeConstraints()
      Description copied from interface: Validator
      Tells if the constraint data of this validator can be merged with another instance.

      This is validator-type specific. For example a date range validator can, a regex validator obviously cannot.

      Specified by:
      canMergeConstraints in interface Validator
      See Also:
    • getType

      public Class<? extends Validator> getType()
      Specified by:
      getType in interface Validator
      Returns:
      The class of the implementing class.
    • iterator

      public Iterator<Validator> iterator()
      Specified by:
      iterator in interface Iterable<Validator>
    • clone

      Specified by:
      clone in interface Validator
      Overrides:
      clone in class AbstractValidator
      Throws:
      CloneNotSupportedException
    • isEmptySoIgnore

      protected boolean isEmptySoIgnore(Object value)
      Description copied from class: AbstractValidator
      Subclasses may override this to define what is considered empty, and thus disables the validator.

      An example is the string field: an empty input string means "no value given".

      Imagine a zipcode field that may be empty (if unknown). A length validator (let's say 4 to 10 characters) must be ignored if no input (empty string) was given.

      Overrides:
      isEmptySoIgnore in class AbstractValidator
      Parameters:
      value - The object value as given to validate.
      Returns:
      True to disable the validator, false to go on.