Class GroupValidatorView
- All Implemented Interfaces:
GroupValidator
,Validator
,Cloneable
,Iterable<Validator>
GroupValidator
.
An example is a "server" view, where only validation rules are visible that run on the server.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.validate.api.validators.Validator
Validator.MergeMode
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addValidator
(Validator validator) Adds a validator to the group.void
addValidator
(Validator validator, boolean respectLevelOrder) Adds a validator to the group in the right position.void
addValidators
(Collection<Validator> validators) boolean
Tells if the constraint data of this validator can be merged with another instance.clone()
boolean
If the validation process should continue on this level with next validator when this one "fails".boolean
doNegate()
Tells if the result of the validation is being negated (internally).@Nullable Validator
Finds a child validator, either a direct child or somewhere down the hierarchy, with the given name path.getLevel()
@Nullable String
getName()
getRunOn()
getType()
Returns a list with the validators in this group.boolean
hasName()
boolean
iterator()
boolean
mergeConstraints
(Validator validator, Validator.MergeMode mode) Merges the constraint data of this validator with the data of another instance.boolean
mergeInValidatorByName
(String name, Validator validator, Validator.MergeMode mode) boolean
mergeInValidatorByType
(Validator validator, Validator.MergeMode mode) 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.void
removeValidator
(Validator validator) Remove a validator to the group.void
setContinue
(boolean doContinue) void
setLevel
(ErrorLevel level) void
void
setNegate
(boolean negate) void
Validates a data component, for example a field or a group of fields.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
GroupValidatorView
-
-
Method Details
-
hasValidators
public boolean hasValidators()- Specified by:
hasValidators
in interfaceGroupValidator
- Returns:
- Tells if this group has any validators.
-
getValidators
Description copied from interface:GroupValidator
Returns a list with the validators in this group.- Specified by:
getValidators
in interfaceGroupValidator
- Returns:
- list may be empty
-
findChild
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 interfaceGroupValidator
-
addValidator
Description copied from interface:GroupValidator
Adds a validator to the group.- Specified by:
addValidator
in interfaceGroupValidator
- Parameters:
validator
- validator, non-null
-
removeValidator
Description copied from interface:GroupValidator
Remove a validator to the group.- Specified by:
removeValidator
in interfaceGroupValidator
- Parameters:
validator
- validator, non-null
-
addValidator
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 interfaceGroupValidator
-
mergeInValidatorByType
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 interfaceGroupValidator
- Parameters:
validator
- The validator to merge in.mode
- .- Returns:
- true if it was merged, false if it was added
-
mergeInValidatorByName
-
addValidators
-
validate
public FieldValidationResult validate(Object value, Map<String, Object> fields) throws IllegalArgumentExceptionDescription 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 interfaceValidator
- Parameters:
value
- the value to validate, non-nullfields
- (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. -
setNegate
public void setNegate(boolean negate) -
hasName
public boolean hasName() -
getName
-
setName
-
getLevel
-
setLevel
-
getRunOn
-
setRunOn
-
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 interfaceValidator
- Returns:
- .
-
setContinue
public void setContinue(boolean doContinue) - Specified by:
setContinue
in interfaceValidator
-
getType
-
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 interfaceValidator
- See Also:
-
mergeConstraints
Description copied from interface:Validator
Merges the constraint data of this validator with the data of another instance.- Specified by:
mergeConstraints
in interfaceValidator
- 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
- Specified by:
clone
in interfaceValidator
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
iterator
-