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 7e3132901f When parsing GCOM-C files, accept `Image_start_time` 
attribute if `Scane_start_time` is not present.
7e3132901f is described below

commit 7e3132901f5201fa798e068feb1fda3ce58c89b9
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Tue Sep 20 18:17:14 2022 +0200

    When parsing GCOM-C files, accept `Image_start_time` attribute if 
`Scane_start_time` is not present.
---
 .../apache/sis/internal/earth/netcdf/GCOM_C.java   | 18 +++++++++---
 .../apache/sis/internal/earth/netcdf/GCOM_W.java   | 15 ++++++----
 .../org/apache/sis/internal/netcdf/Convention.java | 19 +++++++------
 .../sis/internal/netcdf/impl/ChannelDecoder.java   | 32 +++++++++++-----------
 .../sis/internal/netcdf/ucar/DecoderWrapper.java   | 22 +++++++--------
 5 files changed, 61 insertions(+), 45 deletions(-)

diff --git 
a/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
 
b/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
index 8ec93cd0b7..8672c85d57 100644
--- 
a/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
+++ 
b/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_C.java
@@ -231,12 +231,22 @@ public final class GCOM_C extends Convention {
      * The given parameter is a name from <cite>CF conventions</cite> or from 
<cite>Attribute Convention for Dataset Discovery
      * (ACDD)</cite>.
      *
-     * @param  name  an attribute name from CF or ACDD convention.
-     * @return the attribute name expected to be found in a netCDF file for 
GCOM-C, or {@code name} if unknown.
+     * @param  name   an attribute name from CF or ACDD convention.
+     * @param  index  index of the element to get from the list of names.
+     * @return the attribute name expected to be found in a netCDF file for 
GCOM-C, or {@code null} if none.
      */
     @Override
-    public String mapAttributeName(final String name) {
-        return ATTRIBUTES.getOrDefault(name, name);
+    public String mapAttributeName(final String name, final int index) {
+        switch (index) {
+            case 0: return name;
+            case 1: return ATTRIBUTES.get(name);
+            case 2: {
+                if (AttributeNames.TIME.MINIMUM.equalsIgnoreCase(name)) return 
"Image_start_time";
+                if (AttributeNames.TIME.MAXIMUM.equalsIgnoreCase(name)) return 
"Image_end_time";
+                break;
+            }
+        }
+        return null;
     }
 
     /**
diff --git 
a/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_W.java
 
b/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_W.java
index 343984e16e..82b485e1a5 100644
--- 
a/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_W.java
+++ 
b/profiles/sis-japan-profile/src/main/java/org/apache/sis/internal/earth/netcdf/GCOM_W.java
@@ -70,7 +70,7 @@ import org.apache.sis.util.CharSequences;
  * </ul>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.3
  *
  * @see <a href="http://global.jaxa.jp/projects/sat/gcom_w/";>SHIZUKU (GCOM-W) 
on JAXA</a>
  * @see <a 
href="https://en.wikipedia.org/wiki/Global_Change_Observation_Mission";>GCOM on 
Wikipedia</a>
@@ -147,12 +147,17 @@ public final class GCOM_W extends Convention {
      * The given parameter is a name from <cite>CF conventions</cite> or from 
<cite>Attribute Convention for Dataset Discovery
      * (ACDD)</cite>.
      *
-     * @param  name  an attribute name from CF or ACDD convention.
-     * @return the attribute name expected to be found in a netCDF file for 
GCOM-W, or {@code name} if unknown.
+     * @param  name   an attribute name from CF or ACDD convention.
+     * @param  index  index of the element to get from the list of names.
+     * @return the attribute name expected to be found in a netCDF file for 
GCOM-W, or {@code null} if none.
      */
     @Override
-    public String mapAttributeName(final String name) {
-        return ATTRIBUTES.getOrDefault(name, name);
+    public String mapAttributeName(final String name, final int index) {
+        switch (index) {
+            case 0:  return name;
+            case 1:  return ATTRIBUTES.get(name);
+            default: return null;
+        }
     }
 
     /**
diff --git 
a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
 
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
index 67ea796b7a..8570cbd890 100644
--- 
a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
+++ 
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Convention.java
@@ -67,7 +67,7 @@ import ucar.nc2.constants.CF;
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Alexis Manin (Geomatys)
- * @version 1.2
+ * @version 1.3
  *
  * @see <a href="https://issues.apache.org/jira/browse/SIS-315";>SIS-315</a>
  *
@@ -192,17 +192,20 @@ public class Convention {
      * The given parameter is a name from <cite>CF conventions</cite> or from 
<cite>Attribute Convention for Dataset Discovery
      * (ACDD)</cite>. Some of those attribute names are listed in the {@link 
org.apache.sis.storage.netcdf.AttributeNames} class.
      *
+     * <p>The returned names are conceptually a list. However instead of 
returning a {@link java.util.List},
+     * this method is invoked repeatedly with increasing index values until 
this method returns {@code null}.
+     * Implementation are encouraged to return the {@code name} argument 
unchanged as the value at index 0.</p>
+     *
      * <p>In current version of netCDF reader, this method is invoked only for 
global attributes,
      * not for the attributes on variables.</p>
      *
-     * <p>The default implementation returns {@code name} unchanged.</p>
-     *
-     * @param  name  an attribute name from CF or ACDD convention.
-     * @return the attribute name expected to be found in a netCDF file 
structured according this {@code Convention}.
-     *         If this convention does not know about attribute of the given 
name, then {@code name} is returned unchanged.
+     * @param  name   an attribute name from CF or ACDD convention.
+     * @param  index  index of the element to get from the list of names.
+     * @return the attribute name expected to be found in a netCDF file 
structured according this {@code Convention},
+     *         or {@code null} if there is no name mapping at the given index.
      */
-    public String mapAttributeName(final String name) {
-        return name;
+    public String mapAttributeName(final String name, final int index) {
+        return (index == 0) ? name : null;
     }
 
     /**
diff --git 
a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
 
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
index 0d3d376cd3..970e7c0016 100644
--- 
a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
+++ 
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
@@ -47,6 +47,7 @@ import org.apache.sis.internal.netcdf.Node;
 import org.apache.sis.internal.netcdf.Grid;
 import org.apache.sis.internal.netcdf.Variable;
 import org.apache.sis.internal.netcdf.Dimension;
+import org.apache.sis.internal.netcdf.Convention;
 import org.apache.sis.internal.netcdf.NamedElement;
 import org.apache.sis.internal.storage.io.ChannelDataInput;
 import org.apache.sis.internal.util.Constants;
@@ -73,7 +74,7 @@ import org.apache.sis.math.Vector;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.2
+ * @version 1.3
  *
  * @see <a 
href="http://portal.opengeospatial.org/files/?artifact_id=43734";>NetCDF Classic 
and 64-bit Offset Format (1.0)</a>
  *
@@ -790,8 +791,15 @@ public final class ChannelDecoder extends Decoder {
      * @see #getAttributeNames()
      */
     private Object findAttribute(final String name) {
-        Object value = attributeMap.get(name);
-        if (value == null && name != null) {
+        if (name == null) {
+            return null;
+        }
+        int index = 0;
+        String mappedName;
+        final Convention convention = convention();
+        while ((mappedName = convention.mapAttributeName(name, index++)) != 
null) {
+            Object value = attributeMap.get(mappedName);
+            if (value != null) return value;
             /*
              * If no value were found for the given name, tries the following 
alternatives:
              *
@@ -802,21 +810,13 @@ public final class ChannelDecoder extends Decoder {
              * Identity comparisons performed between String instances below 
are okay since they
              * are only optimizations for skipping calls to Map.get(Object) in 
common cases.
              */
-            String lower = name.toLowerCase(NAME_LOCALE);
-            if (lower == name || (value = attributeMap.get(lower)) == null) {
-                final String mappedName = convention().mapAttributeName(name);
-                if (mappedName != name) {
-                    value = attributeMap.get(mappedName);
-                    if (value == null) {
-                        lower = name.toLowerCase(NAME_LOCALE);
-                        if (lower != mappedName) {
-                            value = attributeMap.get(lower);
-                        }
-                    }
-                }
+            final String lowerCase = mappedName.toLowerCase(NAME_LOCALE);
+            if (lowerCase != mappedName) {
+                value = attributeMap.get(lowerCase);
+                if (value != null) return value;
             }
         }
-        return value;
+        return null;
     }
 
     /**
diff --git 
a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
 
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
index 634a3937df..99138aef3d 100644
--- 
a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
+++ 
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
@@ -49,6 +49,7 @@ import org.apache.sis.internal.netcdf.Variable;
 import org.apache.sis.internal.netcdf.Dimension;
 import org.apache.sis.internal.netcdf.Node;
 import org.apache.sis.internal.netcdf.Grid;
+import org.apache.sis.internal.netcdf.Convention;
 import org.apache.sis.internal.netcdf.DiscreteSampling;
 import org.apache.sis.setup.GeometryLibrary;
 import org.apache.sis.storage.DataStore;
@@ -257,20 +258,17 @@ public final class DecoderWrapper extends Decoder 
implements CancelTask {
      * @return the attribute, or {@code null} if none.
      */
     private Attribute findAttribute(final Group group, final String name) {
-        Attribute value = (group != null) ? 
group.attributes().findAttributeIgnoreCase(name)
-                                          : 
file.findGlobalAttributeIgnoreCase(name);
-        if (value == null) {
-            final String mappedName = convention().mapAttributeName(name);
-            /*
-             * Identity check between String instances below is okay
-             * since this is only an optimization for a common case.
-             */
-            if (mappedName != name) {
-                value = (group != null) ? 
group.attributes().findAttributeIgnoreCase(mappedName)
-                                        : 
file.findGlobalAttributeIgnoreCase(mappedName);
+        int index = 0;
+        String mappedName;
+        final Convention convention = convention();
+        while ((mappedName = convention.mapAttributeName(name, index++)) != 
null) {
+            Attribute value = (group != null) ? 
group.attributes().findAttributeIgnoreCase(mappedName)
+                                              : 
file.findGlobalAttributeIgnoreCase(mappedName);
+            if (value != null) {
+                return value;
             }
         }
-        return value;
+        return null;
     }
 
     /**

Reply via email to