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 2b7f3285cfc9deabac62810de5f9e884f102ff7a
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Tue Aug 1 16:39:23 2023 +0200

    Rename `GeometryType` enumeration values for matching WKT names.
---
 .../apache/sis/internal/feature/GeometryType.java  | 36 +++++++++----------
 .../apache/sis/internal/feature/esri/Factory.java  |  8 ++---
 .../apache/sis/internal/feature/jts/Factory.java   | 20 +++++------
 .../apache/sis/internal/feature/jts/Wrapper.java   | 22 ++++++------
 .../apache/sis/internal/filter/sqlmm/SQLMM.java    | 40 +++++++++++-----------
 .../sis/internal/feature/GeometryTypeTest.java     |  8 ++---
 6 files changed, 66 insertions(+), 68 deletions(-)

diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/GeometryType.java
 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/GeometryType.java
index ed6c4e73a8..0476da682e 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/GeometryType.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/GeometryType.java
@@ -21,9 +21,10 @@ import java.util.Locale;
 
 /**
  * Implementation-neutral description of the type of geometry.
+ * The name of each enumeration value is the name in WKT format.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.4
  *
  * @see Geometries#getGeometryClass(GeometryType)
  *
@@ -65,22 +66,22 @@ public enum GeometryType {
     /**
      * Set of points.
      */
-    MULTI_POINT,
+    MULTIPOINT,
 
     /**
      * Set of linestrings.
      */
-    MULTI_LINESTRING,
+    MULTILINESTRING,
 
     /**
      * Set of polygons.
      */
-    MULTI_POLYGON,
+    MULTIPOLYGON,
 
     /**
      * Set of geometries of any type except other geometry collection.
      */
-    GEOMETRY_COLLECTION;
+    GEOMETRYCOLLECTION;
 
     /**
      * The type of this geometry as specified in Well-Known Binary (WKB) 
specification.
@@ -101,13 +102,13 @@ public enum GeometryType {
 
     /**
      * Returns {@code true} if this geometry type is some sort of collection.
-     * Those types are {@link #MULTI_POINT}, {@link #MULTI_LINESTRING},
-     * {@link #MULTI_POLYGON} or {@link #GEOMETRY_COLLECTION}.
+     * Those types are {@link #MULTIPOINT}, {@link #MULTILINESTRING},
+     * {@link #MULTIPOLYGON} or {@link #GEOMETRYCOLLECTION}.
      *
      * @return whether this geometry type is some kind of collections.
      */
     public final boolean isCollection() {
-        return ordinal() >= MULTI_POINT.ordinal();
+        return ordinal() >= MULTIPOINT.ordinal();
     }
 
     /**
@@ -126,14 +127,11 @@ public enum GeometryType {
                 // Remove Z, M or ZM suffix.
                 if (/*non-empty*/ name.charAt(length - 1) == 'M') length--;
                 if (length > 0 && name.charAt(length - 1) == 'Z') length--;
-                name = name.substring(0, length);
-                switch (name) {
-                    case "MULTIPOINT":      return MULTI_POINT;
-                    case "MULTILINESTRING": return MULTI_LINESTRING;
-                    case "MULTIPOLYGON":    return MULTI_POLYGON;
-                    case "GEOMCOLLECTION":  return GEOMETRY_COLLECTION;
-                    default: return valueOf(name);
+                name = name.substring(0, length).replace("_", "");
+                if (name.equals("GEOMCOLLECTION")) {    // Alternative name 
also accepted.
+                    return GEOMETRYCOLLECTION;
                 }
+                return valueOf(name);
             }
         }
         return null;
@@ -158,10 +156,10 @@ public enum GeometryType {
             case 1:  return POINT;
             case 2:  return LINESTRING;
             case 3:  return POLYGON;
-            case 4:  return MULTI_POINT;
-            case 5:  return MULTI_LINESTRING;
-            case 6:  return MULTI_POLYGON;
-            case 7:  return GEOMETRY_COLLECTION;
+            case 4:  return MULTIPOINT;
+            case 5:  return MULTILINESTRING;
+            case 6:  return MULTIPOLYGON;
+            case 7:  return GEOMETRYCOLLECTION;
         //  case 13: return CURVE;
         //  case 14: return SURFACE;
         //  case 15: return POLYHEDRALSURFACE;
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/esri/Factory.java
 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/esri/Factory.java
index acee82c63c..d0a9d12c3d 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/esri/Factory.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/esri/Factory.java
@@ -225,11 +225,11 @@ public final class Factory extends Geometries<Geometry> {
         if (geometry == null) {
             boolean isPolygon = false;
             switch (type) {
-                case MULTI_LINESTRING:
+                case MULTILINESTRING:
                 case LINESTRING: break;
-                case MULTI_POLYGON:
+                case MULTIPOLYGON:
                 case POLYGON: isPolygon=true; break;
-                case GEOMETRY_COLLECTION: {
+                case GEOMETRYCOLLECTION: {
                     for (final Object component : data) {
                         isPolygon = (((Geometry) component).getType() == 
Geometry.Type.Polygon);
                         if (!isPolygon) break;
@@ -238,7 +238,7 @@ public final class Factory extends Geometries<Geometry> {
                 }
                 case GEOMETRY:      // Default to multi-points for now.
                 case POINT:
-                case MULTI_POINT: {
+                case MULTIPOINT: {
                     final MultiPoint points = new MultiPoint();
                     for (final Object p : data) {
                         points.add((Point) p);
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Factory.java
 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Factory.java
index 07be12678c..8428648a76 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Factory.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Factory.java
@@ -408,26 +408,26 @@ public final class Factory extends Geometries<Geometry> {
     public GeometryWrapper createFromComponents(final GeometryType type, final 
Object components) {
         final Geometry geometry;
         switch (type) {
-            case GEOMETRY_COLLECTION: {
+            case GEOMETRYCOLLECTION: {
                 // The ClassCastException that may happen here is part of 
method contract.
                 geometry = factory.createGeometryCollection((Geometry[]) 
components);
                 break;
             }
-            case MULTI_LINESTRING: {
+            case MULTILINESTRING: {
                 // The ClassCastException that may happen here is part of 
method contract.
                 geometry = createFromComponents((LineString[]) components,
                             LineString::getCoordinateSequence,
                             GeometryFactory::createMultiLineString);
                 break;
             }
-            case MULTI_POLYGON: {
+            case MULTIPOLYGON: {
                 // The ClassCastException that may happen here is part of 
method contract.
                 geometry = createFromComponents((Polygon[]) components,
                             (g) -> g.getExteriorRing().getCoordinateSequence(),
                             GeometryFactory::createMultiPolygon);
                 break;
             }
-            case MULTI_POINT: {
+            case MULTIPOINT: {
                 if (components instanceof Point[]) {
                     geometry = createFromComponents((Point[]) components,
                                 Point::getCoordinateSequence,
@@ -472,12 +472,12 @@ public final class Factory extends Geometries<Geometry> {
                     cs = gf.getCoordinateSequenceFactory().create(coordinates);
                 }
                 switch (type) {
-                    case GEOMETRY:    // Default to multi-points for now.
-                    case MULTI_POINT: geometry = gf.createMultiPoint(cs); 
break;
-                    case LINESTRING:  geometry = gf.createLineString(cs); 
break;
-                    case POLYGON:     geometry = gf.createPolygon(cs); break;
-                    case POINT:       geometry = 
gf.createMultiPoint(cs).getCentroid(); break;
-                    default:          throw new AssertionError(type);
+                    case GEOMETRY:   // Default to multi-points for now.
+                    case MULTIPOINT: geometry = gf.createMultiPoint(cs); break;
+                    case LINESTRING: geometry = gf.createLineString(cs); break;
+                    case POLYGON:    geometry = gf.createPolygon(cs); break;
+                    case POINT:      geometry = 
gf.createMultiPoint(cs).getCentroid(); break;
+                    default:         throw new AssertionError(type);
                 }
             }
         }
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Wrapper.java
 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Wrapper.java
index e0e3188cd3..b3606a8b02 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Wrapper.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/Wrapper.java
@@ -574,13 +574,13 @@ add:    for (Geometry next = geometry;;) {
      */
     static Class<?> getGeometryClass(final GeometryType type) {
         switch (type) {
-            default:               return Geometry.class;
-            case POINT:            return Point.class;
-            case LINESTRING:       return LineString.class;
-            case POLYGON:          return Polygon.class;
-            case MULTI_POINT:      return MultiPoint.class;
-            case MULTI_LINESTRING: return MultiLineString.class;
-            case MULTI_POLYGON:    return MultiPolygon.class;
+            default:              return Geometry.class;
+            case POINT:           return Point.class;
+            case LINESTRING:      return LineString.class;
+            case POLYGON:         return Polygon.class;
+            case MULTIPOINT:      return MultiPoint.class;
+            case MULTILINESTRING: return MultiLineString.class;
+            case MULTIPOLYGON:    return MultiPolygon.class;
         }
     }
 
@@ -617,24 +617,24 @@ add:    for (Geometry next = geometry;;) {
                 if (isCollection(geometry)) break;
                 return factory.createPolygon(geometry.getCoordinates());
             }
-            case MULTI_POINT: {
+            case MULTIPOINT: {
                 return (geometry instanceof Point)
                         ? factory.createMultiPoint(new Point[] {(Point) 
geometry})
                         : 
factory.createMultiPointFromCoords(geometry.getCoordinates());
             }
-            case MULTI_LINESTRING: {
+            case MULTILINESTRING: {
                 return toCollection(factory,
                         LineString.class, LineString[]::new,
                         GeometryFactory::createLineString,
                         GeometryFactory::createMultiLineString);
             }
-            case MULTI_POLYGON: {
+            case MULTIPOLYGON: {
                 return toCollection(factory,
                         Polygon.class, Polygon[]::new,
                         GeometryFactory::createPolygon,
                         GeometryFactory::createMultiPolygon);
             }
-            case GEOMETRY_COLLECTION: {
+            case GEOMETRYCOLLECTION: {
                 if (geometry instanceof Point) {
                     return factory.createMultiPoint(new Point[] {(Point) 
geometry});
                 } else if (geometry instanceof LineString) {
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/SQLMM.java
 
b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/SQLMM.java
index 6be342fb50..c8c3615032 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/SQLMM.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/SQLMM.java
@@ -550,17 +550,17 @@ public enum SQLMM {
      * @see #ST_MultiLineString
      * @see #ST_MultiPolygon
      */
-    ST_GeomCollection(1, 2, null, null, GEOMETRY_COLLECTION),
+    ST_GeomCollection(1, 2, null, null, GEOMETRYCOLLECTION),
 
     /**
      * The cardinality of the geometries of a geometry collection.
      */
-    ST_NumGeometries(GEOMETRY_COLLECTION, Integer.class),
+    ST_NumGeometries(GEOMETRYCOLLECTION, Integer.class),
 
     /**
      * The specified element in a geometry collection.
      */
-    ST_GeometryN(2, 2, GEOMETRY_COLLECTION, null, GEOMETRY),
+    ST_GeometryN(2, 2, GEOMETRYCOLLECTION, null, GEOMETRY),
 
     /**
      * Constructor for a geometry collection which is transformed from a 
Well-Known Text (WKT) representation.
@@ -573,7 +573,7 @@ public enum SQLMM {
      * @see #ST_MLineFromText
      * @see #ST_MPolyFromText
      */
-    ST_GeomCollFromText(1, 2, null, null, GEOMETRY_COLLECTION),
+    ST_GeomCollFromText(1, 2, null, null, GEOMETRYCOLLECTION),
 
     /**
      * Constructor for a geometry collection which is transformed from a 
Well-Known Binary (WKB) representation.
@@ -586,7 +586,7 @@ public enum SQLMM {
      * @see #ST_MLineFromWKB
      * @see #ST_MPolyFromWKB
      */
-    ST_GeomCollFromWKB(1, 2, null, null, GEOMETRY_COLLECTION),
+    ST_GeomCollFromWKB(1, 2, null, null, GEOMETRYCOLLECTION),
 
     /**
      * {@code MultiPoint} constructed from either a Well-Known Text (WKT) 
representation,
@@ -598,7 +598,7 @@ public enum SQLMM {
      * @see #ST_MultiLineString
      * @see #ST_MultiPolygon
      */
-    ST_MultiPoint(1, 2, null, null, MULTI_POINT),
+    ST_MultiPoint(1, 2, null, null, MULTIPOINT),
 
     /**
      * Constructor for a multi-point which is transformed from a Well-Known 
Text (WKT) representation.
@@ -611,7 +611,7 @@ public enum SQLMM {
      * @see #ST_MLineFromText
      * @see #ST_MPolyFromText
      */
-    ST_MPointFromText(1, 2, null, null, MULTI_POINT),
+    ST_MPointFromText(1, 2, null, null, MULTIPOINT),
 
     /**
      * Constructor for a multi-point which is transformed from a Well-Known 
Binary (WKB) representation.
@@ -624,7 +624,7 @@ public enum SQLMM {
      * @see #ST_MLineFromWKB
      * @see #ST_MPolyFromWKB
      */
-    ST_MPointFromWKB(1, 2, null, null, MULTI_POINT),
+    ST_MPointFromWKB(1, 2, null, null, MULTIPOINT),
 
     /**
      * {@code MultiLineString} constructed from either a Well-Known Text (WKT) 
representation,
@@ -636,7 +636,7 @@ public enum SQLMM {
      * @see #ST_MultiPoint
      * @see #ST_MultiPolygon
      */
-    ST_MultiLineString(1, 2, null, null, MULTI_LINESTRING),
+    ST_MultiLineString(1, 2, null, null, MULTILINESTRING),
 
     /**
      * Constructor for a multi-line string which is transformed from a 
Well-Known Text (WKT) representation.
@@ -649,7 +649,7 @@ public enum SQLMM {
      * @see #ST_MPointFromText
      * @see #ST_MPolyFromText
      */
-    ST_MLineFromText(1, 2, null, null, MULTI_LINESTRING),
+    ST_MLineFromText(1, 2, null, null, MULTILINESTRING),
 
     /**
      * Constructor for a multi-line string which is transformed from a 
Well-Known Binary (WKB) representation.
@@ -662,7 +662,7 @@ public enum SQLMM {
      * @see #ST_MPointFromWKB
      * @see #ST_MPolyFromWKB
      */
-    ST_MLineFromWKB(1, 2, null, null, MULTI_LINESTRING),
+    ST_MLineFromWKB(1, 2, null, null, MULTILINESTRING),
 
     /**
      * {@code MultiPolygon} constructed from either a Well-Known Text (WKT) 
representation,
@@ -674,7 +674,7 @@ public enum SQLMM {
      * @see #ST_MultiPoint
      * @see #ST_MultiLineString
      */
-    ST_MultiPolygon(1, 2, null, null, MULTI_POLYGON),
+    ST_MultiPolygon(1, 2, null, null, MULTIPOLYGON),
 
     /**
      * Constructor for a multi-polygon which is transformed from a Well-Known 
Text (WKT) representation.
@@ -687,7 +687,7 @@ public enum SQLMM {
      * @see #ST_MPointFromText
      * @see #ST_MLineFromText
      */
-    ST_MPolyFromText(1, 2, null, null, MULTI_POLYGON),
+    ST_MPolyFromText(1, 2, null, null, MULTIPOLYGON),
 
     /**
      * Constructor for a multi-polygon which is transformed from a Well-Known 
Binary (WKB) representation.
@@ -700,7 +700,7 @@ public enum SQLMM {
      * @see #ST_MPointFromWKB
      * @see #ST_MLineFromWKB
      */
-    ST_MPolyFromWKB(1, 2, null, null, MULTI_POLYGON),
+    ST_MPolyFromWKB(1, 2, null, null, MULTIPOLYGON),
 
     /**
      * Constructor for a multi-polygon which is transformed from a Well-Known 
Text (WKT) representation
@@ -708,13 +708,13 @@ public enum SQLMM {
      *
      * @see #ST_BdPolyFromText
      */
-    ST_BdMPolyFromText(1, 2, null, null, MULTI_POLYGON),
+    ST_BdMPolyFromText(1, 2, null, null, MULTIPOLYGON),
 
     /**
      * Constructor for a multi-polygon which is transformed from a Well-Known 
Binary (WKB) representation
      * of multi line string. There is one polygon for each line-string.
      */
-    ST_BdMPolyFromWKB(1, 2, null, null, MULTI_POLYGON),
+    ST_BdMPolyFromWKB(1, 2, null, null, MULTIPOLYGON),
 
     /**
      * Cast a geometry to a specific instantiable subtype of geometry.
@@ -729,22 +729,22 @@ public enum SQLMM {
     /**
      * Cast a geometry to a specific instantiable subtype of geometry.
      */
-    ST_ToMultiPoint(GEOMETRY, MULTI_POINT),
+    ST_ToMultiPoint(GEOMETRY, MULTIPOINT),
 
     /**
      * Cast a geometry to a specific instantiable subtype of geometry.
      */
-    ST_ToMultiLine(GEOMETRY, MULTI_LINESTRING),
+    ST_ToMultiLine(GEOMETRY, MULTILINESTRING),
 
     /**
      * Cast a geometry to a specific instantiable subtype of geometry.
      */
-    ST_ToMultiPolygon(GEOMETRY, MULTI_POLYGON),
+    ST_ToMultiPolygon(GEOMETRY, MULTIPOLYGON),
 
     /**
      * Cast a geometry to a specific instantiable subtype of geometry.
      */
-    ST_ToGeomColl(GEOMETRY, GEOMETRY_COLLECTION),
+    ST_ToGeomColl(GEOMETRY, GEOMETRYCOLLECTION),
 
     /**
      * Computes a geometry simplification.
diff --git 
a/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometryTypeTest.java
 
b/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometryTypeTest.java
index bcfd8dd893..bb339e60f3 100644
--- 
a/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometryTypeTest.java
+++ 
b/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometryTypeTest.java
@@ -51,9 +51,9 @@ public final class GeometryTypeTest extends TestCase {
      */
     @Test
     public void testForName() {
-        assertSame(GeometryType.MULTI_POLYGON, 
GeometryType.forName("multi_polygon"));
-        assertSame(GeometryType.MULTI_POLYGON, 
GeometryType.forName("MULTIPOLYGON"));
-        assertSame(GeometryType.GEOMETRY_COLLECTION, 
GeometryType.forName("GEOMETRY_COLLECTION"));
-        assertSame(GeometryType.GEOMETRY_COLLECTION, 
GeometryType.forName("GeomCollection"));
+        assertSame(GeometryType.MULTIPOLYGON, 
GeometryType.forName("multi_Polygon"));
+        assertSame(GeometryType.MULTIPOLYGON, 
GeometryType.forName("MULTIPOLYGON"));
+        assertSame(GeometryType.GEOMETRYCOLLECTION, 
GeometryType.forName("GEOMETRY_COLLECTION"));
+        assertSame(GeometryType.GEOMETRYCOLLECTION, 
GeometryType.forName("GeomCollection"));
     }
 }

Reply via email to