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 72265215a664fc7857d6d8bac7e0a55ee502e840 Author: Martin Desruisseaux <[email protected]> AuthorDate: Fri Sep 26 10:41:03 2025 +0200 Remove the hack which was used for declaring a parameter with more than one unit of measurement. That hack is no longer necessary since the previous commit allows `EPSGDataAccess` to associate parameter descriptor on a case-by-case basis, with the units expected by a particular operation. --- .../main/org/apache/sis/parameter/Verifier.java | 26 ++-------- .../referencing/factory/sql/EPSGDataAccess.java | 60 ++++++++-------------- .../referencing/internal/EPSGParameterDomain.java | 53 ------------------- 3 files changed, 23 insertions(+), 116 deletions(-) diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/Verifier.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/Verifier.java index 736c17384a..f6a1567ffb 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/Verifier.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/parameter/Verifier.java @@ -28,7 +28,6 @@ import org.opengis.metadata.Identifier; import org.opengis.parameter.ParameterDescriptor; import org.opengis.parameter.GeneralParameterDescriptor; import org.opengis.parameter.InvalidParameterValueException; -import org.apache.sis.referencing.internal.EPSGParameterDomain; import org.apache.sis.referencing.internal.Resources; import org.apache.sis.system.Semaphores; import org.apache.sis.util.Numbers; @@ -117,13 +116,10 @@ final class Verifier { UnitConverter converter = null; Object convertedValue = value; if (unit != null) { - Unit<?> def = descriptor.getUnit(); + final Unit<?> def = descriptor.getUnit(); if (def == null) { - def = getCompatibleUnit(Parameters.getValueDomain(descriptor), unit); - if (def == null) { - final String name = getDisplayName(descriptor); - throw new InvalidParameterValueException(Resources.format(Resources.Keys.UnitlessParameter_1, name), name, unit); - } + final String name = getDisplayName(descriptor); + throw new InvalidParameterValueException(Resources.format(Resources.Keys.UnitlessParameter_1, name), name, unit); } if (!unit.equals(def)) { final short expectedID = getUnitMessageID(def); @@ -324,22 +320,6 @@ final class Verifier { } } - /** - * If the given domain of values accepts units of incompatible dimensions, return the unit which is compatible - * with the given units. This is a non-public mechanism handling a few parameters in the EPSG database, like - * <cite>Coordinate 1 of evaluation point</cite> (EPSG:8617). - */ - private static Unit<?> getCompatibleUnit(final Range<?> valueDomain, final Unit<?> unit) { - if (valueDomain instanceof EPSGParameterDomain) { - for (final Unit<?> valid : ((EPSGParameterDomain) valueDomain).units) { - if (unit.isCompatible(valid)) { - return valid; - } - } - } - return null; - } - /** * Returns an error message for the error detected by * {@link #ensureValidValue(Class, Set, Range, Object)}. diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java index 8d890cb7e9..ccd8b5f226 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java @@ -21,7 +21,6 @@ import java.util.Set; import java.util.Map; import java.util.HashMap; import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.ArrayList; import java.util.Collection; @@ -30,7 +29,6 @@ import java.util.Date; import java.util.Locale; import java.util.Objects; import java.util.Optional; -import java.util.StringJoiner; import java.util.stream.IntStream; import java.util.function.ToIntFunction; import java.util.logging.Level; @@ -86,7 +84,6 @@ import org.apache.sis.referencing.factory.IdentifiedObjectFinder; import org.apache.sis.referencing.internal.DeferredCoordinateOperation; import org.apache.sis.referencing.internal.DeprecatedCode; import org.apache.sis.referencing.internal.Epoch; -import org.apache.sis.referencing.internal.EPSGParameterDomain; import org.apache.sis.referencing.internal.ParameterizedTransformBuilder; import org.apache.sis.referencing.internal.PositionalAccuracyConstant; import org.apache.sis.referencing.internal.SignReversalComment; @@ -112,7 +109,6 @@ import org.apache.sis.util.resources.Vocabulary; import org.apache.sis.util.resources.Errors; import org.apache.sis.util.logging.Logging; import org.apache.sis.util.internal.shared.Constants; -import org.apache.sis.util.internal.shared.CollectionsExt; import org.apache.sis.util.internal.shared.Strings; import org.apache.sis.util.iso.Types; import org.apache.sis.temporal.LenientDateFormat; @@ -2944,10 +2940,11 @@ search: try (ResultSet result = executeMetadataQuery("Deprecation", /** * Determines the most frequently used units of measurement of a parameter. * We can have many different units for the same parameter, but usually all units have the same dimension. - * For example, we may have meters, kilometers, and feet. In such case, the set of units will have only - * one element and that element will be the most frequently used unit. However, some parameters accept - * units of different dimensions. For example, the "Coordinate 1 of evaluation point" (EPSG:8617) parameter - * may be in meters or in degrees. In such case, the set of units will have two elements. + * For example, we may have meters, kilometers, and feet. In such case, the declared unit will be the most + * frequently used unit. However, some parameters accept units of different dimensions. For example, the + * "Coordinate 1 of evaluation point" (EPSG:8617) parameter may be in meters or in degrees. In such case, + * the {@code dimension} argument is necessary for considering only compatible units when searching for + * the most frequently used unit. * * @param parameter the <abbr>EPSG</abbr> code of the parameter descriptor. * @param options the options where to store the {@value #UOM_CODE_OPTION} value. @@ -2956,8 +2953,6 @@ search: try (ResultSet result = executeMetadataQuery("Deprecation", private void getParameterUnit(final int parameter, final Map<String, String> options, final Unit<?> dimension) throws SQLException, FactoryException { - final var codes = new StringJoiner(","); - final var units = new ArrayList<Unit<?>>(); try (ResultSet result = executeQueryForCodes( "Parameter Unit", "SELECT UOM_CODE" @@ -2966,26 +2961,20 @@ search: try (ResultSet result = executeMetadataQuery("Deprecation", + " GROUP BY UOM_CODE" + " ORDER BY COUNT(UOM_CODE) DESC", parameter)) { -next: while (result.next()) { + while (result.next()) { final String uom_code = getOptionalString(result, 1); if (uom_code != null) { - final Unit<?> candidate = owner.createUnit(uom_code); - if (dimension != null && !candidate.isCompatible(dimension)) { - continue; - } - for (final Unit<?> e : units) { - if (candidate.isCompatible(e)) { - continue next; + if (dimension != null) { + final Unit<?> candidate = owner.createUnit(uom_code); + if (!candidate.isCompatible(dimension)) { + continue; } } - units.add(candidate); - codes.add(uom_code); + options.put(UOM_CODE_OPTION, uom_code); + return; } } } - if (codes.length() != 0) { - options.put(UOM_CODE_OPTION, codes.toString()); - } } /** @@ -3125,20 +3114,22 @@ next: while (result.next()) { throws SQLException, FactoryException { final Class<?> type; - final Set<Unit<?>> units; + NumberRange<?> valueDomain = null; if (EPSG_CODE_PARAMETERS.contains(code)) { // If the parameter is an EPSG code, the type is integer and there is no unit. - type = Integer.class; - units = Set.of(); + type = Integer.class; } else { if (URI_TYPE.equalsIgnoreCase(options.remove(PARAMETER_TYPE_OPTION))) { type = String.class; } else { type = Double.class; } - units = new LinkedHashSet<>(); - for (String uom_code : (String[]) CharSequences.split(options.remove(UOM_CODE_OPTION), ',')) { - units.add(owner.createUnit(uom_code)); + final String uom_code = options.remove(UOM_CODE_OPTION); + if (uom_code != null) { + valueDomain = MeasurementRange.create( + Double.NEGATIVE_INFINITY, false, + Double.POSITIVE_INFINITY, false, + owner.createUnit(uom_code)); } } /* @@ -3149,17 +3140,6 @@ next: while (result.next()) { */ metadata.put(IdentifiedObject.REMARKS_KEY, SignReversalComment.of( SQLUtilities.parseBoolean(options.remove(SIGN_REVERSAL_OPTION)))); - /* - * Now creates the parameter descriptor. - */ - final NumberRange<?> valueDomain; - switch (units.size()) { - case 0: valueDomain = null; break; - default: valueDomain = new EPSGParameterDomain(units); break; - case 1: valueDomain = MeasurementRange.create(Double.NEGATIVE_INFINITY, false, - Double.POSITIVE_INFINITY, false, - CollectionsExt.first(units)); break; - } return new DefaultParameterDescriptor<>(metadata, 1, 1, type, valueDomain, null, null); } diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/EPSGParameterDomain.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/EPSGParameterDomain.java deleted file mode 100644 index 0ce8691280..0000000000 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/EPSGParameterDomain.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sis.referencing.internal; - -import java.util.Set; -import javax.measure.Unit; -import org.apache.sis.measure.NumberRange; -import org.apache.sis.util.internal.shared.CollectionsExt; - - -/** - * The domain of values of an <abbr>EPSG</abbr> parameter which accepts different units. - * An example is the EPSG:8617 (<cite>Coordinate 1 of evaluation point</cite>) parameter, - * which may be used in the <abbr>EPSG</abbr> database with either metres or degrees units. - * - * @author Martin Desruisseaux (Geomatys) - */ -public final class EPSGParameterDomain extends NumberRange<Double> { - /** - * For cross-version compatibility. - */ - private static final long serialVersionUID = -8462017652419319184L; - - /** - * The units of measurement. - */ - @SuppressWarnings("serial") // Most SIS implementations are serializable. - public final Set<Unit<?>> units; - - /** - * Creates a new parameter descriptor for the given units. - * - * @param units the units. - */ - public EPSGParameterDomain(final Set<Unit<?>> units) { - super(Double.class, null, false, null, false); - this.units = CollectionsExt.unmodifiableOrCopy(units); - } -}
