sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/07: Replace `DataType.ordinal()` by `DataType.toDataBufferType()` for clarity. Various javadoc fixes.
Date Thu, 29 Jul 2021 13:07:17 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

commit 01cd18c065395fd0421893acade7a667def32080
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Jul 23 15:13:56 2021 +0200

    Replace `DataType.ordinal()` by `DataType.toDataBufferType()` for clarity.
    Various javadoc fixes.
---
 .../org/apache/sis/coverage/grid/GridCoverage.java  |  2 +-
 .../main/java/org/apache/sis/image/DataType.java    | 21 +++++++++++++++++----
 .../java/org/apache/sis/image/ImageProcessor.java   |  2 +-
 .../sis/internal/coverage/j2d/RasterFactory.java    |  4 ++--
 .../java/org/apache/sis/image/DataTypeTest.java     | 12 ++++++------
 .../org/apache/sis/storage/geotiff/DataSubset.java  |  8 ++++----
 .../sis/storage/geotiff/ImageFileDirectory.java     |  2 +-
 .../sis/storage/geotiff/SelfConsistencyTest.java    |  2 +-
 .../sis/storage/netcdf/SelfConsistencyTest.java     |  2 +-
 9 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
index e0debbd..bca11bb 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
@@ -261,7 +261,7 @@ public abstract class GridCoverage extends BandedCoverage {
         final Colorizer colorizer = new Colorizer(Colorizer.GRAYSCALE);
         final ColorModel colors;
         if (colorizer.initialize(sampleDimensions[visibleBand]) || colorizer.initialize(source.getColorModel()))
{
-            colors = colorizer.createColorModel(bandType.ordinal(), sampleDimensions.length,
visibleBand);
+            colors = colorizer.createColorModel(bandType.toDataBufferType(), sampleDimensions.length,
visibleBand);
         } else {
             colors = Colorizer.NULL_COLOR_MODEL;
         }
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/DataType.java b/core/sis-feature/src/main/java/org/apache/sis/image/DataType.java
index 29a84a7..f4c1c19 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/DataType.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/DataType.java
@@ -180,6 +180,8 @@ public enum DataType {
 
     /**
      * Returns the enumeration value for the given {@link DataBuffer} constant.
+     * This method is the converse of {@link #toDataBufferType()}.
+     * It is provided for interoperability with Java2D.
      *
      * @param  type  one of {@code DataBuffer.TYPE_*} constants.
      * @return the data type (never {@code null}) for the given data buffer type.
@@ -198,7 +200,7 @@ public enum DataType {
      *
      * @return size in bits of this data type.
      */
-    public int size() {
+    public final int size() {
         return DataBuffer.getDataTypeSize(ordinal());
     }
 
@@ -208,7 +210,7 @@ public enum DataType {
      *
      * @return {@code true} if this type is an unsigned integer type.
      */
-    public boolean isUnsigned() {
+    public final boolean isUnsigned() {
         return ordinal() <= DataBuffer.TYPE_USHORT;
     }
 
@@ -218,7 +220,7 @@ public enum DataType {
      *
      * @return {@code true} if this type is an integer type.
      */
-    public boolean isInteger() {
+    public final boolean isInteger() {
         return ordinal() <= DataBuffer.TYPE_INT;
     }
 
@@ -237,8 +239,19 @@ public enum DataType {
      * @return the smallest of {@link #FLOAT} or {@link #DOUBLE} types
      *         which can store all values of this type without any lost.
      */
-    public DataType toFloat() {
+    public final DataType toFloat() {
         final int type = ordinal();
         return (type < DataBuffer.TYPE_INT || type == DataBuffer.TYPE_FLOAT) ? FLOAT :
DOUBLE;
     }
+
+    /**
+     * Returns the {@link DataBuffer} constant for this enumeration value.
+     * This method is the converse of {@link #forDataBufferType(int)}.
+     * It is provided for interoperability with Java2D.
+     *
+     * @return one of the {@link DataBuffer} constants.
+     */
+    public final int toDataBufferType() {
+        return ordinal();
+    }
 }
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java b/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java
index 94e1d36..3b85591 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/ImageProcessor.java
@@ -793,7 +793,7 @@ public class ImageProcessor implements Cloneable {
         }
         // No need to clone `sourceRanges` because it is not stored by `BandedSampleConverter`.
         return unique(BandedSampleConverter.create(source, layout,
-                sourceRanges, converters, targetType.ordinal(), colorModel));
+                sourceRanges, converters, targetType.toDataBufferType(), colorModel));
     }
 
     /**
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/RasterFactory.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/RasterFactory.java
index a73c7dc..e350521 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/RasterFactory.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/RasterFactory.java
@@ -73,7 +73,7 @@ public final class RasterFactory extends Static {
      * <p><b>Warning:</b> displaying this image is very slow, except in
a few special cases.
      * It should be used only when no standard color model can be used.</p>
      *
-     * @param  dataType       the color model type as one of {@code DataBuffer.TYPE_*} constants.
+     * @param  dataType       the buffer type as one of {@code DataBuffer.TYPE_*} constants.
      * @param  width          the desired image width.
      * @param  height         the desired image height.
      * @param  numComponents  the number of components.
@@ -207,7 +207,7 @@ public final class RasterFactory extends Static {
      *
      * @param  dataType  type of buffer to create.
      * @param  data      the data, one for each band.
-     * @return buffer of the given type (ever null).
+     * @return buffer of the given type (never null).
      * @throws UnsupportedOperationException if a buffer is not backed by an accessible array.
      * @throws ReadOnlyBufferException if a buffer is backed by an array but is read-only.
      * @throws ArrayStoreException if the type of a backing array is not {@code dataType}.
diff --git a/core/sis-feature/src/test/java/org/apache/sis/image/DataTypeTest.java b/core/sis-feature/src/test/java/org/apache/sis/image/DataTypeTest.java
index 6e911ce..a0b6f60 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/image/DataTypeTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/image/DataTypeTest.java
@@ -37,12 +37,12 @@ public final strictfp class DataTypeTest extends TestCase {
      */
     @Test
     public void verifyOrdinalValues() {
-        assertEquals(DataBuffer.TYPE_BYTE  , DataType.BYTE  .ordinal());
-        assertEquals(DataBuffer.TYPE_USHORT, DataType.USHORT.ordinal());
-        assertEquals(DataBuffer.TYPE_SHORT , DataType.SHORT .ordinal());
-        assertEquals(DataBuffer.TYPE_INT   , DataType.INT   .ordinal());
-        assertEquals(DataBuffer.TYPE_FLOAT , DataType.FLOAT .ordinal());
-        assertEquals(DataBuffer.TYPE_DOUBLE, DataType.DOUBLE.ordinal());
+        assertEquals(DataBuffer.TYPE_BYTE  , DataType.BYTE  .toDataBufferType());
+        assertEquals(DataBuffer.TYPE_USHORT, DataType.USHORT.toDataBufferType());
+        assertEquals(DataBuffer.TYPE_SHORT , DataType.SHORT .toDataBufferType());
+        assertEquals(DataBuffer.TYPE_INT   , DataType.INT   .toDataBufferType());
+        assertEquals(DataBuffer.TYPE_FLOAT , DataType.FLOAT .toDataBufferType());
+        assertEquals(DataBuffer.TYPE_DOUBLE, DataType.DOUBLE.toDataBufferType());
     }
 
     /**
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/DataSubset.java
b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/DataSubset.java
index 82eb663..c23fc34 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/DataSubset.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/DataSubset.java
@@ -283,7 +283,7 @@ class DataSubset extends TiledGridCoverage implements Localized {
     WritableRaster readSlice(final long[] offsets, final long[] byteCounts, final long[]
lower, final long[] upper,
                              final int[] subsampling, final Point location) throws IOException,
DataStoreException
     {
-        final int  type   = model.getDataType();
+        final DataType type = DataType.forDataBufferType(model.getDataType());
         final long width  = subtractExact(upper[0], lower[0]);
         final long height = subtractExact(upper[1], lower[1]);
         /*
@@ -305,7 +305,7 @@ class DataSubset extends TiledGridCoverage implements Localized {
          * a subregion is read. Note that the `length` value may be different than `capacity`
if the tile to read
          * is smaller than the "standard" tile size of the image. It happens often when reading
the last strip.
          */
-        final long length  = multiplyExact(DataBuffer.getDataTypeSize(type) / Byte.SIZE,
+        final long length  = multiplyExact(type.size() / Byte.SIZE,
                              multiplyExact(multiplyExact(width, height), numInterleaved));
         final int capacity = multiplyExact(multiplyExact(model.getWidth(), model.getHeight()),
numInterleaved);
         final long[] size = new long[] {multiplyFull(numInterleaved, getTileSize(0)), getTileSize(1)};
@@ -322,7 +322,7 @@ class DataSubset extends TiledGridCoverage implements Localized {
          * Read each plane ("banks" in Java2D terminology). Note that a single bank contain
all bands
          * in the interleaved sample model case.
          */
-        final HyperRectangleReader hr = new HyperRectangleReader(ImageUtilities.toNumberEnum(type),
source.reader.input);
+        final HyperRectangleReader hr = new HyperRectangleReader(ImageUtilities.toNumberEnum(type.toDataBufferType()),
source.reader.input);
         final Region region = new Region(size, lower, upper, subsampling);
         final Buffer[] banks = new Buffer[numBanks];
         for (int b=0; b<numBanks; b++) {
@@ -346,7 +346,7 @@ class DataSubset extends TiledGridCoverage implements Localized {
             }
             banks[b] = buffer.limit(capacity);
         }
-        final DataBuffer buffer = RasterFactory.wrap(DataType.forDataBufferType(type), banks);
+        final DataBuffer buffer = RasterFactory.wrap(type, banks);
         return WritableRaster.createWritableRaster(model, buffer, location);
     }
 }
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
index 4f6bb4a..a71ee3a 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/ImageFileDirectory.java
@@ -1355,7 +1355,7 @@ final class ImageFileDirectory extends DataCube {
         if (sampleModel == null) {
             final DataType type = getDataType();
             try {
-                final int bt = type.ordinal();
+                final int bt = type.toDataBufferType();
                 if (bitsPerSample != type.size()) {
                     /*
                      * Supported types for both sample models are TYPE_BYTE, TYPE_USHORT,
and TYPE_INT.
diff --git a/storage/sis-geotiff/src/test/java/org/apache/sis/storage/geotiff/SelfConsistencyTest.java
b/storage/sis-geotiff/src/test/java/org/apache/sis/storage/geotiff/SelfConsistencyTest.java
index 92e0723..bd9e820 100644
--- a/storage/sis-geotiff/src/test/java/org/apache/sis/storage/geotiff/SelfConsistencyTest.java
+++ b/storage/sis-geotiff/src/test/java/org/apache/sis/storage/geotiff/SelfConsistencyTest.java
@@ -61,7 +61,7 @@ public final strictfp class SelfConsistencyTest extends CoverageReadConsistency
     }
 
     /**
-     * Closes the test file to be used for all tests.
+     * Closes the test file used by all tests.
      *
      * @throws DataStoreException if an error occurred while closing the file.
      */
diff --git a/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/SelfConsistencyTest.java
b/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/SelfConsistencyTest.java
index 50d9c16..fe12a72 100644
--- a/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/SelfConsistencyTest.java
+++ b/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/SelfConsistencyTest.java
@@ -62,7 +62,7 @@ public final strictfp class SelfConsistencyTest extends CoverageReadConsistency
     }
 
     /**
-     * Closes the test file to be used for all tests.
+     * Closes the test file used by all tests.
      *
      * @throws DataStoreException if an error occurred while closing the file.
      */

Mime
View raw message