Class MandatoryValidatorImpl
java.lang.Object
ch.tocco.nice2.validate.api.validators.AbstractValidator
ch.tocco.nice2.validate.api.validators.MandatoryValidatorImpl
- All Implemented Interfaces:
MandatoryValidator
,Validator
,ValueValidator
,Cloneable
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.validate.api.validators.Validator
Validator.MergeMode
-
Field Summary
Fields inherited from class ch.tocco.nice2.validate.api.validators.AbstractValidator
doContinue, level, name, negate, runOn
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected FieldValidationResult
boolean
Tells if the constraint data of this validator can be merged with another instance.clone()
Class
<? extends ValueValidator> getType()
protected boolean
If subclass overwrites and returns true then the validate() method won't do it anymore.void
init()
protected boolean
isEmptySoIgnore
(Object value) Subclasses may override this to define what is considered empty, and thus disables the validator.boolean
mergeConstraints
(Validator validator, Validator.MergeMode mode) Default implementation so that subclasses are only forced to override canMergeConstraints().Methods inherited from class ch.tocco.nice2.validate.api.validators.AbstractValidator
doContinueOnFailure, doNegate, getErrorStatusByLevel, getLevel, getName, getRunOn, hasName, negateResultIfNeeded, setContinue, setLevel, setName, setNegate, setRunOn, validate
-
Constructor Details
-
MandatoryValidatorImpl
public MandatoryValidatorImpl()
-
-
Method Details
-
init
public void init()- Specified by:
init
in interfaceMandatoryValidator
-
_validate
protected FieldValidationResult _validate(Object value, Map<String, Object> fields) throws IllegalArgumentException- Specified by:
_validate
in classAbstractValidator
- Throws:
IllegalArgumentException
-
iNegateMyself
protected boolean iNegateMyself()Description copied from class:AbstractValidator
If subclass overwrites and returns true then the validate() method won't do it anymore. That's preferred for implementing validators (not groups).- Overrides:
iNegateMyself
in classAbstractValidator
- See Also:
-
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 class:AbstractValidator
Default implementation so that subclasses are only forced to override canMergeConstraints().- Specified by:
mergeConstraints
in interfaceValidator
- Overrides:
mergeConstraints
in classAbstractValidator
- 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:
-
getType
-
isEmptySoIgnore
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 classAbstractValidator
- Parameters:
value
- The object value as given to validate.- Returns:
- True to disable the validator, false to go on.
-
clone
- Specified by:
clone
in interfaceValidator
- Overrides:
clone
in classAbstractValidator
- Throws:
CloneNotSupportedException
-