This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 1b0c4e2c6e43efde7afdaae320e4d88ace015b2d Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sun Apr 3 17:05:42 2022 +0200 Make a better effort for saying in which object a property was missing. Minor formatting in comments. --- .../apache/sis/internal/metadata/Identifiers.java | 20 ++++++++++++++++++-- .../sis/internal/metadata/MetadataUtilities.java | 4 ++-- .../apache/sis/internal/metadata/package-info.java | 2 +- .../iso/extent/DefaultGeographicBoundingBox.java | 12 ++++++------ .../referencing/CC_GeneralOperationParameter.java | 18 +++++++++--------- .../jaxb/referencing/CC_OperationMethod.java | 8 ++++---- .../sis/referencing/AbstractIdentifiedObject.java | 2 +- .../apache/sis/referencing/ImmutableIdentifier.java | 2 +- .../sis/referencing/crs/AbstractDerivedCRS.java | 15 ++++++++------- .../operation/AbstractSingleOperation.java | 6 +++--- 10 files changed, 53 insertions(+), 36 deletions(-) diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Identifiers.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Identifiers.java index 925c378..c764dee 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Identifiers.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Identifiers.java @@ -27,13 +27,14 @@ import org.apache.sis.util.CharSequences; import org.apache.sis.util.Characters; import org.apache.sis.util.Deprecable; import org.apache.sis.util.Static; +import org.apache.sis.util.resources.Errors; /** * Methods working on {@link Identifier} instances. * * @author Martin Desruisseaux (Geomatys) - * @since 1.1 + * @since 1.2 * @version 1.0 * @module */ @@ -110,7 +111,7 @@ public final class Identifiers extends Static { */ public static String getIdentifier(final Citation citation, final boolean strict) { if (citation != null) { - boolean isUnicode = false; // Whether 'identifier' is a Unicode identifier. + boolean isUnicode = false; // Whether `identifier` is a Unicode identifier. String identifier = null; // The best identifier found so far. String codeSpace = null; // Code space of the identifier, or null if none. for (final Identifier id : CollectionsExt.nonNull(citation.getIdentifiers())) { @@ -263,4 +264,19 @@ public final class Identifiers extends Static { } return null; } + + /** + * Returns a message saying that a property is missing for an object having the given identifier. + * + * @param owner identifier of the object for which a property is missing. + * @param property name of the missing property. + * @return a message saying that a value is missing for the given property in the specified identified object. + * + * @since 1.2 + */ + public static String missingValueForProperty(final Identifier owner, final String property) { + return (owner == null) + ? Errors.format(Errors.Keys.MissingValueForProperty_1, property) + : Errors.format(Errors.Keys.MissingValueForProperty_2, owner, property); + } } diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java index f8fab9c..087cf45 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java @@ -100,7 +100,7 @@ public final class MetadataUtilities extends Static { { if (newValue != null) { final double value = newValue.doubleValue(); - if (!(strict ? value > 0 : value >= 0)) { // Use '!' for catching NaN. + if (!(strict ? value > 0 : value >= 0)) { // Use `!` for catching NaN. if (NilReason.forObject(newValue) == null) { final String msg = logOrFormat(classe, property, strict ? Errors.Keys.ValueNotGreaterThanZero_2 @@ -134,7 +134,7 @@ public final class MetadataUtilities extends Static { { if (newValue != null) { final double value = newValue.doubleValue(); - if (!(value >= minimum.doubleValue() && value <= maximum.doubleValue())) { // Use '!' for catching NaN. + if (!(value >= minimum.doubleValue() && value <= maximum.doubleValue())) { // Use `!` for catching NaN. if (NilReason.forObject(newValue) == null) { final String msg = logOrFormat(classe, property, Errors.Keys.ValueOutOfRange_4, property, minimum, maximum, newValue); diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/package-info.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/package-info.java index e77da0c..3aa3f67 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/package-info.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/package-info.java @@ -24,7 +24,7 @@ * may change in incompatible ways in any future version without notice. * * @author Martin Desruisseaux (Geomatys) - * @version 1.0 + * @version 1.2 * @since 0.3 * @module */ diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java index db059d0..7bfdfa7 100644 --- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java +++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java @@ -264,7 +264,7 @@ public class DefaultGeographicBoundingBox extends AbstractGeographicExtent imple final boolean p = value; /* * (value == Boolean.FALSE) is an optimization for a common case avoiding PrimitiveTypeProperties check. - * DO NOT REPLACE BY 'equals' OR 'booleanValue()' - the exact reference value matter. + * DO NOT REPLACE BY `equals` OR `booleanValue()` — the exact reference value matter. */ if (p || (value == Boolean.FALSE) || !(PrimitiveTypeProperties.property(value) instanceof NilReason)) { return p; @@ -442,7 +442,7 @@ public class DefaultGeographicBoundingBox extends AbstractGeographicExtent imple southBoundLatitude = Latitude.clamp(southBoundLatitude); northBoundLatitude = Latitude.clamp(northBoundLatitude); final double span = eastBoundLongitude - westBoundLongitude; - if (!(span >= (Longitude.MAX_VALUE - Longitude.MIN_VALUE))) { // 'span' may be NaN. + if (!(span >= (Longitude.MAX_VALUE - Longitude.MIN_VALUE))) { // `span` may be NaN. westBoundLongitude = Longitude.normalize(westBoundLongitude); eastBoundLongitude = Longitude.normalize(eastBoundLongitude); if (span != 0) { @@ -596,14 +596,14 @@ public class DefaultGeographicBoundingBox extends AbstractGeographicExtent imple * the result would be much wort (for each lower rectangle, imagine translating * the longuest part in the opposite direction instead of the shortest one). * - * Note that only one of 'left' and 'right' can be positive, otherwise we would + * Note that only one of `left` and `right` can be positive, otherwise we would * not be in the case where one box is crossing the anti-meridian while the other * box does not. */ if (left >= 0) return +1; if (right >= 0) return -1; /* - * Both 'left' and 'right' are negative. For each alternatives (translating λmin + * Both `left` and `right` are negative. For each alternatives (translating λmin * or translating λmax), we will choose the one which give the closest result to * a bound of this box: * @@ -618,7 +618,7 @@ public class DefaultGeographicBoundingBox extends AbstractGeographicExtent imple return (left < right) ? -1 : +1; } /* - * Same algorithm than above, but with the sign of 'left' an 'right' inversed. + * Same algorithm than above, but with the sign of `left` an `right` inversed. * The "if" statements have been combined for avoiding to repeat the +/- operations. */ if (!(left <= 0) && right <= 0 || left > right) { @@ -665,7 +665,7 @@ public class DefaultGeographicBoundingBox extends AbstractGeographicExtent imple double φmin = box.getSouthBoundLatitude(); double φmax = box.getNorthBoundLatitude(); /* - * Reminder: 'inclusion' is a mandatory attribute, so it should never be null for a + * Reminder: `inclusion` is a mandatory attribute, so it should never be null for a * valid metadata object. If the metadata object is invalid, it is better to get a * an exception than having a code doing silently some inappropriate work. */ diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java index a51e119..f3ecbd4 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_GeneralOperationParameter.java @@ -186,7 +186,7 @@ public final class CC_GeneralOperationParameter extends PropertyType<CC_GeneralO if (min instanceof Number) { final Comparable<?> max = descriptor.getMaximumValue(); if (max instanceof Number) { - // Compare as 'double' because we want (-0 == +0) to be true. + // Compare as `double` because we want (-0 == +0) to be true. return ((Number) min).doubleValue() == ((Number) max).doubleValue(); } } @@ -247,7 +247,7 @@ public final class CC_GeneralOperationParameter extends PropertyType<CC_GeneralO * assuming that the additional properties are acceptable. * * We make an exception to the above rule if the existing instance put a possibly too strong - * restriction on the parameter values. See 'isRestricted(…)' for more information. + * restriction on the parameter values. See `isRestricted(…)` for more information. */ if (!isRestricted((ParameterDescriptor<?>) complete)) { return complete; @@ -255,7 +255,7 @@ public final class CC_GeneralOperationParameter extends PropertyType<CC_GeneralO } /* * Collect the properties specified in the GML document and complete with the properties provided - * by the 'complete' descriptor. If the descriptor is a group, then this 'replacement' method will + * by the `complete` descriptor. If the descriptor is a group, then this `replacement` method will * be invoked recursively for each parameter in the group. */ final Map<String,Object> merged = new HashMap<>(expected); @@ -303,11 +303,11 @@ public final class CC_GeneralOperationParameter extends PropertyType<CC_GeneralO final GeneralParameterDescriptor p = provided[i]; try { /* - * Replace the descriptors provided in the GML document by descriptors from the 'complete' instance, + * Replace the descriptors provided in the GML document by descriptors from the `complete` instance, * if possible. Keep trace of the complete descriptors that we found in this process. */ GeneralParameterDescriptor predefined = complete.descriptor(p.getName().getCode()); - if (predefined != null) { // Safety in case 'complete' is a user's implementation. + if (predefined != null) { // Safety in case `complete` is a user's implementation. canSubstitute &= (provided[i] = merge(p, predefined)) == predefined; if (!included.add(predefined)) { throw new CorruptedObjectException(predefined); // Broken hashCode/equals, or object mutated. @@ -325,7 +325,7 @@ public final class CC_GeneralOperationParameter extends PropertyType<CC_GeneralO (caller == DefaultParameterValueGroup.class) ? "setValues" : "setDescriptors", e, canSubstitute); } /* - * If a parameter was not found in the 'complete' descriptor, we will not be able to use that descriptor. + * If a parameter was not found in the `complete` descriptor, we will not be able to use that descriptor. * But we may still be able to use its properties (name, alias, identifier) provided that the parameter * not found was optional. */ @@ -334,7 +334,7 @@ public final class CC_GeneralOperationParameter extends PropertyType<CC_GeneralO } if (isCompatible) { /* - * At this point, we determined that all mandatory parameters in the GML document exist in the 'complete' + * At this point, we determined that all mandatory parameters in the GML document exist in the `complete` * descriptor. However the converse is not necessarily true. Verify that all parameters missing in the GML * document were optional. */ @@ -427,9 +427,9 @@ public final class CC_GeneralOperationParameter extends PropertyType<CC_GeneralO T[] complete = (T[]) merged.get(key); if (complete != null) { /* - * Add the 'provided' values before 'complete' for two reasons: + * Add the `provided` values before `complete` for two reasons: * 1) Use the same insertion order than the declaration order in the GML file. - * 2) Replace 'provided' instances by 'complete' instances, since the latter + * 2) Replace `provided` instances by `complete` instances, since the latter * are sometime pre-defined instances defined as static final constants. */ final Map<NamedIdentifier,T> c = new LinkedHashMap<>(); diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java index 83e3f64..5ec514f 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CC_OperationMethod.java @@ -32,6 +32,7 @@ import org.opengis.parameter.ParameterDescriptorGroup; import org.opengis.referencing.operation.OperationMethod; import org.apache.sis.internal.jaxb.Context; import org.apache.sis.internal.jaxb.gco.PropertyType; +import org.apache.sis.internal.metadata.Identifiers; import org.apache.sis.internal.referencing.CoordinateOperations; import org.apache.sis.internal.referencing.provider.MapProjection; import org.apache.sis.parameter.DefaultParameterValue; @@ -39,7 +40,6 @@ import org.apache.sis.parameter.DefaultParameterValueGroup; import org.apache.sis.parameter.DefaultParameterDescriptorGroup; import org.apache.sis.referencing.operation.DefaultOperationMethod; import org.apache.sis.referencing.IdentifiedObjects; -import org.apache.sis.util.resources.Errors; import org.apache.sis.util.ArraysExt; @@ -48,7 +48,7 @@ import org.apache.sis.util.ArraysExt; * package documentation for more information about JAXB and interface. * * @author Martin Desruisseaux (Geomatys) - * @version 0.7 + * @version 1.2 * @since 0.6 * @module */ @@ -113,7 +113,7 @@ public final class CC_OperationMethod extends PropertyType<CC_OperationMethod, O * Parameters are mandatory and SIS classes need them. Provide an error message * here instead of waiting for a NullPointerException in some arbitrary place. */ - throw new IllegalArgumentException(Errors.format(Errors.Keys.MissingValueForProperty_1, "parameters")); + throw new IllegalArgumentException(Identifiers.missingValueForProperty(method.getName(), "parameters")); } metadata = method; } @@ -191,7 +191,7 @@ public final class CC_OperationMethod extends PropertyType<CC_OperationMethod, O if (method != null) { /* * Verify that the pre-defined operation method contains at least all the parameters specified by - * the 'descriptors' array. If this is the case, then the pre-defined parameters will be used in + * the `descriptors` array. If this is the case, then the pre-defined parameters will be used in * replacement of the given ones. */ final ParameterDescriptorGroup parameters = method.getParameters(); diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java index 3420131..650f1cc 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java @@ -1084,7 +1084,7 @@ public class AbstractIdentifiedObject extends FormattableObject implements Ident } else { /* * Our Code and RS_Identifier implementations should always create NamedIdentifier instance, - * so the 'instanceof' check should not be necessary. But we do a paranoiac check anyway. + * so the `instanceof` check should not be necessary. But we do a paranoiac check anyway. */ final GenericName n = id instanceof GenericName ? (GenericName) id : new NamedIdentifier(id); if (alias == null) { diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/ImmutableIdentifier.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/ImmutableIdentifier.java index 97de5bb..2cb778b 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/ImmutableIdentifier.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/ImmutableIdentifier.java @@ -465,7 +465,7 @@ public class ImmutableIdentifier extends FormattableObject implements Identifier * The code, codeSpace, authority and version local variables in this method usually have the exact same * value than the fields of the same name in this class. But we get those values by invoking the public * methods in order to give to users a chance to override those properties. The intent is also to use a - * consistent approach for all 'formatTo' implementations, since some other classes have no choice other + * consistent approach for all `formatTo` implementations, since some other classes have no choice other * than using the public methods. */ final String code = getCode(); diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java index 6824cfc..5c8fdb5 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java @@ -38,6 +38,7 @@ import org.apache.sis.referencing.operation.DefaultConversion; import org.apache.sis.internal.jaxb.referencing.CC_Conversion; import org.apache.sis.internal.referencing.ReferencingFactoryContainer; import org.apache.sis.internal.metadata.MetadataUtilities; +import org.apache.sis.internal.metadata.Identifiers; import org.apache.sis.internal.system.DefaultFactories; import org.apache.sis.internal.system.Semaphores; import org.apache.sis.util.resources.Errors; @@ -53,7 +54,7 @@ import static org.apache.sis.util.Utilities.deepEquals; * (not by a {@linkplain org.apache.sis.referencing.datum.AbstractDatum datum}). * * @author Martin Desruisseaux (IRD, Geomatys) - * @version 1.1 + * @version 1.2 * * @param <C> the conversion type, either {@code Conversion} or {@code Projection}. * @@ -223,7 +224,7 @@ abstract class AbstractDerivedCRS<C extends Conversion> extends AbstractCRS impl if (super.equals(object, mode)) { final boolean strict = (mode == ComparisonMode.STRICT); /* - * Avoid never-ending recursivity: Conversion has a 'targetCRS' field (inherited from + * Avoid never-ending recursivity: Conversion has a `targetCRS` field (inherited from * the AbstractCoordinateOperation super-class) that is set to this AbstractDerivedCRS. * * Do NOT compare the baseCRS explicitly. This is done implicitely in the comparison of the Conversion @@ -254,8 +255,8 @@ abstract class AbstractDerivedCRS<C extends Conversion> extends AbstractCRS impl @Override protected long computeHashCode() { /* - * Do not invoke 'conversionFromBase.hashCode()' in order to avoid a never-ending loop. - * This is because Conversion inherits a 'sourceCRS' field from the CoordinateOperation + * Do not invoke `conversionFromBase.hashCode()` in order to avoid a never-ending loop. + * This is because Conversion inherits a `sourceCRS` field from the CoordinateOperation * parent type, which is set to this DerivedCRS. Checking the OperationMethod does not * work neither for the reason documented inside the AbstractSingleOperation.equals(…) * method body. The MathTransform is our best discriminant. @@ -345,10 +346,10 @@ abstract class AbstractDerivedCRS<C extends Conversion> extends AbstractCRS impl } } /* - * If we reach this point, we failed to update the conversion. The 'baseCRS' information will be lost - * and call to 'getConversionFromBase()' will throw a ClassCastException if this instance is actually + * If we reach this point, we failed to update the conversion. The `baseCRS` information will be lost + * and call to `getConversionFromBase()` will throw a ClassCastException if this instance is actually * a ProjectedCRS (because of the method overriding with return type covariance). */ - throw new ValidationException(Errors.format(Errors.Keys.MissingValueForProperty_1, property)); + throw new ValidationException(Identifiers.missingValueForProperty(getName(), property)); } } diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java index 969b1b2..cd6eacb 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java @@ -45,8 +45,8 @@ import org.apache.sis.internal.referencing.CoordinateOperations; import org.apache.sis.internal.referencing.ReferencingUtilities; import org.apache.sis.internal.metadata.MetadataUtilities; import org.apache.sis.internal.system.DefaultFactories; +import org.apache.sis.internal.metadata.Identifiers; import org.apache.sis.util.collection.Containers; -import org.apache.sis.util.resources.Errors; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.ComparisonMode; @@ -64,7 +64,7 @@ import static org.apache.sis.util.Utilities.deepEquals; * {@link DefaultPassThroughOperation}.</p> * * @author Martin Desruisseaux (IRD, Geomatys) - * @version 0.8 + * @version 1.2 * @since 0.6 * @module */ @@ -346,7 +346,7 @@ class AbstractSingleOperation extends AbstractCoordinateOperation implements Sin private void setParameters(final GeneralParameterValue[] values) { if (parameters == null) { if (!(method instanceof DefaultOperationMethod)) { // May be a non-null proxy if defined only by xlink:href. - throw new IllegalStateException(Errors.format(Errors.Keys.MissingValueForProperty_1, "method")); + throw new IllegalStateException(Identifiers.missingValueForProperty(getName(), "method")); } /* * The descriptors in the <gml:method> element do not know the class of parameter value