sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Rename Features.castOrUnwrap(IdentifiedType) as Features.toAttribute(IdentifiedType) and use it where appropriate.
Date Fri, 10 Jan 2020 18:18:55 GMT
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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new b9bfce3  Rename Features.castOrUnwrap(IdentifiedType) as Features.toAttribute(IdentifiedType)
and use it where appropriate.
b9bfce3 is described below

commit b9bfce351b880e387a335f41763d7750f351e4f6
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Jan 10 19:17:38 2020 +0100

    Rename Features.castOrUnwrap(IdentifiedType) as Features.toAttribute(IdentifiedType) and
use it where appropriate.
---
 .../org/apache/sis/feature/EnvelopeOperation.java  | 21 ++++++++-----------
 .../main/java/org/apache/sis/feature/Features.java |  2 +-
 .../java/org/apache/sis/filter/DefaultBBOX.java    |  2 +-
 .../sis/internal/feature/AttributeConvention.java  | 24 ++++++++++------------
 .../filter/sqlmm/AbstractSpatialFunction.java      | 16 +++++++--------
 .../sis/internal/filter/sqlmm/ST_Envelope.java     |  2 +-
 6 files changed, 31 insertions(+), 36 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/EnvelopeOperation.java
b/core/sis-feature/src/main/java/org/apache/sis/feature/EnvelopeOperation.java
index 8e49d8c..13cab73 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/feature/EnvelopeOperation.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/feature/EnvelopeOperation.java
@@ -21,6 +21,7 @@ import java.util.Set;
 import java.util.Map;
 import java.util.LinkedHashMap;
 import java.util.Objects;
+import java.util.Optional;
 import org.opengis.util.GenericName;
 import org.opengis.util.FactoryException;
 import org.opengis.geometry.Envelope;
@@ -43,7 +44,6 @@ import org.opengis.feature.Attribute;
 import org.opengis.feature.AttributeType;
 import org.opengis.feature.Feature;
 import org.opengis.feature.IdentifiedType;
-import org.opengis.feature.Operation;
 import org.opengis.feature.Property;
 import org.opengis.feature.PropertyType;
 
@@ -138,8 +138,9 @@ final class EnvelopeOperation extends AbstractOperation {
          */
         boolean characterizedByCRS = false;
         final Map<String,CoordinateReferenceSystem> names = new LinkedHashMap<>(4);
-        for (IdentifiedType property : geometryAttributes) {
-            if (AttributeConvention.isGeometryAttribute(property)) {
+        for (final IdentifiedType property : geometryAttributes) {
+            final Optional<AttributeType<?>> at = Features.toAttribute(property);
+            if (at.isPresent() && Geometries.isKnownType(at.get().getValueClass()))
{
                 final GenericName name = property.getName();
                 final String attributeName = (property instanceof LinkOperation)
                                              ? ((LinkOperation) property).referentName :
name.toString();
@@ -148,18 +149,14 @@ final class EnvelopeOperation extends AbstractOperation {
                     defaultGeometry = attributeName;
                 }
                 CoordinateReferenceSystem attributeCRS = null;
-                while (property instanceof Operation) {
-                    property = ((Operation) property).getResult();
-                }
                 /*
-                 * At this point 'property' is an attribute, otherwise isGeometryAttribute(property)
would have
-                 * returned false. Set 'characterizedByCRS' to true if we find at least one
attribute which may
-                 * have the "CRS" characteristic. Note that we can not rely on 'attributeCRS'
being non-null
+                 * Set `characterizedByCRS` to true if we find at least one attribute which
may have the
+                 * "CRS" characteristic. Note that we can not rely on `attributeCRS` being
non-null
                  * because an attribute may be characterized by a CRS without providing default
CRS.
                  */
-                final AttributeType<?> at = ((AttributeType<?>) property).characteristics().get(characteristicName);
-                if (at != null && CoordinateReferenceSystem.class.isAssignableFrom(at.getValueClass()))
{
-                    attributeCRS = (CoordinateReferenceSystem) at.getDefaultValue();    
         // May still null.
+                final AttributeType<?> ct = at.get().characteristics().get(characteristicName);
+                if (ct != null && CoordinateReferenceSystem.class.isAssignableFrom(ct.getValueClass()))
{
+                    attributeCRS = (CoordinateReferenceSystem) ct.getDefaultValue();    
         // May still null.
                     if (crs == null && isDefault) {
                         crs = attributeCRS;
                     }
diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java b/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java
index b818a22..16f1b7d 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java
@@ -140,7 +140,7 @@ public final class Features extends Static {
      *
      * @since 1.1
      */
-    public static Optional<AttributeType<?>> castOrUnwrap(IdentifiedType type)
{
+    public static Optional<AttributeType<?>> toAttribute(IdentifiedType type)
{
         if (!(type instanceof AttributeType<?>)) {
             if (!(type instanceof Operation)) {
                 return Optional.empty();
diff --git a/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultBBOX.java b/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultBBOX.java
index e3127b4..e0789c8 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultBBOX.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultBBOX.java
@@ -145,7 +145,7 @@ final class DefaultBBOX extends SpatialFunction implements BBOX, Serializable
{
             return type.getProperties(true)
                     .stream()
                     .filter(p
-                            -> Features.castOrUnwrap(p)
+                            -> Features.toAttribute(p)
                             .map(AttributeType::getValueClass)
                             .filter(Geometries::isKnownType)
                             .isPresent()
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/AttributeConvention.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/AttributeConvention.java
index 8eeeb3d..f2400a3 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/AttributeConvention.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/AttributeConvention.java
@@ -16,12 +16,14 @@
  */
 package org.apache.sis.internal.feature;
 
+import java.util.Optional;
 import org.opengis.util.LocalName;
 import org.opengis.util.ScopedName;
 import org.opengis.util.GenericName;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.util.iso.Names;
 import org.apache.sis.util.Static;
+import org.apache.sis.feature.Features;
 
 // Branch-dependent imports
 import org.opengis.feature.Feature;
@@ -67,7 +69,7 @@ import org.opengis.feature.PropertyNotFoundException;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   0.7
  * @module
  */
@@ -247,11 +249,9 @@ public final class AttributeConvention extends Static {
      *
      * @see #GEOMETRY_PROPERTY
      */
-    public static boolean isGeometryAttribute(IdentifiedType type) {
-        while (type instanceof Operation) {
-            type = ((Operation) type).getResult();
-        }
-        return (type instanceof AttributeType<?>) && Geometries.isKnownType(((AttributeType<?>)
type).getValueClass());
+    public static boolean isGeometryAttribute(final IdentifiedType type) {
+        final Optional<AttributeType<?>> at = Features.toAttribute(type);
+        return at.isPresent() && Geometries.isKnownType(at.get().getValueClass());
     }
 
     /**
@@ -356,13 +356,11 @@ public final class AttributeConvention extends Static {
      * @return {@code true} if a characteristic of the given name exists and has values assignable
to the given class.
      */
     private static boolean hasCharacteristic(IdentifiedType type, final String name, final
Class<?> valueClass) {
-        while (type instanceof Operation) {
-            type = ((Operation) type).getResult();
-        }
-        if (type instanceof AttributeType<?>) {
-            final AttributeType<?> at = ((AttributeType<?>) type).characteristics().get(name);
-            if (at != null) {
-                return valueClass.isAssignableFrom(at.getValueClass());
+        final Optional<AttributeType<?>> at = Features.toAttribute(type);
+        if (at.isPresent()) {
+            final AttributeType<?> ct = at.get().characteristics().get(name);
+            if (ct != null) {
+                return valueClass.isAssignableFrom(ct.getValueClass());
             }
         }
         return false;
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/AbstractSpatialFunction.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/AbstractSpatialFunction.java
index daa3bad..bf6eddf 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/AbstractSpatialFunction.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/AbstractSpatialFunction.java
@@ -17,6 +17,7 @@
 package org.apache.sis.internal.filter.sqlmm;
 
 import java.util.Map;
+import java.util.Optional;
 import org.apache.sis.feature.Features;
 import org.apache.sis.feature.builder.FeatureTypeBuilder;
 import org.apache.sis.internal.feature.AttributeConvention;
@@ -81,16 +82,15 @@ public abstract class AbstractSpatialFunction extends NamedFunction implements
F
     }
 
     protected static CoordinateReferenceSystem expectedCrs(FeatureType type, Expression exp)
{
-
         final PropertyType expressionType = FeatureExpression.expectedType(exp, type, new
FeatureTypeBuilder()).build();
-        final AttributeType<?> attr = Features.castOrUnwrap(expressionType).orElse(null);
-        if (attr == null) {
-            return null;
+        final Optional<AttributeType<?>> attr = Features.toAttribute(expressionType);
+        if (attr.isPresent()) {
+            final AttributeType<CoordinateReferenceSystem> crsCharacteristic = Features.cast(
+                    attr.get().characteristics().get(AttributeConvention.CRS_CHARACTERISTIC),
+                    CoordinateReferenceSystem.class);
+            return crsCharacteristic == null ? null : crsCharacteristic.getDefaultValue();
         }
-
-        final AttributeType<CoordinateReferenceSystem> crsCharacteristic = (AttributeType<CoordinateReferenceSystem>)
-                attr.characteristics().get(AttributeConvention.CRS_CHARACTERISTIC);
-        return crsCharacteristic == null ? null : crsCharacteristic.getDefaultValue();
+        return null;
     }
 
     protected static void copyCrs(Geometry source, Geometry target) {
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_Envelope.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_Envelope.java
index d4d4e08..cab9c4b 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_Envelope.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/filter/sqlmm/ST_Envelope.java
@@ -142,7 +142,7 @@ public class ST_Envelope extends NamedFunction implements FeatureExpression
{
         @Override
         public PropertyType type(FeatureType target) {
             final PropertyType expressionType = source.expectedType(target, new FeatureTypeBuilder()).build();
-            final AttributeType<?> attr = Features.castOrUnwrap(expressionType)
+            final AttributeType<?> attr = Features.toAttribute(expressionType)
                     .orElseThrow(() -> new UnsupportedOperationException("Cannot evaluate
given expression because it does not create attribute values"));
             // If given expression evaluates directly to a bbox, there's no need for a conversion
step.
             if (Envelope.class.isAssignableFrom(attr.getValueClass())) {


Mime
View raw message