- Direct Known Subclasses:
CodeListValidator
,GeometryValidator
,ImageValidator
,MetadataValidator
,NameValidator
,ReferencingValidator
ValidatorContainer.all
provides a convenient way to make such
change in a loop.
Configurations available in this class and some subclasses are:
requireMandatoryAttributes
- controls whether unexpected null values can be tolerated.enforceForbiddenAttributes
- controls whether unexpected non-null values can be tolerated.CRSValidator.enforceStandardNames
- controls whether axis names shall be restricted to ISO standards.
Once the configuration is finished, all validators provided in GeoAPI are thread-safe provided that their configuration is not modified.
- Since:
- 2.2
-
Field Summary
Modifier and TypeFieldDescriptionprotected final ValidatorContainer
The validators to use for every validations not defined in the concrete subclass.static final double
The default tolerance value for comparisons of floating point numbers in validators.boolean
true
if forbidden attributes are required to be null, orfalse
for tolerating non-null values.protected final Logger
The logger for reporting non-fatal warnings.boolean
true
if mandatory attributes are required to be non-null, orfalse
for tolerating null values. -
Constructor Summary
ModifierConstructorDescriptionprotected
Validator
(ValidatorContainer container, String packageName) Creates a new validator instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Invoked when the existence of a forbidden attribute needs to be checked.protected final void
Invoked when the existence of a forbidden attribute needs to be verified.protected void
Invoked when the existence of a mandatory attribute needs to be verified.protected final void
Invoked when the existence of an optional attribute needs to be verified.protected <E> void
validate
(String property, Collection<? extends E> values, BiConsumer<ValidatorContainer, E> validator, boolean mandatory) Validates the given collection, then validates each element in that collection.protected void
validate
(Collection<?> collection) Ensures that the elements in the given collection are compliant with theequals(Object)
andhashCode()
contract.
-
Field Details
-
DEFAULT_TOLERANCE
The default tolerance value for comparisons of floating point numbers in validators. The current value is 1.0E-6. This value is relatively large because some implementations may store their values asfloat
numbers instead ofdouble
.Note that
TestCase
subclasses use smaller tolerance thresholds, typically centimetric. Test cases are stricter then validators because the tests control the objects they create, while validators need to work reasonably well for arbitrary objects.- See Also:
-
container
The validators to use for every validations not defined in the concrete subclass. For example ifCRSValidator
needs to validate a datum, it will use theDatumValidator
instance defined in this container.The container may contain this validator instance. For example if this validator is an instance of
CRSValidator
, then theValidatorContainer.crs
field may be set tothis
. Doing so ensure that the propervalidate(…)
methods will be invoked in case of callback.Tip: if the other validators are not expected to callback the
validate
methods defined in thisValidator
instance (for example a datum has no reason to validate a CRS), then it is safe to set this field toValidators.DEFAULT
. -
logger
-
requireMandatoryAttributes
true
if mandatory attributes are required to be non-null, orfalse
for tolerating null values. ISO specifications flags some attributes as mandatory, while some other are optional. Optional attributes are allowed to be null at any time, but mandatory attributes shall never be null - in theory. However, implementers may choose to returnnull
on a temporary basis while they are developing their library. If this field is set tofalse
, then missing mandatory attributes will be logged as warnings instead of causing a failure.The default value is
true
.- See Also:
-
enforceForbiddenAttributes
true
if forbidden attributes are required to be null, orfalse
for tolerating non-null values. In ISO specifications, some attributes are declared as optional in parent class and specialized in subclasses, either as mandatory or as forbidden. If this field is set tofalse
, then forbidden attributes will be logged as warnings instead of causing a failure.The default value is
true
.- See Also:
-
-
Constructor Details
-
Validator
Creates a new validator instance.- Parameters:
container
- the set of validators to use for validating other kinds of objects (see field javadoc).packageName
- the name of the package containing the classes to be validated.
-
-
Method Details
-
mandatory
Invoked when the existence of a mandatory attribute needs to be verified. If the given value isnull
or is an empty collection, then there is a choice:- If
requireMandatoryAttributes
istrue
(which is the default), then the test fails with the given message. - Otherwise, the message is logged as a warning and the test continues.
- Parameters:
value
- the value to test for non-nullity.message
- the message to send in case of failure.- See Also:
- If
-
mandatory
Invoked when the existence of an optional attribute needs to be verified. This method is invoked when an attribute is optional in a parent interface, but become mandatory in a sub-interface.- Parameters:
value
- the value to test for non-nullity.message
- the message to send in case of failure.
-
forbidden
Invoked when the existence of a forbidden attribute needs to be checked. If the given value is non-null and is not an empty collection, then there is a choice:- If
enforceForbiddenAttributes
istrue
(which is the default), then the test fails with the given message. - Otherwise, the message is logged as a warning and the test continues.
- Parameters:
value
- the value to test for nullity.message
- the message to send in case of failure.- See Also:
- If
-
forbidden
Invoked when the existence of a forbidden attribute needs to be verified. This method is invoked when an attribute is optional in a parent interface, but become forbidden in a sub-interface.- Parameters:
value
- the value to test for nullity.message
- the message to send in case of failure.
-
validate
Ensures that the elements in the given collection are compliant with theequals(Object)
andhashCode()
contract. This method ensures that theequals(Object)
methods implement reflexive, symmetric and transitive relations. It also ensures that ifA.equals(B)
, thenA.hashCode() == B.hashCode()
.If the given collection is null, then this method does nothing. If the given collection contains null elements, then those elements are ignored.
This method does not invoke any other
validate
method on collection elements. It is caller responsibility to validates elements according their types.- Parameters:
collection
- the collection of elements to validate, ornull
.- Since:
- 3.1
-
validate
protected <E> void validate(String property, Collection<? extends E> values, BiConsumer<ValidatorContainer, E> validator, boolean mandatory) Validates the given collection, then validates each element in that collection. This method invokesvalidate(Collection)
and adds the restriction that the collection and all its element shall be non-null. Then the given validate function is invoked for each element. Example:validate("identifiers", object.getIdentifiers(), ValidatorContainer::validate, false);
- Type Parameters:
E
- type of elements to validate.- Parameters:
property
- name of the property to validate.values
- values of the property to validate.validator
- the function to invoke for validating each element.mandatory
- whether at least one element shall be present.- Since:
- 3.1
-