Class GroupValidatorView

java.lang.Object
ch.tocco.nice2.validate.api.validators.GroupValidatorView
All Implemented Interfaces:
GroupValidator, Validator, Cloneable, Iterable<Validator>

public class GroupValidatorView extends Object implements GroupValidator
A restricted, non-modifiable view on a GroupValidator.

An example is a "server" view, where only validation rules are visible that run on the server.

  • Constructor Details

  • Method Details

    • 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
    • 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
    • mergeInValidatorByName

      public boolean mergeInValidatorByName(String name, Validator validator, Validator.MergeMode mode)
    • addValidators

      public void addValidators(Collection<Validator> validators)
    • validate

      public FieldValidationResult validate(Object value, Map<String,Object> fields) throws IllegalArgumentException
      Description copied from interface: Validator
      Validates a data component, for example a field or a group of fields.

      The fields map is required for looking at other values of this entity/form when conditions are in use.

      With this definition we don't know which value in the fields map is "us", cause we dont' know our name here. Don't think it's needed.

      Groups: if there are no (active) validators in this group then the OK status is returned.

      Specified by:
      validate in interface Validator
      Parameters:
      value - the value to validate, non-null
      fields - (all fields, key=name, value=value plus type)
      Throws:
      IllegalArgumentException - Wrong data type.
    • doNegate

      public boolean doNegate()
      Description copied from interface: Validator
      Tells if the result of the validation is being negated (internally). This means that the properties of specific validator implementations like a number range have negated meaning in the end.
      Specified by:
      doNegate in interface Validator
      Returns:
      .
    • setNegate

      public void setNegate(boolean negate)
      Specified by:
      setNegate in interface Validator
    • hasName

      public boolean hasName()
      Specified by:
      hasName in interface Validator
      Returns:
      Tells if this validator has a name, otherwise it is null.
    • getName

      @Nullable public @Nullable String getName()
      Specified by:
      getName in interface Validator
    • setName

      public void setName(String name)
      Specified by:
      setName in interface Validator
    • getLevel

      public ErrorLevel getLevel()
      Specified by:
      getLevel in interface Validator
    • setLevel

      public void setLevel(ErrorLevel level)
      Specified by:
      setLevel in interface Validator
    • getRunOn

      public RunOn getRunOn()
      Specified by:
      getRunOn in interface Validator
    • setRunOn

      public void setRunOn(RunOn runOn)
      Specified by:
      setRunOn in interface Validator
    • doContinueOnFailure

      public boolean doContinueOnFailure()
      Description copied from interface: Validator
      If the validation process should continue on this level with next validator when this one "fails". Failing means a negative result, how negative depends on ghe error level, an INFO counts as failed too (the test failed, it's just not that important).
      Specified by:
      doContinueOnFailure in interface Validator
      Returns:
      .
    • setContinue

      public void setContinue(boolean doContinue)
      Specified by:
      setContinue in interface Validator
    • getType

      public Class<? extends Validator> getType()
      Specified by:
      getType in interface Validator
      Returns:
      The class of the implementing class.
    • 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:
    • mergeConstraints

      public boolean mergeConstraints(Validator validator, Validator.MergeMode mode)
      Description copied from interface: Validator
      Merges the constraint data of this validator with the data of another instance.
      Specified by:
      mergeConstraints in interface Validator
      Parameters:
      validator - The validator to merge in.
      mode - How to merge.
      Returns:
      true if it was done. This should only fail if canMergeConstraints() says false.
      See Also:
    • clone

      public Validator clone() throws CloneNotSupportedException
      Specified by:
      clone in interface Validator
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • iterator

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