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 3d5020c294 Replace the `Optional` in `GridExtent.intersect(…)`  by 
`DisjointExtentException` for more consistency with other API doing similar 
work. It allows us to provide more helpful error message.
3d5020c294 is described below

commit 3d5020c294a040e46581a51d15a78b80e7db7f2f
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Fri Dec 9 11:00:42 2022 +0100

    Replace the `Optional` in `GridExtent.intersect(…)`  by 
`DisjointExtentException`
    for more consistency with other API doing similar work.
    It allows us to provide more helpful error message.
---
 .../apache/sis/coverage/grid/DisjointExtentException.java  |  2 +-
 .../java/org/apache/sis/coverage/grid/GridDerivation.java  |  6 +++---
 .../main/java/org/apache/sis/coverage/grid/GridExtent.java |  7 ++++---
 .../java/org/apache/sis/internal/feature/Resources.java    |  6 +++---
 .../org/apache/sis/internal/feature/Resources.properties   |  2 +-
 .../apache/sis/internal/feature/Resources_fr.properties    |  2 +-
 .../java/org/apache/sis/coverage/grid/GridExtentTest.java  | 14 ++++++++++----
 7 files changed, 23 insertions(+), 16 deletions(-)

diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/DisjointExtentException.java
 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/DisjointExtentException.java
index aebaa23bd9..6e51ff33fd 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/DisjointExtentException.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/DisjointExtentException.java
@@ -72,7 +72,7 @@ public class DisjointExtentException extends 
IllegalGridGeometryException {
      * @param upper  the upper bound specified by user, which is invalid.
      */
     DisjointExtentException(final Object dim, final long min, final long max, 
final long lower, final long upper) {
-        super(Resources.format(Resources.Keys.GridEnvelopeOutsideCoverage_5, 
new Object[] {dim, min, max, lower, upper}));
+        super(Resources.format(Resources.Keys.GridExtentsAreDisjoint_5, new 
Object[] {dim, min, max, lower, upper}));
     }
 
     /**
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
index 7364fbb9ef..26ab0221c2 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
@@ -482,7 +482,7 @@ public class GridDerivation {
         final double[] scales;
         if (areaOfInterest.isExtentOnly()) {
             if (baseExtent != null) {
-                baseExtent = 
baseExtent.intersect(areaOfInterest.extent).orElseThrow(DisjointExtentException::new);
+                baseExtent = baseExtent.intersect(areaOfInterest.extent);
                 subGridSetter = "subgrid";
             }
             scales = areaOfInterest.resolution;
@@ -879,7 +879,7 @@ public class GridDerivation {
             }
         }
         if (areaOfInterest != null && baseExtent != null) {
-            baseExtent = 
baseExtent.intersect(areaOfInterest).orElseThrow(DisjointExtentException::new);
+            baseExtent = baseExtent.intersect(areaOfInterest);
             subGridSetter = "subgrid";
         }
         if (subsampling == null) {
@@ -1175,7 +1175,7 @@ public class GridDerivation {
                     resized = resized.forChunkSize(chunkSize);
                 }
                 if (clipping == GridClippingMode.STRICT) {
-                    resized = 
resized.intersect(base.extent).orElseThrow(DisjointExtentException::new);
+                    resized = resized.intersect(base.extent);
                 }
                 if (!resized.equals(baseExtent)) {
                     baseExtent = resized;
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
index ea210a710d..c9a7e25070 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
@@ -1759,11 +1759,12 @@ public class GridExtent implements GridEnvelope, 
LenientComparable, Serializable
      * @return the intersection result. May be one of the existing instances.
      * @throws MismatchedDimensionException if the two extents do not have the 
same number of dimensions.
      * @throws IllegalArgumentException if axis types are specified but 
inconsistent in at least one dimension.
+     * @throws DisjointExtentException if the given extent does not intersect 
this extent.
      *
      * @since 1.3
      */
-    public Optional<GridExtent> intersect(final GridExtent other) {
-        return Optional.ofNullable(combine(other, false));
+    public GridExtent intersect(final GridExtent other) {
+        return combine(other, false);
     }
 
     /**
@@ -1819,7 +1820,7 @@ public class GridExtent implements GridEnvelope, 
LenientComparable, Serializable
         if (!union) {
             for (i=0; i<m; i++) {
                 if (clipped[i] > clipped[i+m]) {
-                    return null;                    // No intersection.
+                    throw new DisjointExtentException(this, other, i);
                 }
             }
         }
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources.java 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources.java
index af18fe363f..f643c483cd 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources.java
@@ -181,10 +181,10 @@ public final class Resources extends 
IndexedResourceBundle {
         public static final short GridEnvelopeMustBeNDimensional_1 = 22;
 
         /**
-         * Envelope is outside grid coverage. Indices [{3,number} … 
{4,number}] in dimension {0} do not
-         * intersect the [{1,number} … {2,number}] grid extent.
+         * The specified grid extent is outside the domain. Indices 
[{3,number} … {4,number}] specified
+         * in dimension {0} do not intersect the [{1,number} … {2,number}] 
grid extent.
          */
-        public static final short GridEnvelopeOutsideCoverage_5 = 23;
+        public static final short GridExtentsAreDisjoint_5 = 23;
 
         /**
          * Sample value range {1} for “{0}” category is illegal.
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources.properties
 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources.properties
index 181596a444..3c0eb6a938 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources.properties
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources.properties
@@ -43,7 +43,7 @@ EmptyImage                        = Image has zero pixel.
 EmptyTileOrImageRegion            = Empty tile or image region.
 GridCoordinateOutsideCoverage_4   = Indices ({3}) are outside grid coverage. 
The value in dimension {0} shall be between {1,number} and {2,number} inclusive.
 GridEnvelopeMustBeNDimensional_1  = The grid envelope must have at least {0} 
dimensions.
-GridEnvelopeOutsideCoverage_5     = Envelope is outside grid coverage. Indices 
[{3,number} \u2026 {4,number}] in dimension {0} do not intersect the 
[{1,number} \u2026 {2,number}] grid extent.
+GridExtentsAreDisjoint_5          = The specified grid extent is outside the 
domain. Indices [{3,number} \u2026 {4,number}] specified in dimension {0} do 
not intersect the [{1,number} \u2026 {2,number}] grid extent.
 IllegalCategoryRange_2            = Sample value range {1} for \u201c{0}\u201d 
category is illegal.
 IllegalCharacteristicsType_3      = Expected an instance of \u2018{1}\u2019 
for the \u201c{0}\u201d characteristics, but got an instance of \u2018{2}\u2019.
 IllegalFeatureType_3              = Association \u201c{0}\u201d does not 
accept features of type \u2018{2}\u2019. Expected an instance of 
\u2018{1}\u2019 or derived type.
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources_fr.properties
 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources_fr.properties
index 951a7ad66b..0ce750b962 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources_fr.properties
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Resources_fr.properties
@@ -48,7 +48,7 @@ EmptyImage                        = L\u2019image a z\u00e9ro 
pixel.
 EmptyTileOrImageRegion            = La tuile ou la r\u00e9gion de l\u2019image 
est vide.
 GridCoordinateOutsideCoverage_4   = Les indices ({3}) sont en dehors du 
domaine de la grille. La valeur dans la dimension {0} doit \u00eatre entre 
{1,number} et {2,number} inclusivement.
 GridEnvelopeMustBeNDimensional_1  = L\u2019enveloppe de la grille doit avoir 
au moins {0} dimensions.
-GridEnvelopeOutsideCoverage_5     = L\u2019enveloppe est en dehors du domaine 
de la grille. Les indices [{3,number} \u2026 {4,number}] dans la dimension {0} 
n\u2019interceptent pas l\u2019\u00e9tendue [{1,number} \u2026 {2,number}] de 
la grille.
+GridExtentsAreDisjoint_5          = L\u2019\u00e9tendue de grille 
sp\u00e9cifi\u00e9e est en dehors du domaine. Les indices [{3,number} \u2026 
{4,number}] qui ont \u00e9t\u00e9 sp\u00e9cifi\u00e9es dans la dimension {0} 
n\u2019interceptent pas l\u2019\u00e9tendue [{1,number} \u2026 {2,number}] de 
la grille.
 IllegalCategoryRange_2            = La plage de valeurs {1} pour la 
cat\u00e9gorie \u00ab\u202f{0}\u202f\u00bb est ill\u00e9gale.
 IllegalCharacteristicsType_3      = Une instance \u2018{1}\u2019 \u00e9tait 
attendue pour la caract\u00e9ristique \u00ab\u202f{0}\u202f\u00bb, mais la 
valeur donn\u00e9e est une instance de \u2018{2}\u2019.
 IllegalFeatureType_3              = L\u2019association 
\u00ab\u202f{0}\u202f\u00bb n\u2019accepte pas les entit\u00e9s de type 
\u2018{2}\u2019. Une instance de \u2018{1}\u2019 ou d\u2019un type 
d\u00e9riv\u00e9 \u00e9tait attendue.
diff --git 
a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
 
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
index cb71f51b95..30c198236c 100644
--- 
a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
+++ 
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
@@ -277,12 +277,18 @@ public final strictfp class GridExtentTest extends 
TestCase {
     @Test
     public void testIntersect() {
         final GridExtent domain = createOther();
-        final GridExtent extent = create3D().intersect(domain).get();
+        final GridExtent extent = create3D().intersect(domain);
         assertExtentEquals(extent, 0, 150, 399);
         assertExtentEquals(extent, 1, 220, 799);
         assertExtentEquals(extent, 2, 40,  46);
-        assertSame(extent.intersect(domain).get(), extent);
-        assertFalse(extent.intersect(domain.translate(1000)).isPresent());
+        assertSame(extent.intersect(domain), extent);
+        final GridExtent disjoint = domain.translate(0, 1000);
+        try {
+            extent.intersect(disjoint);
+            fail("Expected DisjointExtentException.");
+        } catch (DisjointExtentException e) {
+            assertNotNull(e.getMessage());
+        }
     }
 
     /**
@@ -309,7 +315,7 @@ public final strictfp class GridExtentTest extends TestCase 
{
                 new DimensionNameType[] {DimensionNameType.COLUMN, 
DimensionNameType.TRACK, DimensionNameType.TIME},
                 new long[] {100, 200, 40}, new long[] {500, 800, 50}, false);
         try {
-            domain.intersect(other).get();
+            domain.intersect(other);
             fail("Should not be allowed");
         } catch (IllegalArgumentException e) {
             assertNotNull(e.getMessage());

Reply via email to