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: PixelIteration.getIterationOrder() is Optional.
Date Wed, 05 Jun 2019 10:25:56 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 b942045  PixelIteration.getIterationOrder() is Optional.
b942045 is described below

commit b942045bff0c5342df973813bfc46bf67b70a750
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jun 5 12:14:21 2019 +0200

    PixelIteration.getIterationOrder() is Optional.
---
 .../java/org/apache/sis/image/DefaultIterator.java |  7 ++--
 .../java/org/apache/sis/image/LinearIterator.java  |  5 +--
 .../java/org/apache/sis/image/PixelIterator.java   |  7 ++--
 .../org/apache/sis/image/DefaultIteratorTest.java  | 42 +++++++++++++---------
 .../org/apache/sis/image/LinearIteratorTest.java   |  2 +-
 5 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java b/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java
index 41ad3c8..d4f7b79 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.image;
 
+import java.util.Optional;
 import java.awt.Point;
 import java.awt.Dimension;
 import java.awt.Rectangle;
@@ -149,11 +150,11 @@ class DefaultIterator extends WritablePixelIterator {
      * Returns the order in which pixels are traversed.
      */
     @Override
-    public SequenceType getIterationOrder() {
+    public Optional<SequenceType> getIterationOrder() {
         if (image == null || (tileUpperX - tileLowerX) <=1 && (tileUpperY - tileLowerY)
<= 1) {
-            return SequenceType.LINEAR;
+            return Optional.of(SequenceType.LINEAR);
         } else {
-            return null;            // Undefined order.
+            return Optional.empty();                // Undefined order.
         }
     }
 
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/LinearIterator.java b/core/sis-feature/src/main/java/org/apache/sis/image/LinearIterator.java
index 0a1bd64..7eb1688 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/LinearIterator.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/LinearIterator.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.image;
 
+import java.util.Optional;
 import java.awt.Dimension;
 import java.awt.Rectangle;
 import java.awt.image.Raster;
@@ -75,8 +76,8 @@ final class LinearIterator extends DefaultIterator {
      * Returns the order in which pixels are traversed.
      */
     @Override
-    public SequenceType getIterationOrder() {
-        return SequenceType.LINEAR;
+    public Optional<SequenceType> getIterationOrder() {
+        return Optional.of(SequenceType.LINEAR);
     }
 
     /**
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java b/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
index e85c9ba..8b7a793 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
@@ -17,6 +17,7 @@
 package org.apache.sis.image;
 
 import java.util.Arrays;
+import java.util.Optional;
 import java.nio.Buffer;
 import java.awt.Point;
 import java.awt.Dimension;
@@ -474,11 +475,11 @@ public abstract class PixelIterator {
     /**
      * Returns the order in which pixels are traversed. {@link SequenceType#LINEAR} means
that pixels on the first
      * row are traversed from left to right, then pixels on the second row from left to right,
<i>etc.</i>
-     * A {@code null} value means that the iteration order is unspecified.
+     * An empty value means that the iteration order is unspecified.
      *
-     * @return order in which pixels are traversed, or {@code null} if unspecified.
+     * @return order in which pixels are traversed.
      */
-    public abstract SequenceType getIterationOrder();
+    public abstract Optional<SequenceType> getIterationOrder();
 
     /**
      * Returns the number of bands (samples per pixel) in the image or raster.
diff --git a/core/sis-feature/src/test/java/org/apache/sis/image/DefaultIteratorTest.java
b/core/sis-feature/src/test/java/org/apache/sis/image/DefaultIteratorTest.java
index 825307c..724defe 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/image/DefaultIteratorTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/image/DefaultIteratorTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.image;
 
+import java.util.Optional;
 import java.awt.Point;
 import java.awt.Dimension;
 import java.awt.Rectangle;
@@ -305,6 +306,15 @@ public strictfp class DefaultIteratorTest extends TestCase {
     }
 
     /**
+     * Verifies that actual iteration order is equals to the expected one.
+     *
+     * @param  singleTile  {@code true} if iteration occurs in a single tile, or {@code false} for
the whole image.
+     */
+    private void verifyIterationOrder(final boolean singleTile) {
+        assertEquals("getIterationOrder()", Optional.ofNullable(getIterationOrder(singleTile)),
iterator.getIterationOrder());
+    }
+
+    /**
      * Creates a {@code PixelIterator} for a sub-area of given raster.
      * The iterator shall be assigned to the {@link #iterator} field.
      *
@@ -316,7 +326,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
      */
     void createPixelIterator(WritableRaster raster, Rectangle subArea) {
         iterator = new DefaultIterator(raster, isWritable ? raster : null, subArea, null);
-        assertEquals("getIterationOrder()", SequenceType.LINEAR, iterator.getIterationOrder());
+        assertEquals("getIterationOrder()", SequenceType.LINEAR, iterator.getIterationOrder().get());
         assertEquals("isWritable", isWritable, iterator.isWritable());
     }
 
@@ -626,7 +636,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         tileHeight =   5;
         numBands   =   3;
         createPixelIterator(createImage(null), null);
-        assertEquals("getIterationOrder()", getIterationOrder(false), iterator.getIterationOrder());
+        verifyIterationOrder(false);
         verifyIteration(false);
     }
 
@@ -646,7 +656,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         tileHeight =   5;
         numBands   =   2;
         createPixelIterator(createImage(null), null);
-        assertEquals("getIterationOrder()", getIterationOrder(false), iterator.getIterationOrder());
+        verifyIterationOrder(false);
         verifyIteration(false);
 
         iterator.rewind();
@@ -673,7 +683,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Rectangle subArea = new Rectangle(-10, -20, 8, 28);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(true), iterator.getIterationOrder());
+        verifyIterationOrder(true);
         verifyIteration(false);
     }
 
@@ -697,7 +707,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Rectangle subArea = new Rectangle(45, -20, 30, 29);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(true), iterator.getIterationOrder());
+        verifyIterationOrder(true);
         verifyIteration(false);
     }
 
@@ -722,7 +732,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Rectangle subArea = new Rectangle(68, 5, 4, 4);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(true), iterator.getIterationOrder());
+        verifyIterationOrder(true);
         verifyIteration(false);
     }
 
@@ -747,7 +757,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Rectangle subArea = new Rectangle(0, 0, 9, 50);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(true), iterator.getIterationOrder());
+        verifyIterationOrder(true);
         verifyIteration(false);
     }
 
@@ -770,7 +780,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Rectangle subArea = new Rectangle(6, 20, 4, 5);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(true), iterator.getIterationOrder());
+        verifyIterationOrder(true);
         verifyIteration(false);
     }
 
@@ -794,7 +804,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Rectangle subArea = new Rectangle(-10, -5, 25, 22);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(false), iterator.getIterationOrder());
+        verifyIterationOrder(false);
         verifyIteration(false);
     }
 
@@ -818,7 +828,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Rectangle subArea = new Rectangle(27, -20, 30, 37);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(false), iterator.getIterationOrder());
+        verifyIterationOrder(false);
         verifyIteration(false);
     }
 
@@ -842,7 +852,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Rectangle subArea = new Rectangle(36, 8, 12, 20);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(false), iterator.getIterationOrder());
+        verifyIterationOrder(false);
         verifyIteration(false);
     }
 
@@ -866,7 +876,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Rectangle subArea = new Rectangle(-20, -1, 30, 20);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(false), iterator.getIterationOrder());
+        verifyIterationOrder(false);
         verifyIteration(false);
     }
 
@@ -889,7 +899,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Rectangle subArea = new Rectangle(20, 10, 30, 25);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(false), iterator.getIterationOrder());
+        verifyIterationOrder(false);
         verifyIteration(false);
     }
 
@@ -911,7 +921,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Rectangle subArea = new Rectangle(-10, -10, 150, 80);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(false), iterator.getIterationOrder());
+        verifyIterationOrder(false);
         verifyIteration(false);
     }
 
@@ -1176,7 +1186,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Dimension window = new Dimension(3, 4);
         createWindowIterator(createImage(null), window);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(true), iterator.getIterationOrder());
+        verifyIterationOrder(true);
         verifyWindow(window);
     }
 
@@ -1198,7 +1208,7 @@ public strictfp class DefaultIteratorTest extends TestCase {
         final Dimension window = new Dimension(2, 3);
         createWindowIterator(createImage(null), window);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
-        assertEquals("getIterationOrder()", getIterationOrder(false), iterator.getIterationOrder());
+        verifyIterationOrder(false);
         verifyWindow(window);
     }
 
diff --git a/core/sis-feature/src/test/java/org/apache/sis/image/LinearIteratorTest.java b/core/sis-feature/src/test/java/org/apache/sis/image/LinearIteratorTest.java
index 99f9f93..de7a87d 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/image/LinearIteratorTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/image/LinearIteratorTest.java
@@ -98,7 +98,7 @@ public final strictfp class LinearIteratorTest extends DefaultIteratorTest
{
     @Override
     void createPixelIterator(WritableRaster raster, Rectangle subArea) {
         iterator = new LinearIterator(raster, isWritable ? raster : null, subArea, null);
-        assertEquals("getIterationOrder()", SequenceType.LINEAR, iterator.getIterationOrder());
+        assertEquals("getIterationOrder()", SequenceType.LINEAR, iterator.getIterationOrder().get());
         assertEquals("isWritable", isWritable, iterator.isWritable());
     }
 


Mime
View raw message