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 aa810757115aaf211e7e2b0442752515894a5c90
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Tue Sep 26 10:42:49 2023 +0200

    Avoid a direct dependencies of metadata `Extents` class toward referencing 
interfaces.
---
 .../apache/sis/metadata/iso/extent/Extents.java    | 57 +++++++++-------------
 .../main/org/apache/sis/referencing/CRS.java       | 13 ++++-
 2 files changed, 34 insertions(+), 36 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/extent/Extents.java
 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/extent/Extents.java
index f1c9cec939..6859de279e 100644
--- 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/extent/Extents.java
+++ 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/extent/Extents.java
@@ -24,13 +24,16 @@ import java.util.Set;
 import java.util.LinkedHashSet;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.stream.Stream;
 import java.util.function.Function;
 import java.util.function.BiConsumer;
+import java.util.Optional;
 import javax.measure.Unit;
 import org.opengis.geometry.Envelope;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.geometry.Geometry;
 import org.opengis.temporal.TemporalPrimitive;
+import org.opengis.geometry.MismatchedReferenceSystemException;
 import org.opengis.metadata.Metadata;
 import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.extent.VerticalExtent;
@@ -48,6 +51,7 @@ import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.datum.VerticalDatum;
 import org.opengis.referencing.datum.VerticalDatumType;
 import org.opengis.referencing.operation.TransformException;
+import org.opengis.referencing.operation.CoordinateOperation;
 import org.apache.sis.metadata.InvalidMetadataException;
 import org.apache.sis.metadata.internal.ReferencingServices;
 import org.apache.sis.metadata.iso.ISOMetadata;
@@ -67,12 +71,6 @@ import static 
org.apache.sis.util.collection.Containers.isNullOrEmpty;
 import static org.apache.sis.util.internal.CollectionsExt.nonNull;
 import static 
org.apache.sis.metadata.internal.ReferencingServices.AUTHALIC_RADIUS;
 
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import java.util.Optional;
-import org.opengis.referencing.ObjectDomain;
-import org.opengis.geometry.MismatchedReferenceSystemException;
-import org.opengis.referencing.operation.CoordinateOperation;
-
 
 /**
  * Convenience static methods for extracting information from {@link Extent} 
or {@link Metadata} objects.
@@ -209,43 +207,34 @@ public final class Extents extends Static {
     }
 
     /**
-     * Returns a single geographic bounding box for the given domains of 
validity.
-     * For each domain, the bounding box is fetched with {@link 
#getGeographicBoundingBox(Extent)}.
-     * If more than one geographic domain of validity is found, this method 
computes their union.
+     * Returns a single geographic bounding box for the given extents.
+     * For each extent, the bounding box is fetched with {@link 
#getGeographicBoundingBox(Extent)}.
+     * If more than one geographic bound is found, this method computes their 
union.
      *
-     * <p>This is a convenience method for fetching the domain of validity of 
{@link Datum},
-     * {@link CoordinateReferenceSystem} or {@link CoordinateOperation} 
objects.</p>
+     * <p>This is a convenience method for fetching the domain of validity of
+     * {@link org.opengis.referencing.datum.Datum},
+     * {@link org.opengis.referencing.crs.CoordinateReferenceSystem} or
+     * {@link org.opengis.referencing.operation.CoordinateOperation} 
objects.</p>
      *
-     * @param  domains  the domains of validity for which to get a single 
geographic bounding box, or {@code null}.
-     * @return the union of all geographic bounding boxes found in all domains 
of validity.
+     * @param  extents  the extents for which to get a single geographic 
bounding box.
+     * @return the union of all geographic bounding boxes found in all extents.
      * @throws InvalidMetadataException if an envelope cannot be transformed 
to a geographic bounding box.
      *
-     * @see CoordinateReferenceSystem#getDomains()
+     * @see org.opengis.referencing.crs.CoordinateReferenceSystem#getDomains()
      * @see 
org.apache.sis.referencing.CRS#getDomainOfValidity(CoordinateReferenceSystem)
      *
      * @since 1.4
      */
-    public static Optional<GeographicBoundingBox> 
getGeographicBoundingBox(final Iterable<? extends ObjectDomain> domains) {
-        if (domains != null) {
-            Extents m = null;
-            for (final ObjectDomain domain : domains) {
-                final Extent extent = domain.getDomainOfValidity();
-                if (extent != null) {
-                    if (m == null) {
-                        m = new Extents();
-                    }
-                    try {
-                        m.addHorizontal(extent);
-                    } catch (TransformException e) {
-                        throw new 
InvalidMetadataException(Errors.format(Errors.Keys.CanNotTransformEnvelope), e);
-                    }
-                }
-            }
-            if (m != null) {
-                return Optional.ofNullable(m.bounds);
+    public static Optional<GeographicBoundingBox> 
getGeographicBoundingBox(final Stream<? extends Extent> extents) {
+        final Extents m = new Extents();
+        extents.forEach((extent) -> {
+            if (extent != null) try {
+                m.addHorizontal(extent);
+            } catch (TransformException e) {
+                throw new 
InvalidMetadataException(Errors.format(Errors.Keys.CanNotTransformEnvelope), e);
             }
-        }
-        return Optional.empty();
+        });
+        return Optional.ofNullable(m.bounds);
     }
 
     /**
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CRS.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CRS.java
index e872936e19..819133b88d 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CRS.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/CRS.java
@@ -19,6 +19,7 @@ package org.apache.sis.referencing;
 import java.util.Map;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Optional;
 import java.util.logging.Filter;
 import java.util.logging.Logger;
 import java.util.logging.LogRecord;
@@ -775,7 +776,7 @@ public final class CRS extends Static {
         if (operation == null) {
             return null;
         }
-        return 
Extents.getGeographicBoundingBox(operation.getDomains()).orElseGet(
+        return getDomains(operation).orElseGet(
                 () -> 
Extents.intersection(getGeographicBoundingBox(operation.getSourceCRS()),
                                            
getGeographicBoundingBox(operation.getTargetCRS())));
     }
@@ -797,7 +798,15 @@ public final class CRS extends Static {
      */
     @OptionalCandidate
     public static GeographicBoundingBox getGeographicBoundingBox(final 
CoordinateReferenceSystem crs) {
-        return (crs != null) ? 
Extents.getGeographicBoundingBox(crs.getDomains()).orElse(null) : null;
+        return (crs != null) ? getDomains(crs).orElse(null) : null;
+    }
+
+    /**
+     * Returns the geographic bounding box computed from the domain of the 
given object. This method may be renamed and
+     * refactored as a replacement of {@link 
#getGeographicBoundingBox(CoordinateReferenceSystem)} in a future version.
+     */
+    private static Optional<GeographicBoundingBox> getDomains(final 
IdentifiedObject object) {
+        return 
Extents.getGeographicBoundingBox(object.getDomains().stream().map(ObjectDomain::getDomainOfValidity));
     }
 
     /**

Reply via email to