Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 3.1.x.
Browse files Browse the repository at this point in the history
This is a first round (incomplete) of upgrade to ISO 19111:2019.

#72
  • Loading branch information
desruisseaux committed Apr 4, 2024
2 parents f9a461b + c8e052d commit 41f2ea7
Show file tree
Hide file tree
Showing 146 changed files with 4,875 additions and 2,131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public interface ToleranceModifier {
* geographic coordinates. This modifier is identical to the {@link #GEOGRAPHIC} tolerance
* modifier, except that φ and λ axes are interchanged. This is the most common
* modifier used when testing {@link GeographicCRS} instances created from the
* <a href="http://www.epsg.org">EPSG</a> database.
* <a href="https://epsg.org">EPSG geodetic registry</a>.
*
* @see ToleranceModifiers#geographic(int, int)
*/
Expand All @@ -88,7 +88,7 @@ public interface ToleranceModifier {
* the result of an <i>reverse projection</i>. This modifier is identical to the
* {@link #PROJECTION} tolerance modifier, except that φ and λ axes are
* interchanged. This is the most common modifier used when testing {@link ProjectedCRS}
* instances created from the <a href="http://www.epsg.org">EPSG</a> database.
* instances created from the <a href="https://epsg.org">EPSG geodetic registry</a>.
*
* @see ToleranceModifiers#projection(int, int)
*/
Expand Down
51 changes: 46 additions & 5 deletions geoapi-conformance/src/main/java/org/opengis/test/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.BitSet;
import java.util.Objects;
import java.util.Collection;
import java.util.function.BiConsumer;
import java.util.logging.Logger;
import org.opengis.annotation.Obligation;

Expand Down Expand Up @@ -212,11 +213,11 @@ protected void conditional(final String message, final Object value, final boole
}

/**
* Ensures that the elements in the given collection are compliant with the {@link Object}
* {@code equals(Object)} and {@code hashCode()} contract. This method ensures that the
* {@code equals(Object)} methods implement <i>reflexive</i>, <i>symmetric</i>
* and <i>transitive</i> relations. It also ensures that if {@code A.equals(B)},
* then {@code A.hashCode() == B.hashCode()}.
* Ensures that the elements in the given collection are compliant
* with the {@code equals(Object)} and {@code hashCode()} contract.
* This method ensures that the {@code equals(Object)} methods implement
* <i>reflexive</i>, <i>symmetric</i> and <i>transitive</i> relations.
* It also ensures that if {@code A.equals(B)}, then {@code A.hashCode() == B.hashCode()}.
*
* <p>If the given collection is null, then this method does nothing.
* If the given collection contains null elements, then those elements are ignored.</p>
Expand All @@ -228,6 +229,7 @@ protected void conditional(final String message, final Object value, final boole
*
* @since 3.1
*/
@SuppressWarnings("ObjectEqualsNull")
protected void validate(final Collection<?> collection) {
if (collection == null) {
return;
Expand Down Expand Up @@ -279,4 +281,43 @@ protected void validate(final Collection<?> collection) {
assertEquals(hashCodes[i], elements[i].hashCode(), "The hash code value has changed.");
}
}

/**
* Validates the given collection, then validates each element in that collection.
* This method invokes {@link #validate(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:
*
* {@snippet lang="java" :
* validate("identifiers", object.getIdentifiers(), ValidatorContainer::validate, false);
* }
*
* @param <E> type of elements to validate.
* @param property name of the property to validate.
* @param values values of the property to validate.
* @param validator the function to invoke for validating each element.
* @param mandatory whether at least one element shall be present.
*
* @since 3.1
*/
protected <E> void validate(final String property,
final Collection<? extends E> values,
final BiConsumer<ValidatorContainer,E> validator,
final boolean mandatory)
{
assertNotNull(values, () -> property + " shall not be null. "
+ (mandatory ? "Expected a collection with at least one element."
: "If absent, it should be an empty collection instead."));
validate(values);
boolean isPresent = false;
for (final E element : values) {
assertNotNull(element, () -> property + " shall not contain null elements.");
validator.accept(container, element);
isPresent = true;
}
if (mandatory && requireMandatoryAttributes) {
assertTrue(isPresent, () -> " is mandatory. The collection shall not be empty.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.opengis.metadata.*;
import org.opengis.metadata.extent.*;
import org.opengis.metadata.citation.*;
import org.opengis.metadata.quality.*;
import org.opengis.metadata.maintenance.*;
import org.opengis.metadata.maintenance.Scope; // Resolve ambiguity.
import org.opengis.geometry.*;
import org.opengis.parameter.*;
import org.opengis.referencing.*;
Expand Down Expand Up @@ -96,6 +99,26 @@ public class ValidatorContainer implements Cloneable {
@SuppressWarnings("this-escape")
public CitationValidator citation = new CitationValidator(this);

/**
* The validator for {@link DataQuality} and related objects.
* Vendors can change this field to a different validator, or change the setting
* of the referenced validator. This field shall not be set to {@code null} however.
*
* @since 3.1
*/
@SuppressWarnings("this-escape")
public QualityValidator quality = new QualityValidator(this);

/**
* The validator for {@link MaintenanceInformation} and related objects.
* Vendors can change this field to a different validator, or change the setting
* of the referenced validator. This field shall not be set to {@code null} however.
*
* @since 3.1
*/
@SuppressWarnings("this-escape")
public MaintenanceValidator maintenance = new MaintenanceValidator(this);

/**
* The validator for {@link Extent} and related objects.
* Vendors can change this field to a different validator, or change the setting
Expand Down Expand Up @@ -180,7 +203,7 @@ public ValidatorContainer() {
all = new AbstractList<Validator>() {
/** Returns the number of elements in this list. */
@Override public int size() {
return 11;
return 13;
}

/** Returns the validator at the given index. */
Expand All @@ -189,14 +212,16 @@ public ValidatorContainer() {
case 0: return naming;
case 1: return metadata;
case 2: return citation;
case 3: return extent;
case 4: return datum;
case 5: return cs;
case 6: return crs;
case 7: return parameter;
case 8: return coordinateOperation;
case 9: return geometry;
case 10: return image;
case 3: return quality;
case 4: return maintenance;
case 5: return extent;
case 6: return datum;
case 7: return cs;
case 8: return crs;
case 9: return parameter;
case 10: return coordinateOperation;
case 11: return geometry;
case 12: return image;
default: throw new IndexOutOfBoundsException(index);
}
}
Expand Down Expand Up @@ -245,15 +270,18 @@ public final void dispatch(final Object object) {
if (object instanceof Telephone) validate((Telephone) object);
if (object instanceof Address) validate((Address) object);
if (object instanceof OnlineResource) validate((OnlineResource) object);
if (object instanceof DataQuality) validate((DataQuality) object);
if (object instanceof Element) validate((Element) object); // Dispatch according sub-type.
if (object instanceof Result) validate((Result) object); // Dispatch according sub-type.
if (object instanceof Extent) validate((Extent) object);
if (object instanceof GeographicExtent) validate((GeographicExtent) object);
if (object instanceof GeographicExtent) validate((GeographicExtent) object); // Dispatch according sub-type.
if (object instanceof VerticalExtent) validate((VerticalExtent) object);
if (object instanceof TemporalExtent) validate((TemporalExtent) object);
if (object instanceof IdentifiedObject) validate((IdentifiedObject) object);
if (object instanceof IdentifiedObject) validate((IdentifiedObject) object); // Dispatch according sub-type.
if (object instanceof Identifier) validate((Identifier) object);
if (object instanceof GenericName) validate((GenericName) object);
if (object instanceof GenericName) validate((GenericName) object); // Dispatch according sub-type.
if (object instanceof NameSpace) validate((NameSpace) object);
if (object instanceof GeneralParameterValue) validate((GeneralParameterValue) object);
if (object instanceof GeneralParameterValue) validate((GeneralParameterValue) object); // Dispatch according sub-type.
if (object instanceof Envelope) validate((Envelope) object);
if (object instanceof DirectPosition) validate((DirectPosition) object);
if (object instanceof InternationalString) validate((InternationalString) object);
Expand Down Expand Up @@ -374,6 +402,136 @@ public final void validate(final OnlineResource object) {
citation.validate(object);
}

/**
* Tests the conformance of the given object.
*
* @param object the object to test, or {@code null}.
*
* @see QualityValidator#validate(DataQuality)
*
* @since 3.1
*/
public final void validate(final DataQuality object) {
quality.validate(object);
}

/**
* Tests the conformance of the given object.
*
* @param object the object to test, or {@code null}.
*
* @see QualityValidator#dispatch(Element)
*
* @since 3.1
*/
public final void validate(final Element object) {
quality.dispatch(object);
}

/**
* Tests the conformance of the given object.
*
* @param object the object to test, or {@code null}.
*
* @see MaintenanceValidator#validate(MaintenanceInformation)
*
* @since 3.1
*/
public final void validate(final PositionalAccuracy object) {
quality.validate(object);
}

/**
* Tests the conformance of the given object.
*
* @param object the object to test, or {@code null}.
*
* @see QualityValidator#dispatch(Result)
*
* @since 3.1
*/
public final void validate(final Result object) {
quality.dispatch(object);
}

/**
* Tests the conformance of the given object.
*
* @param object the object to test, or {@code null}.
*
* @see QualityValidator#validate(DescriptiveResult)
*
* @since 3.1
*/
public final void validate(final DescriptiveResult object) {
quality.validate(object);
}

/**
* Tests the conformance of the given object.
*
* @param object the object to test, or {@code null}.
*
* @see QualityValidator#validate(ConformanceResult)
*
* @since 3.1
*/
public final void validate(final ConformanceResult object) {
quality.validate(object);
}

/**
* Tests the conformance of the given object.
*
* @param object the object to test, or {@code null}.
*
* @see QualityValidator#validate(QuantitativeResult)
*
* @since 3.1
*/
public final void validate(final QuantitativeResult object) {
quality.validate(object);
}

/**
* Tests the conformance of the given object.
*
* @param object the object to test, or {@code null}.
*
* @see QualityValidator#validate(CoverageResult)
*
* @since 3.1
*/
public final void validate(final CoverageResult object) {
quality.validate(object);
}

/**
* Tests the conformance of the given object.
*
* @param object the object to test, or {@code null}.
*
* @see MaintenanceValidator#validate(MaintenanceInformation)
*
* @since 3.1
*/
public final void validate(final MaintenanceInformation object) {
maintenance.validate(object);
}

/**
* Tests the conformance of the given object.
*
* @param object the object to test, or {@code null}.
*
* @see MaintenanceValidator#validate(Scope)
*
* @since 3.1
*/
public final void validate(final Scope object) {
maintenance.validate(object);
}

/**
* Tests the conformance of the given object.
*
Expand Down Expand Up @@ -534,7 +692,10 @@ public final void validate(final DerivedCRS object) {
* @param object the object to validate, or {@code null}.
*
* @see CRSValidator#validate(ImageCRS)
*
* @deprecated {@code ImageCRS} is replaced by {@link EngineeringCRS} as of ISO 19111:2019.
*/
@Deprecated(since="3.1")
public final void validate(final ImageCRS object) {
crs.validate(object);
}
Expand Down Expand Up @@ -689,6 +850,7 @@ public final void validate(final TimeCS object) {
*
* @see CSValidator#validate(UserDefinedCS)
*/
@Deprecated(since="3.1")
public final void validate(final UserDefinedCS object) {
cs.validate(object);
}
Expand Down Expand Up @@ -776,7 +938,11 @@ public final void validate(final TemporalDatum object) {
* @param object the object to test, or {@code null}.
*
* @see DatumValidator#validate(ImageDatum)
*
* @deprecated {@code ImageCRS} is replaced by {@link EngineeringCRS} as of ISO 19111:2019.
*/
@Deprecated(since="3.1")
@SuppressWarnings("removal")
public final void validate(final ImageDatum object) {
datum.validate(object);
}
Expand All @@ -792,6 +958,19 @@ public final void validate(final EngineeringDatum object) {
datum.validate(object);
}

/**
* Tests the conformance of the given object.
*
* @param object the object to test, or {@code null}.
*
* @see DatumValidator#validate(DatumEnsemble)
*
* @since 3.1
*/
public final void validate(final DatumEnsemble<?> object) {
datum.validate(object);
}

/**
* Tests the conformance of the given object.
*
Expand Down Expand Up @@ -1067,7 +1246,7 @@ public final void validate(final ImageWriterSpi object) {
*
* @see ImageValidator#validate(IIOMetadataFormat)
*/
public void validate(final IIOMetadataFormat object) {
public final void validate(final IIOMetadataFormat object) {
image.validate(object);
}
}
Loading

0 comments on commit 41f2ea7

Please sign in to comment.