This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-3.1
in repository https://gitbox.apache.org/repos/asf/sis.git

commit bede3d4c053dd9c9a855b924e2269b342f4d9312
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Fri Jun 28 05:12:40 2024 +0200

    Partial revert of the previous merge: the `CodeList.identifier()` method 
already existed in GeoAPI 3.0,
    we cannot change its return type (from `String` to `Optional<String>`) in 
GeoAPI 3.1.
---
 .../org/apache/sis/coverage/grid/PixelInCell.java   |  1 -
 .../org/apache/sis/temporal/DefaultInstant.java     |  4 +++-
 .../main/org/apache/sis/util/iso/Types.java         | 16 ++++++++++++++--
 .../apache/sis/xml/bind/gml/TimePeriodBound.java    |  7 ++++---
 .../org/apache/sis/geometry/CoordinateFormat.java   |  4 +++-
 .../sis/referencing/privy/AxisDirections.java       |  4 +++-
 .../org/apache/sis/util/privy/MetadataServices.java | 21 +--------------------
 geoapi/snapshot                                     |  2 +-
 .../main/org/apache/sis/cql/FilterToCQLVisitor.java |  8 ++++++--
 .../test/org/apache/sis/cql/FilterReadingTest.java  |  4 ++--
 10 files changed, 37 insertions(+), 34 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/PixelInCell.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/PixelInCell.java
index 13ebad22fd..b9771e9d7f 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/PixelInCell.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/PixelInCell.java
@@ -103,7 +103,6 @@ public enum PixelInCell implements ControlledVocabulary {
      *
      * @return the legacy ISO/OGC identifier for this constant.
      */
-    @Override
     public Optional<String> identifier() {
         return Optional.of(identifier);
     }
diff --git 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/DefaultInstant.java
 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/DefaultInstant.java
index 77cdcc2d1c..17f412ffe3 100644
--- 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/DefaultInstant.java
+++ 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/temporal/DefaultInstant.java
@@ -324,7 +324,9 @@ cmp:    if (canTestBefore | canTestAfter | canTestEqual) {
     public String toString() {
         final var s = new StringBuilder();
         if (indeterminate != null) {
-            s.append(indeterminate.identifier().orElse(indeterminate.name()));
+            String id = indeterminate.identifier();
+            if (id == null) id = indeterminate.name();
+            s.append(id);
             if (position != null) {
                 s.append(' ').append(position);
             }
diff --git 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/util/iso/Types.java 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/util/iso/Types.java
index 1214ab578d..37f8764164 100644
--- 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/util/iso/Types.java
+++ 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/util/iso/Types.java
@@ -222,7 +222,19 @@ public final class Types extends Static {
         if (code == null) {
             return null;
         }
-        String id = code.identifier().orElse("");
+        String id = null;
+        if (code instanceof CodeList<?>) {
+            id = ((CodeList<?>) code).identifier();
+        }
+        if (id == null) {
+            id = code.name();
+            for (String name : code.names()) {
+                if (!name.equals(id)) {
+                    id = name;
+                    break;
+                }
+            }
+        }
         return id.isEmpty() ? code.name() : id;
     }
 
@@ -255,7 +267,7 @@ public final class Types extends Static {
             return null;
         }
         final String name = code.name();
-        String id = code.identifier().orElse(name);
+        String id = getCodeName(code);
         for (final String candidate : code.names()) {
             if (!candidate.equals(name) && candidate.length() >= id.length()) {
                 id = candidate;
diff --git 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gml/TimePeriodBound.java
 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gml/TimePeriodBound.java
index cf94c7a1c9..b70dbc2a38 100644
--- 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gml/TimePeriodBound.java
+++ 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gml/TimePeriodBound.java
@@ -22,8 +22,10 @@ import jakarta.xml.bind.annotation.XmlElement;
 import jakarta.xml.bind.annotation.XmlAttribute;
 import jakarta.xml.bind.annotation.XmlTransient;
 
+// Specific to the main and geoapi-3.1 branches:
+import org.apache.sis.util.iso.Types;
+
 // Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.temporal.IndeterminateValue;
 import org.opengis.temporal.Instant;
 
 
@@ -106,8 +108,7 @@ public abstract class TimePeriodBound {
                 value = TimeInstant.toXML(instant.getPosition());
                 if (value == null) {
                     instant.getIndeterminatePosition()
-                            .flatMap(IndeterminateValue::identifier)
-                            .ifPresent((p) -> indeterminatePosition = p);
+                            .ifPresent((p) -> indeterminatePosition = 
Types.getCodeName(p));
                 }
             }
             if (value == null && indeterminatePosition == null) {
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
index e39e51b45c..69cd312e03 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
@@ -632,7 +632,9 @@ public class CoordinateFormat extends 
CompoundFormat<DirectPosition> {
      */
     private static String symbol(final AxisDirection direction) {
         // Following cast uses our knowledge of `camelCaseToAcronym` 
implementation.
-        return ((StringBuilder) 
CharSequences.camelCaseToAcronym(direction.identifier().orElse(direction.name())))
+        String id = direction.identifier();
+        if (id == null) id = direction.name();
+        return ((StringBuilder) CharSequences.camelCaseToAcronym(id))
                 .insert(0, Characters.NO_BREAK_SPACE).toString();
     }
 
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/AxisDirections.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/AxisDirections.java
index 2cec5bccff..f1a452946a 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/AxisDirections.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/AxisDirections.java
@@ -686,7 +686,9 @@ next:       for (int i=0; i <= limit; i++) {
                 return abbreviation;
             }
         }
-        return 
camelCaseToAcronym(direction.identifier().orElse(direction.name())).toString().intern();
+        String id = direction.identifier();
+        if (id == null) id = direction.name();
+        return camelCaseToAcronym(id).toString().intern();
     }
 
     /**
diff --git 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/privy/MetadataServices.java
 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/privy/MetadataServices.java
index c20f80d7c5..de950c772d 100644
--- 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/privy/MetadataServices.java
+++ 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/privy/MetadataServices.java
@@ -29,9 +29,6 @@ import org.apache.sis.system.OptionalDependency;
 import org.apache.sis.util.CharSequences;
 
 // Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import java.util.MissingResourceException;
-import org.opengis.annotation.UML;
-import org.opengis.annotation.ResourceBundles;
 import org.opengis.util.ControlledVocabulary;
 
 
@@ -122,23 +119,7 @@ public class MetadataServices extends OptionalDependency {
      * @see org.apache.sis.util.iso.Types#getCodeTitle(ControlledVocabulary)
      */
     public String getCodeTitle(final ControlledVocabulary code, final Locale 
locale) {
-        /*
-         * Following code reproduces the work done by 
`org.apache.sis.util.iso.Types.getCodeList(…)` with
-         * less handling of special cases. It is executed only if the 
`org.apache.sis.metadata` module is
-         * not on the module path, otherwise the `org.apache.sis.metadata` 
implementation will be used.
-         */
-        final UML uml = code.getClass().getAnnotation(UML.class);
-        if (uml != null) try {
-            return 
ResourceBundles.codeLists(locale).getString(uml.identifier() + '.' + 
code.identifier());
-        } catch (MissingResourceException e) {
-            /*
-             * Ignore. The reason for not finding the resource may because of 
above code not covering enough cases.
-             * Usually the `org.apache.sis.metadata` module will be present on 
the module path, in which case this
-             * implementation will not be used. We need just enough code for 
allowing `org.apache.sis.util` tests
-             * to pass.
-             */
-        }
-        return 
CharSequences.camelCaseToSentence(code.identifier().orElse(code.name())).toString();
+        return CharSequences.camelCaseToSentence(code.name()).toString();
     }
 
     /**
diff --git a/geoapi/snapshot b/geoapi/snapshot
index e32e9fca0a..3a789ec3cf 160000
--- a/geoapi/snapshot
+++ b/geoapi/snapshot
@@ -1 +1 @@
-Subproject commit e32e9fca0a1b0f7f07b98cb7d396bff23a6a35c2
+Subproject commit 3a789ec3cfbbc41a961963bbc1447f0b988185bc
diff --git 
a/incubator/src/org.apache.sis.cql/main/org/apache/sis/cql/FilterToCQLVisitor.java
 
b/incubator/src/org.apache.sis.cql/main/org/apache/sis/cql/FilterToCQLVisitor.java
index 8e07c44d27..98ea262159 100644
--- 
a/incubator/src/org.apache.sis.cql/main/org/apache/sis/cql/FilterToCQLVisitor.java
+++ 
b/incubator/src/org.apache.sis.cql/main/org/apache/sis/cql/FilterToCQLVisitor.java
@@ -142,14 +142,18 @@ final class FilterToCQLVisitor extends 
Visitor<Feature,StringBuilder> {
         });
         for (final SpatialOperatorName type : SpatialOperatorName.values()) {
             if (type != SpatialOperatorName.BBOX) {
-                function(type, 
type.identifier().orElse(type.name()).toUpperCase(Locale.US));
+                String id = type.identifier();
+                if (id == null) id = type.name();
+                function(type, id.toUpperCase(Locale.US));
                 if (type == SpatialOperatorName.OVERLAPS) break;
             }
         }
         function(DistanceOperatorName.WITHIN, "DWITHIN");
         function(DistanceOperatorName.BEYOND, "BEYOND");
         for (final TemporalOperatorName type : TemporalOperatorName.values()) {
-            function(type, 
type.identifier().orElse(type.name()).toUpperCase(Locale.US));
+            String id = type.identifier();
+            if (id == null) id = type.name();
+            function(type, id.toUpperCase(Locale.US));
             if (type == TemporalOperatorName.ANY_INTERACTS) break;
         }
         /*
diff --git 
a/incubator/src/org.apache.sis.cql/test/org/apache/sis/cql/FilterReadingTest.java
 
b/incubator/src/org.apache.sis.cql/test/org/apache/sis/cql/FilterReadingTest.java
index e220fe4b6c..fcedc82f40 100644
--- 
a/incubator/src/org.apache.sis.cql/test/org/apache/sis/cql/FilterReadingTest.java
+++ 
b/incubator/src/org.apache.sis.cql/test/org/apache/sis/cql/FilterReadingTest.java
@@ -352,7 +352,7 @@ public final class FilterReadingTest extends CQLTestCase {
     }
 
     private Filter<?> testSpatialOperators(final CodeList<?> operator, final 
String suffix) throws CQLException {
-        final String name = operator.identifier().get().toUpperCase(Locale.US);
+        final String name = operator.identifier().toUpperCase(Locale.US);
         final String cql = name + "(\"att\", POLYGON((10 20, 30 40, 50 60, 10 
20))" + suffix + ')';
         final Filter<?> filter = CQL.parseFilter(cql);
         assertInstanceOf(SpatialOperator.class, filter, name);
@@ -429,7 +429,7 @@ public final class FilterReadingTest extends CQLTestCase {
     @Test
     public void testTemporalOperators() throws CQLException, ParseException {
         for (final TemporalOperatorName operator : 
TemporalOperatorName.values()) {
-            final String name = 
operator.identifier().get().toUpperCase(Locale.US);
+            final String name = operator.identifier().toUpperCase(Locale.US);
             final String cql  = "att " + name + " 2012-03-21T05:42:36Z";
             final Filter<?> filter = CQL.parseFilter(cql);
             assertInstanceOf(TemporalOperator.class, filter, name);

Reply via email to