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 e4515b0eb1ce5ba29303e9b576a4687fd43ffc2e Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sat Nov 25 11:57:02 2023 +0100 Better anticipation of methods and constants to be available in future Java versions. --- .../sis/coverage/grid/j2d/SampleModelFactory.java | 4 +- .../main/org/apache/sis/filter/sqlmm/Registry.java | 4 +- .../apache/sis/geometry/wrapper/j2d/Polyline.java | 4 +- .../main/org/apache/sis/image/MaskedImage.java | 2 +- .../main/org/apache/sis/image/PixelIterator.java | 2 +- .../main/org/apache/sis/image/PlanarImage.java | 6 +- .../apache/sis/image/processing/TiledProcess.java | 6 +- .../apache/sis/coverage/grid/GridExtentTest.java | 4 +- .../test/org/apache/sis/image/TiledImageMock.java | 6 +- .../gazetteer/GeohashReferenceSystem.java | 6 +- .../org/apache/sis/referencing/util/Formulas.java | 2 +- .../org/apache/sis/storage/geotiff/DataSubset.java | 2 +- .../sis/storage/geotiff/ImageFileDirectory.java | 5 +- .../geotiff/inflater/CompressionChannel.java | 4 +- .../geotiff/inflater/HorizontalPredictor.java | 4 +- .../sis/storage/geotiff/inflater/Inflater.java | 5 +- .../storage/geotiff/inflater/PredictorChannel.java | 4 +- .../sis/storage/geotiff/writer/TileMatrix.java | 4 +- .../org/apache/sis/storage/netcdf/base/Axis.java | 4 +- .../sis/storage/sql/postgis/RasterReader.java | 4 +- .../main/org/apache/sis/io/stream/Region.java | 2 +- .../aggregate/ConcatenatedGridResource.java | 5 +- .../apache/sis/storage/base/TiledGridCoverage.java | 2 +- .../apache/sis/storage/esri/CharactersView.java | 6 +- .../apache/sis/storage/esri/RawRasterReader.java | 2 +- .../apache/sis/storage/esri/RawRasterStore.java | 2 +- .../src/org.apache.sis.util/main/module-info.java | 2 + .../main/org/apache/sis/math/DecimalFunctions.java | 15 ++--- .../main/org/apache/sis/math/Fraction.java | 9 +-- .../main/org/apache/sis/math/MathFunctions.java | 7 ++- .../apache/sis/measure/SexagesimalConverter.java | 3 +- .../sis/pending/jdk/{JDK17.java => JDK13.java} | 42 +------------ .../main/org/apache/sis/pending/jdk/JDK16.java | 47 ++++++++++++++ .../main/org/apache/sis/pending/jdk/JDK18.java | 65 +++++++++++++++++++ .../main/org/apache/sis/pending/jdk/JDK19.java | 41 ++++++++++++ .../org/apache/sis/util/internal/DoubleDouble.java | 3 +- .../org/apache/sis/util/internal/Numerics.java | 73 +++++++--------------- .../org/apache/sis/math/MathFunctionsTest.java | 12 ++-- .../org/apache/sis/util/internal/NumericsTest.java | 11 ++-- 39 files changed, 264 insertions(+), 167 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/j2d/SampleModelFactory.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/j2d/SampleModelFactory.java index 8ca65478d2..fe48943ed2 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/j2d/SampleModelFactory.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/j2d/SampleModelFactory.java @@ -27,9 +27,9 @@ import java.awt.image.SinglePixelPackedSampleModel; import java.awt.image.RasterFormatException; import org.apache.sis.util.ArraysExt; import org.apache.sis.util.ArgumentChecks; -import org.apache.sis.util.internal.Numerics; import org.apache.sis.image.DataType; import org.apache.sis.util.resources.Errors; +import org.apache.sis.pending.jdk.JDK18; /** @@ -126,7 +126,7 @@ public final class SampleModelFactory { // MultiPixelPackedSampleModel pixelStride = 0; numberOfBits = bitsPerSample; - scanlineStride = Numerics.ceilDiv(Math.multiplyExact(width, numberOfBits), type.size()); + scanlineStride = JDK18.ceilDiv(Math.multiplyExact(width, numberOfBits), type.size()); } else if (!isBanded) { // SinglePixelPackedSampleModel bitMasks = new int[numBands]; diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/sqlmm/Registry.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/sqlmm/Registry.java index e3f421ec37..fe74f5d3f7 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/sqlmm/Registry.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/sqlmm/Registry.java @@ -20,7 +20,7 @@ import java.util.Arrays; import java.util.Collection; import org.apache.sis.geometry.wrapper.Geometries; import org.apache.sis.filter.internal.FunctionRegister; -import org.apache.sis.pending.jdk.JDK17; +import org.apache.sis.pending.jdk.JDK16; // Specific to the geoapi-3.1 and geoapi-4.0 branches: import org.opengis.filter.Expression; @@ -62,7 +62,7 @@ public final class Registry implements FunctionRegister { */ @Override public Collection<String> getNames() { - return JDK17.toList(Arrays.stream(SQLMM.values()).map(SQLMM::name)); + return JDK16.toList(Arrays.stream(SQLMM.values()).map(SQLMM::name)); } /** diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Polyline.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Polyline.java index 46fd02321c..f124650af4 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Polyline.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Polyline.java @@ -24,7 +24,7 @@ import java.awt.geom.Rectangle2D; import java.awt.geom.PathIterator; import java.awt.geom.AffineTransform; import org.apache.sis.util.Classes; -import org.apache.sis.util.internal.Numerics; +import static org.apache.sis.pending.jdk.JDK19.FLOAT_PRECISION; /** @@ -95,7 +95,7 @@ class Polyline extends FlatShape { * in the significand (mantissa) of {@code float} type. */ private static double round(final double center, final double min, final double max) { - final int e = Math.getExponent(Math.max(Math.abs(min), Math.abs(max))) - (Numerics.SIGNIFICAND_SIZE_OF_FLOAT - 3); + final int e = Math.getExponent(Math.max(Math.abs(min), Math.abs(max))) - (FLOAT_PRECISION - 4); return Math.scalb(Math.round(Math.scalb(center, -e)), e); } diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MaskedImage.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MaskedImage.java index 979fbf2dc6..bfbb7c7142 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MaskedImage.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/MaskedImage.java @@ -36,8 +36,8 @@ import org.apache.sis.util.internal.Numerics; import org.apache.sis.coverage.grid.j2d.FillValues; import org.apache.sis.coverage.grid.j2d.ImageUtilities; import org.apache.sis.coverage.grid.j2d.TilePlaceholder; -import static org.apache.sis.util.internal.Numerics.ceilDiv; import static org.apache.sis.util.internal.Numerics.LONG_SHIFT; +import static org.apache.sis.pending.jdk.JDK18.ceilDiv; /** diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PixelIterator.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PixelIterator.java index f94ebc469d..7a13096dad 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PixelIterator.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PixelIterator.java @@ -46,7 +46,7 @@ import org.apache.sis.measure.NumberRange; import org.apache.sis.util.internal.Numerics; import org.apache.sis.feature.internal.Resources; import org.apache.sis.coverage.grid.j2d.ImageUtilities; -import static org.apache.sis.util.internal.Numerics.ceilDiv; +import static org.apache.sis.pending.jdk.JDK18.ceilDiv; // Specific to the geoapi-3.1 and geoapi-4.0 branches: import org.opengis.coverage.grid.SequenceType; diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java index 8895ff7209..f717963122 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/PlanarImage.java @@ -33,12 +33,12 @@ import org.apache.sis.util.Disposable; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.resources.Errors; import org.apache.sis.util.resources.Messages; -import org.apache.sis.util.internal.Numerics; import org.apache.sis.coverage.SampleDimension; import org.apache.sis.coverage.grid.GridGeometry; // For javadoc import org.apache.sis.coverage.grid.j2d.ImageUtilities; import org.apache.sis.coverage.grid.j2d.TileOpExecutor; import org.apache.sis.coverage.grid.j2d.ColorModelFactory; +import org.apache.sis.pending.jdk.JDK18; /** @@ -369,7 +369,7 @@ public abstract class PlanarImage implements RenderedImage { * If assumption documented in javadoc does not hold, the calculation performed here would need to be * more complicated: compute tile index of minX, compute tile index of maxX, return difference plus 1. */ - return Numerics.ceilDiv(getWidth(), getTileWidth()); + return JDK18.ceilDiv(getWidth(), getTileWidth()); } /** @@ -383,7 +383,7 @@ public abstract class PlanarImage implements RenderedImage { */ @Override public int getNumYTiles() { - return Numerics.ceilDiv(getHeight(), getTileHeight()); + return JDK18.ceilDiv(getHeight(), getTileHeight()); } /** diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/processing/TiledProcess.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/processing/TiledProcess.java index 4a2c2f04cf..6afeaff7c5 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/processing/TiledProcess.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/processing/TiledProcess.java @@ -24,8 +24,8 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.atomic.AtomicInteger; import org.apache.sis.system.CommonExecutor; import org.apache.sis.util.ArgumentChecks; -import org.apache.sis.util.internal.Numerics; import org.apache.sis.image.PixelIterator; +import org.apache.sis.pending.jdk.JDK18; /** @@ -170,8 +170,8 @@ public abstract class TiledProcess<R> { final int ymin = data.getMinY(); final int xmax = Math.addExact(xmin, width); final int ymax = Math.addExact(ymin, height); - final int xinc = Numerics.ceilDiv(width, numTileX); - final int yinc = Numerics.ceilDiv(height, numTileY); + final int xinc = JDK18.ceilDiv(width, numTileX); + final int yinc = JDK18.ceilDiv(height, numTileY); final Rectangle subArea = new Rectangle(Math.addExact(xinc, overlapX), Math.addExact(yinc, overlapY)); int count = 0; diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java index c9afd55f9b..a656c5ea68 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java @@ -33,7 +33,7 @@ import org.apache.sis.referencing.operation.transform.MathTransforms; import org.apache.sis.referencing.operation.matrix.Matrices; import org.apache.sis.referencing.operation.matrix.Matrix3; import org.apache.sis.util.resources.Vocabulary; -import org.apache.sis.util.internal.Numerics; +import org.apache.sis.pending.jdk.JDK18; // Test dependencies import org.junit.Test; @@ -81,7 +81,7 @@ public final class GridExtentTest extends TestCase { assertEquals(low, extent.getLow (dimension), "low"); assertEquals(high, extent.getHigh(dimension), "high"); assertEquals(high - low + 1, extent.getSize(dimension), "size"); - assertEquals(Numerics.ceilDiv(high + low, 2), extent.getMedian(dimension), "median"); + assertEquals(JDK18.ceilDiv(high + low, 2), extent.getMedian(dimension), "median"); } /** diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/TiledImageMock.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/TiledImageMock.java index 06339d7d3d..0d9d4eaaee 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/TiledImageMock.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/TiledImageMock.java @@ -39,7 +39,7 @@ import java.awt.image.WritableRenderedImage; import org.apache.sis.coverage.grid.j2d.ImageUtilities; import org.apache.sis.coverage.grid.j2d.WritableTiledImage; import org.apache.sis.util.ArraysExt; -import org.apache.sis.util.internal.Numerics; +import org.apache.sis.pending.jdk.JDK18; // Test dependencies import static org.junit.jupiter.api.Assertions.*; @@ -172,8 +172,8 @@ public final class TiledImageMock extends PlanarImage implements WritableRendere this.tileHeight = tileHeight; this.minTileX = minTileX; this.minTileY = minTileY; - this.numXTiles = Numerics.ceilDiv(width, tileWidth); - this.numYTiles = Numerics.ceilDiv(height, tileHeight); + this.numXTiles = JDK18.ceilDiv(width, tileWidth); + this.numYTiles = JDK18.ceilDiv(height, tileHeight); this.tiles = new WritableRaster[numXTiles * numYTiles]; this.sampleModel = banded ? new BandedSampleModel(dataType, tileWidth, tileHeight, numBands) : new PixelInterleavedSampleModel(dataType, tileWidth, tileHeight, numBands, diff --git a/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java b/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java index 77181fad5b..a69353edce 100644 --- a/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java +++ b/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java @@ -41,9 +41,9 @@ import org.apache.sis.util.Utilities; import org.apache.sis.util.Workaround; import org.apache.sis.util.ComparisonMode; import org.apache.sis.util.ArgumentChecks; -import org.apache.sis.util.internal.Numerics; import org.apache.sis.util.resources.Errors; import org.apache.sis.util.resources.Vocabulary; +import org.apache.sis.pending.jdk.JDK18; // Specific to the geoapi-3.1 and geoapi-4.0 branches: import org.opengis.referencing.gazetteer.Location; @@ -375,7 +375,7 @@ public class GeohashReferenceSystem extends ReferencingByIdentifiers { final long b = Math.round(numLat); latNumBits = (Long.SIZE-1) - Long.numberOfLeadingZeros(b); if ((1L << latNumBits) != b) latNumBits++; - length = Math.max(Numerics.ceilDiv(latNumBits << 1, 5), 1); + length = Math.max(JDK18.ceilDiv(latNumBits << 1, 5), 1); } if (numLon > numLat) { final long b = Math.round(numLon); @@ -387,7 +387,7 @@ public class GeohashReferenceSystem extends ReferencingByIdentifiers { * If the latitude had enough bits, then length is sufficient. */ } else { - length = Math.max(Numerics.ceilDiv(lonNumBits << 1, 5), 1); + length = Math.max(JDK18.ceilDiv(lonNumBits << 1, 5), 1); } } } diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/util/Formulas.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/util/Formulas.java index d4a207e075..8908d4672a 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/util/Formulas.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/util/Formulas.java @@ -79,7 +79,7 @@ public final class Formulas extends Static { * * @see org.apache.sis.measure.Longitude#normalize(double) */ - public static final double LONGITUDE_MAX = (1L << Numerics.SIGNIFICAND_SIZE) * ANGULAR_TOLERANCE; + public static final double LONGITUDE_MAX = Numerics.MAX_INTEGER_CONVERTIBLE_TO_DOUBLE/2 * ANGULAR_TOLERANCE; /** * The length of a <cite>Julian year</cite> in milliseconds. diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java index 60f5193fe8..c6b7fceb0f 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/DataSubset.java @@ -50,7 +50,7 @@ import org.apache.sis.storage.geotiff.base.Resources; import org.apache.sis.storage.geotiff.reader.ReversedBitsChannel; import org.apache.sis.util.resources.Errors; import org.apache.sis.math.Vector; -import static org.apache.sis.util.internal.Numerics.ceilDiv; +import static org.apache.sis.pending.jdk.JDK18.ceilDiv; /** diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java index 48bc3d0192..52a0dca631 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/ImageFileDirectory.java @@ -64,6 +64,7 @@ import org.apache.sis.util.resources.Errors; import org.apache.sis.math.Vector; import org.apache.sis.measure.NumberRange; import org.apache.sis.image.DataType; +import org.apache.sis.pending.jdk.JDK18; /** @@ -1586,8 +1587,8 @@ final class ImageFileDirectory extends DataCube { @Override final long getNumTiles() { return Math.multiplyExact( - Numerics.ceilDiv(imageWidth, tileWidth), - Numerics.ceilDiv(imageHeight, tileHeight)); + JDK18.ceilDiv(imageWidth, tileWidth), + JDK18.ceilDiv(imageHeight, tileHeight)); } /** diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CompressionChannel.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CompressionChannel.java index 87ff92d9fd..bc04af0472 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CompressionChannel.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/CompressionChannel.java @@ -20,11 +20,11 @@ import java.util.Arrays; import java.io.IOException; import java.nio.ByteBuffer; import org.apache.sis.math.MathFunctions; -import org.apache.sis.util.internal.Numerics; import org.apache.sis.storage.StorageConnector; import org.apache.sis.storage.geotiff.base.Resources; import org.apache.sis.io.stream.ChannelDataInput; import org.apache.sis.storage.event.StoreListeners; +import org.apache.sis.pending.jdk.JDK18; /** @@ -118,7 +118,7 @@ abstract class CompressionChannel extends PixelChannel { if (i < 0) i = ~i; // Really tild, not minus. capacity = divisors[i]; // Smallest divisor ≥ BUFFER_SIZE } else { - capacity = Numerics.ceilDiv(BUFFER_SIZE, scanlineStride) * scanlineStride; // ≥ BUFFER_SIZE + capacity = JDK18.ceilDiv(BUFFER_SIZE, scanlineStride) * scanlineStride; // ≥ BUFFER_SIZE } ByteBuffer buffer = directBuffer ? ByteBuffer.allocateDirect(capacity) : ByteBuffer.allocate(capacity); buffer = buffer.order(input.buffer.order()).limit(0); diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/HorizontalPredictor.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/HorizontalPredictor.java index a1fbb9a447..ba2d507c0c 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/HorizontalPredictor.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/HorizontalPredictor.java @@ -19,7 +19,7 @@ package org.apache.sis.storage.geotiff.inflater; import java.io.IOException; import java.nio.ByteBuffer; import org.apache.sis.image.DataType; -import org.apache.sis.pending.jdk.JDK17; +import org.apache.sis.pending.jdk.JDK13; import org.apache.sis.storage.geotiff.base.Predictor; @@ -261,7 +261,7 @@ abstract class HorizontalPredictor extends PredictorChannel { @Override void saveLastPixel(final ByteBuffer buffer, int offset, int position) { System.arraycopy(savedValues, savedValues.length - offset, savedValues, 0, offset); - JDK17.get(buffer, position, savedValues, offset, savedValues.length - offset); + JDK13.get(buffer, position, savedValues, offset, savedValues.length - offset); } /** diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/Inflater.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/Inflater.java index 6c406bddde..2c6db16750 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/Inflater.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/Inflater.java @@ -23,14 +23,13 @@ import java.nio.Buffer; import org.apache.sis.image.DataType; import org.apache.sis.math.MathFunctions; import org.apache.sis.util.ArgumentChecks; -import org.apache.sis.util.internal.Numerics; import org.apache.sis.storage.UnsupportedEncodingException; import org.apache.sis.storage.geotiff.base.Compression; import org.apache.sis.storage.geotiff.base.Predictor; import org.apache.sis.storage.geotiff.base.Resources; import org.apache.sis.io.stream.ChannelDataInput; import org.apache.sis.storage.event.StoreListeners; -import static org.apache.sis.util.internal.Numerics.ceilDiv; +import static org.apache.sis.pending.jdk.JDK18.ceilDiv; /** @@ -124,7 +123,7 @@ public abstract class Inflater implements Closeable { * the value that we search cannot be greater. */ final int[] divisors = MathFunctions.divisors(samplesPerChunk); - int i = Arrays.binarySearch(divisors, Numerics.ceilDiv(samplesPerChunk, maxChunkSize)); + int i = Arrays.binarySearch(divisors, ceilDiv(samplesPerChunk, maxChunkSize)); if (i < 0) i = ~i; // No need for array bound check. /* * Following loop iterates exactly once unless `pixelsPerElement` > 1. diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/PredictorChannel.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/PredictorChannel.java index 08148517bf..be9068ed7e 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/PredictorChannel.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/inflater/PredictorChannel.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import org.apache.sis.util.ArraysExt; import org.apache.sis.storage.geotiff.base.Predictor; -import org.apache.sis.pending.jdk.JDK17; +import org.apache.sis.pending.jdk.JDK13; /** @@ -116,7 +116,7 @@ abstract class PredictorChannel extends PixelChannel { if (length > deferred.length) { deferred = new byte[length]; } - JDK17.get(target, end, deferred, deferredCount, remaining); + JDK13.get(target, end, deferred, deferredCount, remaining); target.position(end); deferredCount = length; } diff --git a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/writer/TileMatrix.java b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/writer/TileMatrix.java index f8d5314b24..48d2f83dc6 100644 --- a/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/writer/TileMatrix.java +++ b/endorsed/src/org.apache.sis.storage.geotiff/main/org/apache/sis/storage/geotiff/writer/TileMatrix.java @@ -31,13 +31,13 @@ import java.awt.image.DataBufferFloat; import java.awt.image.DataBufferDouble; import java.awt.image.SampleModel; import org.apache.sis.image.DataType; -import org.apache.sis.util.internal.Numerics; import org.apache.sis.io.stream.ChannelDataOutput; import org.apache.sis.io.stream.HyperRectangleWriter; import org.apache.sis.storage.DataStoreException; import org.apache.sis.storage.geotiff.base.Compression; import org.apache.sis.storage.geotiff.base.Predictor; import org.apache.sis.storage.geotiff.base.Resources; +import org.apache.sis.pending.jdk.JDK18; /** @@ -138,7 +138,7 @@ public final class TileMatrix { type = DataType.forBands(image); tileWidth = image.getTileWidth(); tileHeight = image.getTileHeight(); - pixelSize = (bitsPerSample != null) ? Numerics.ceilDiv(Arrays.stream(bitsPerSample).sum(), Byte.SIZE) : 1; + pixelSize = (bitsPerSample != null) ? JDK18.ceilDiv(Arrays.stream(bitsPerSample).sum(), Byte.SIZE) : 1; tileSize = tileWidth * tileHeight * pixelSize; // Overflow is not really a problem for our usage. numXTiles = image.getNumXTiles(); numYTiles = image.getNumYTiles(); diff --git a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Axis.java b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Axis.java index 78b2cb0c41..dff335eb41 100644 --- a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Axis.java +++ b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/Axis.java @@ -49,7 +49,6 @@ import org.apache.sis.referencing.operation.transform.MathTransforms; import org.apache.sis.storage.DataStoreException; import org.apache.sis.storage.netcdf.internal.Resources; import org.apache.sis.util.ArraysExt; -import org.apache.sis.util.internal.Numerics; import org.apache.sis.util.resources.Errors; import org.apache.sis.util.collection.Cache; import org.apache.sis.util.iso.Types; @@ -57,6 +56,7 @@ import org.apache.sis.measure.Longitude; import org.apache.sis.measure.Latitude; import org.apache.sis.measure.Units; import org.apache.sis.math.Vector; +import org.apache.sis.pending.jdk.JDK18; /** @@ -249,7 +249,7 @@ public final class Axis extends NamedElement { final Vector data = coordinates.read(); int n = data.size(); while (--n >= 0 && data.isNaN(n)) {} - final int nr = Numerics.ceilDiv(++n, page); + final int nr = JDK18.ceilDiv(++n, page); assert nr <= gridSizes[0] : nr; gridSizes[0] = nr; assert getSizeProduct(0) == n : n; diff --git a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/postgis/RasterReader.java b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/postgis/RasterReader.java index c7ded6a3ab..e272fbcb79 100644 --- a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/postgis/RasterReader.java +++ b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/postgis/RasterReader.java @@ -51,11 +51,11 @@ import org.apache.sis.io.stream.InputStreamArrayGetter; import org.apache.sis.io.stream.ChannelDataInput; import org.apache.sis.storage.sql.feature.InfoStatements; import org.apache.sis.util.internal.Constants; -import org.apache.sis.util.internal.Numerics; import org.apache.sis.measure.NumberRange; import org.apache.sis.math.Vector; import org.apache.sis.util.resources.Errors; import static org.apache.sis.storage.sql.postgis.Band.OPPOSITE_SIGN; +import org.apache.sis.pending.jdk.JDK18; /** @@ -235,7 +235,7 @@ public final class RasterReader extends RasterFormat { */ final int sampleSize = band.getDataTypeSize(); // In bits: 1, 2, 4, 8, 16, 32 or 64. final int elementSize = DataBuffer.getDataTypeSize(dataType); // Same as above except for 1, 2, 4. - final int length = Math.toIntExact(Numerics.ceilDiv(Math.multiplyFull(width, height) * sampleSize, elementSize)); + final int length = Math.toIntExact(JDK18.ceilDiv(Math.multiplyFull(width, height) * sampleSize, elementSize)); final Object data; switch (dataType & ~OPPOSITE_SIGN) { case DataBuffer.TYPE_USHORT: diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/Region.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/Region.java index f3264f426d..281b01c469 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/Region.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/io/stream/Region.java @@ -22,7 +22,7 @@ import static java.lang.Math.multiplyExact; import static java.lang.Math.incrementExact; import static java.lang.Math.toIntExact; import org.apache.sis.io.TableAppender; -import static org.apache.sis.util.internal.Numerics.ceilDiv; +import static org.apache.sis.pending.jdk.JDK18.ceilDiv; /** diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/ConcatenatedGridResource.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/ConcatenatedGridResource.java index 218751caf8..4b0fc78ff3 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/ConcatenatedGridResource.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/aggregate/ConcatenatedGridResource.java @@ -43,6 +43,7 @@ import org.apache.sis.coverage.internal.RangeArgument; import org.apache.sis.util.ArraysExt; import org.apache.sis.util.internal.UnmodifiableArrayList; import org.apache.sis.util.internal.Numerics; +import org.apache.sis.pending.jdk.JDK18; /** @@ -170,7 +171,7 @@ final class ConcatenatedGridResource extends AbstractGridCoverageResource implem this.slices = slices; this.locator = locator; this.strategy = strategy; - this.deferredLoading = new int[Numerics.ceilDiv(slices.length, Integer.SIZE)]; + this.deferredLoading = new int[JDK18.ceilDiv(slices.length, Integer.SIZE)]; for (final SampleDimension sd : ranges) { if (sd.forConvertedValues(true) != sd) { isConverted = false; @@ -448,7 +449,7 @@ final class ConcatenatedGridResource extends AbstractGridCoverageResource implem coverages [i] = slice; geometries[i] = slice.getGridGeometry(); if (deferred == null) { - deferred = new int[Numerics.ceilDiv(count, Integer.SIZE)]; + deferred = new int[JDK18.ceilDiv(count, Integer.SIZE)]; } deferred[i >>> Numerics.INT_SHIFT] |= (1 << i); } diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridCoverage.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridCoverage.java index dba4177747..c78ffa373b 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridCoverage.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/base/TiledGridCoverage.java @@ -46,7 +46,7 @@ import org.apache.sis.storage.tiling.TileMatrixSet; import org.apache.sis.storage.internal.Resources; import org.apache.sis.util.collection.WeakValueHashMap; import org.apache.sis.util.resources.Errors; -import static org.apache.sis.util.internal.Numerics.ceilDiv; +import static org.apache.sis.pending.jdk.JDK18.ceilDiv; // Specific to the geoapi-3.1 and geoapi-4.0 branches: import org.opengis.coverage.CannotEvaluateException; diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/CharactersView.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/CharactersView.java index beaf1cfeb7..583d26efdd 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/CharactersView.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/CharactersView.java @@ -23,7 +23,7 @@ import java.io.IOException; import java.io.EOFException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; -import org.apache.sis.pending.jdk.JDK17; +import org.apache.sis.pending.jdk.JDK13; import org.apache.sis.storage.DataStoreContentException; import org.apache.sis.storage.internal.Resources; import org.apache.sis.io.stream.ChannelDataInput; @@ -217,11 +217,11 @@ final class CharactersView implements CharSequence { if (direct) { return new String(array, start, length, StandardCharsets.US_ASCII); } else if (length <= array.length) { - JDK17.get(buffer, start, array, 0, length); + JDK13.get(buffer, start, array, 0, length); return new String(array, 0, length, StandardCharsets.US_ASCII); } else { final byte[] data = new byte[length]; - JDK17.get(buffer, start, data); + JDK13.get(buffer, start, data); return new String(data, StandardCharsets.US_ASCII); } } diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RawRasterReader.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RawRasterReader.java index d22acb4b1c..cc1b6639e4 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RawRasterReader.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RawRasterReader.java @@ -42,8 +42,8 @@ import org.apache.sis.io.stream.Region; import org.apache.sis.storage.DataStoreException; import org.apache.sis.storage.DataStoreContentException; import org.apache.sis.util.ArraysExt; -import static org.apache.sis.util.internal.Numerics.ceilDiv; import static org.apache.sis.util.internal.Numerics.wholeDiv; +import static org.apache.sis.pending.jdk.JDK18.ceilDiv; /** diff --git a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RawRasterStore.java b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RawRasterStore.java index 6b888b2c50..1a5871868f 100644 --- a/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RawRasterStore.java +++ b/endorsed/src/org.apache.sis.storage/main/org/apache/sis/storage/esri/RawRasterStore.java @@ -49,8 +49,8 @@ import org.apache.sis.util.ArraysExt; import org.apache.sis.util.resources.Messages; import org.apache.sis.util.resources.Errors; import org.apache.sis.image.DataType; -import static org.apache.sis.util.internal.Numerics.ceilDiv; import static org.apache.sis.util.internal.Numerics.wholeDiv; +import static org.apache.sis.pending.jdk.JDK18.ceilDiv; /** diff --git a/endorsed/src/org.apache.sis.util/main/module-info.java b/endorsed/src/org.apache.sis.util/main/module-info.java index afebada7be..4078e07f42 100644 --- a/endorsed/src/org.apache.sis.util/main/module-info.java +++ b/endorsed/src/org.apache.sis.util/main/module-info.java @@ -164,8 +164,10 @@ module org.apache.sis.util { org.apache.sis.referencing.database; // In the "non-free" sub-project. exports org.apache.sis.pending.jdk to + org.apache.sis.referencing.gazetteer, org.apache.sis.feature, org.apache.sis.storage, org.apache.sis.storage.sql, + org.apache.sis.storage.netcdf, org.apache.sis.storage.geotiff; } diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/DecimalFunctions.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/DecimalFunctions.java index c6fabf07d5..909963eb1b 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/DecimalFunctions.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/DecimalFunctions.java @@ -20,7 +20,8 @@ import org.apache.sis.util.Static; import org.apache.sis.util.Workaround; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.internal.Numerics; -import static org.apache.sis.util.internal.Numerics.SIGNIFICAND_SIZE; +import static org.apache.sis.pending.jdk.JDK19.FLOAT_PRECISION; +import static org.apache.sis.pending.jdk.JDK19.DOUBLE_PRECISION; /** @@ -143,7 +144,7 @@ public final class DecimalFunctions extends Static { * there is no fractional part in the value, in which case there is no rounding error to fix. * (Note: NaN and infinities also have exponent greater than zero). */ - final int e = Math.getExponent(value) - Numerics.SIGNIFICAND_SIZE_OF_FLOAT; + final int e = Math.getExponent(value) - (FLOAT_PRECISION - 1); if (e >= 0) { return value; // Integer, infinity or NaN. } @@ -221,11 +222,11 @@ public final class DecimalFunctions extends Static { * * m × (2 ^ e) == m × c × (10 ^ -e₁₀) */ - final int e = Math.getExponent(value) - SIGNIFICAND_SIZE; + final int e = Math.getExponent(value) - (DOUBLE_PRECISION - 1); if (e >= 0) { return 0; // Integer, infinity or NaN. } - if (e < -24 - SIGNIFICAND_SIZE) { // 2.9802322E-8 threshold found empirically. + if (e < -23 - DOUBLE_PRECISION) { // 2.9802322E-8 threshold found empirically. return (e == -1075) ? 0 : Double.NaN; // Returns 0 for the 0 value, NaN for all others. } final long m = Numerics.getSignificand(value); @@ -247,7 +248,7 @@ public final class DecimalFunctions extends Static { * will be equal or greater than 2^52. At that threshold, `double` values cannot have * fraction digits. */ - final int PRECISION = SIGNIFICAND_SIZE + 4; // Number of bits to use for scaling to integers. + final int PRECISION = DOUBLE_PRECISION + 3; // Number of bits to use for scaling to integers. double cs = Math.scalb(pow10(e10 - 1), e + PRECISION); // Range: (0.1 × 2^56 … 2^56) exclusive. /* * This is where magic happen: the following multiplication overflow (we would need a 128 bits integer @@ -416,13 +417,13 @@ public final class DecimalFunctions extends Static { /* * We really need Math.getExponent(value) here rather than MathFunctions.getExponent(value). * What we actually want is MathFunctions.getExponent(Math.ulp(value)), but we get the same - * result more efficiently if we replace the call to Math.ulp(double) by a SIGNIFICAND_SIZE + * result more efficiently if we replace the call to Math.ulp(double) by a Double.PRECISION * subtraction in the exponent, provided that the exponent has NOT been corrected for sub- * normal numbers (in order to reproduce the Math.ulp behavior). */ final int exponent = Math.getExponent(value); if (exponent <= Double.MAX_EXPONENT) { // Exclude NaN and ±∞ cases. - return -Numerics.toExp10(exponent - SIGNIFICAND_SIZE); + return -Numerics.toExp10(exponent - (DOUBLE_PRECISION - 1)); } return 0; } diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/Fraction.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/Fraction.java index 9435f7f7ab..8f87ee208b 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/Fraction.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/Fraction.java @@ -21,6 +21,7 @@ import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.resources.Errors; import org.apache.sis.util.collection.WeakHashSet; import org.apache.sis.util.internal.Numerics; +import static org.apache.sis.pending.jdk.JDK19.DOUBLE_PRECISION; /** @@ -127,7 +128,7 @@ public final class Fraction extends Number implements Comparable<Fraction>, Seri * exact match is found, the best match will be taken. */ long significand = Numerics.getSignificand(value); - int exponent = Math.getExponent(value) - Numerics.SIGNIFICAND_SIZE; // Power of 2. + int exponent = Math.getExponent(value) - (DOUBLE_PRECISION - 1); // Power of 2. int shift = Long.numberOfTrailingZeros(significand); significand >>>= shift; exponent += shift; @@ -155,14 +156,14 @@ public final class Fraction extends Number implements Comparable<Fraction>, Seri * starting with base 10. We will multiply the numerator and denominator by the largest power of 10 (or other base) * that can be used without causing an overflow, then simplify the fraction. */ - final double toMaximalSignificand = ((1L << Numerics.SIGNIFICAND_SIZE) - 1) / Math.ceil(Math.abs(value)); + final double toMaximalSignificand = Numerics.SIGNIFICAND_MASK / Math.ceil(Math.abs(value)); if (toMaximalSignificand > 1) { - exponent = Numerics.toExp10(Math.getExponent(toMaximalSignificand)); // Power of 10. + exponent = Numerics.toExp10(Math.getExponent(toMaximalSignificand)); // Power of 10. double factor = DecimalFunctions.pow10(exponent + 1); if (factor > toMaximalSignificand) { factor = DecimalFunctions.pow10(exponent); } - assert factor >= 1 && factor <= (1L << Numerics.SIGNIFICAND_SIZE) - 1 : factor; // For use as denominator. + assert factor >= 1 && factor <= Numerics.SIGNIFICAND_MASK : factor; // For use as denominator. try { final Fraction f = simplify(null, Math.round(value * factor), Math.round(factor)); if (f.doubleValue() == value) return f; diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/MathFunctions.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/MathFunctions.java index 4c6d8c27e6..e28b03c93e 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/MathFunctions.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/math/MathFunctions.java @@ -39,7 +39,8 @@ import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.resources.Errors; import org.apache.sis.util.internal.DoubleDouble; import static org.apache.sis.util.internal.Numerics.SIGN_BIT_MASK; -import static org.apache.sis.util.internal.Numerics.SIGNIFICAND_SIZE; +import static org.apache.sis.util.internal.Numerics.SIGNIFICAND_MASK; +import static org.apache.sis.pending.jdk.JDK19.DOUBLE_PRECISION; /** @@ -317,7 +318,7 @@ public final class MathFunctions extends Static { */ public static int getExponent(final double value) { final long bits = doubleToRawLongBits(value); - int exponent = (int) ((bits >>> SIGNIFICAND_SIZE) & 0x7FFL); + int exponent = (int) ((bits >>> (DOUBLE_PRECISION - 1)) & 0x7FFL); if (exponent == 0) { /* * Number is sub-normal: there is no implicit 1 bit before the significand. @@ -326,7 +327,7 @@ public final class MathFunctions extends Static { * 64 bits while the significand size is only 52 bits. The last term below * is for fixing this difference. */ - exponent -= Long.numberOfLeadingZeros(bits & ((1L << SIGNIFICAND_SIZE) - 1)) - (Long.SIZE - SIGNIFICAND_SIZE); + exponent -= Long.numberOfLeadingZeros(bits & SIGNIFICAND_MASK) - (Long.SIZE - (DOUBLE_PRECISION - 1)); } return exponent - Double.MAX_EXPONENT; } diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/SexagesimalConverter.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/SexagesimalConverter.java index dc02eb8ef8..129bcaf4ab 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/SexagesimalConverter.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/measure/SexagesimalConverter.java @@ -23,6 +23,7 @@ import org.apache.sis.util.resources.Errors; import org.apache.sis.util.internal.Numerics; import org.apache.sis.math.MathFunctions; import static org.apache.sis.math.MathFunctions.truncate; +import static org.apache.sis.pending.jdk.JDK19.DOUBLE_PRECISION; /** @@ -242,7 +243,7 @@ class SexagesimalConverter extends AbstractConverter { * Removal of degrees and/or minutes fields as integers do not add rounding errors. */ int p = Math.getExponent(Math.ulp(magnitude)); // Power of 2 (negative for fractional value). - if (p < 0 && p >= -Numerics.SIGNIFICAND_SIZE) { // Precision is a fraction digit >= Math.ulp(1). + if (p < 0 && p > -DOUBLE_PRECISION) { // Precision is a fraction digit >= Math.ulp(1). p = Numerics.toExp10(-p); // Positive power of 10, rounded to lower value. final double scale = MathFunctions.pow10(p); remainder = Math.rint(remainder * scale) / scale; diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK17.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK13.java similarity index 61% rename from endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK17.java rename to endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK13.java index 341bcced1e..26365ef0fb 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK17.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK13.java @@ -16,13 +16,7 @@ */ package org.apache.sis.pending.jdk; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; import java.nio.ByteBuffer; -import java.util.List; -import java.util.stream.Stream; -import org.apache.sis.util.internal.UnmodifiableArrayList; /** @@ -30,11 +24,11 @@ import org.apache.sis.util.internal.UnmodifiableArrayList; * * @author Martin Desruisseaux (Geomatys) */ -public final class JDK17 { +public final class JDK13 { /** * Do not allow instantiation of this class. */ - private JDK17() { + private JDK13() { } /** @@ -62,36 +56,4 @@ public final class JDK17 { dst[offset + i] = b.get(index + i); } } - - /** - * Place holder for {@link InputStream#skipNBytes(long)} method added in JDK12. - * - * @param s the input stream where to skip bytes. - * @param n the number of bytes to skip. - * @throws IOException if an error occurred while reading bytes, including EOF. - */ - public static void skipNBytes(final InputStream s, long n) throws IOException { - while (n > 0) { - long c = s.skip(n); - if (c <= 0) { - if (c < 0 || s.read() < 0) { - throw new EOFException(); - } - c = 1; - } - n -= c; - } - } - - /** - * Place holder for {@link Stream#toList()} method added in JDK16. - * - * @param <T> type of elements in the stream. - * @param s the stream to convert to a list. - * @return the stream content as a list. - */ - @SuppressWarnings("unchecked") - public static <T> List<T> toList(final Stream<T> s) { - return (List<T>) UnmodifiableArrayList.wrap(s.toArray()); - } } diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK16.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK16.java new file mode 100644 index 0000000000..53270b08ea --- /dev/null +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK16.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.pending.jdk; + +import java.util.List; +import java.util.stream.Stream; +import org.apache.sis.util.internal.UnmodifiableArrayList; + + +/** + * Place holder for some functionalities defined in a JDK more recent than Java 11. + * + * @author Martin Desruisseaux (Geomatys) + */ +public final class JDK16 { + /** + * Do not allow instantiation of this class. + */ + private JDK16() { + } + + /** + * Place holder for {@link Stream#toList()} method added in JDK16. + * + * @param <T> type of elements in the stream. + * @param s the stream to convert to a list. + * @return the stream content as a list. + */ + @SuppressWarnings("unchecked") + public static <T> List<T> toList(final Stream<T> s) { + return (List<T>) UnmodifiableArrayList.wrap(s.toArray()); + } +} diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK18.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK18.java new file mode 100644 index 0000000000..3596bf6da7 --- /dev/null +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK18.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.pending.jdk; + + +/** + * Place holder for some functionalities defined in a JDK more recent than Java 11. + * + * @author Martin Desruisseaux (Geomatys) + */ +public final class JDK18 { + /** + * Do not allow instantiation of this class. + */ + private JDK18() { + } + + /** + * Returns the smallest (closest to negative infinity) integer value that is greater than or equals to x/y. + * + * @param x the dividend. + * @param y the divisor. + * @return x/y rounded toward positive infinity. + * + * @see Math#floorDiv(int, int) + */ + public static int ceilDiv(final int x, final int y) { + int r = x / y; + if ((x ^ y) >= 0 && (r * y != x)) { + r++; + } + return r; + } + + /** + * Returns the smallest (closest to negative infinity) long value that is greater than or equals to x/y. + * + * @param x the dividend. + * @param y the divisor. + * @return x/y rounded toward positive infinity. + * + * @see Math#floorDiv(long, long) + */ + public static long ceilDiv(final long x, final long y) { + long r = x / y; + if ((x ^ y) >= 0 && (r * y != x)) { + r++; + } + return r; + } +} diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK19.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK19.java new file mode 100644 index 0000000000..933e9ef92e --- /dev/null +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/pending/jdk/JDK19.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.pending.jdk; + + +/** + * Place holder for some functionalities defined in a JDK more recent than Java 11. + * + * @author Martin Desruisseaux (Geomatys) + */ +public final class JDK19 { + /** + * Place holder for {@code Float.PRECISION}. + */ + public static final int FLOAT_PRECISION = 24; + + /** + * Place holder for {@code Double.PRECISION}. + */ + public static final int DOUBLE_PRECISION = 53; + + /** + * Do not allow instantiation of this class. + */ + private JDK19() { + } +} diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/internal/DoubleDouble.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/internal/DoubleDouble.java index 6938ed9f6a..19e8961676 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/internal/DoubleDouble.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/internal/DoubleDouble.java @@ -25,6 +25,7 @@ import org.apache.sis.math.MathFunctions; import org.apache.sis.math.DecimalFunctions; import org.apache.sis.system.Configuration; import org.apache.sis.util.Debug; +import static org.apache.sis.pending.jdk.JDK19.DOUBLE_PRECISION; /** @@ -533,7 +534,7 @@ public final class DoubleDouble extends Number implements Comparable<DoubleDoubl * significand bits (we ignore some more bits if ZERO_THRESHOLD is greater than 0). * If the error is not greater than that value, then assume that it is not significant. */ - if (Math.abs(e) <= Math.scalb(Math.ulp(otherValue), ZERO_THRESHOLD - Numerics.SIGNIFICAND_SIZE)) { + if (Math.abs(e) <= Math.scalb(Math.ulp(otherValue), ZERO_THRESHOLD - (DOUBLE_PRECISION - 1))) { return new DoubleDouble(s, 0); } } diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/internal/Numerics.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/internal/Numerics.java index b1b338bdfb..f7f6f62111 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/internal/Numerics.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/internal/Numerics.java @@ -33,6 +33,8 @@ import org.apache.sis.math.MathFunctions; import org.apache.sis.math.Statistics; import org.apache.sis.math.Fraction; import org.apache.sis.system.Configuration; +import static org.apache.sis.pending.jdk.JDK19.FLOAT_PRECISION; +import static org.apache.sis.pending.jdk.JDK19.DOUBLE_PRECISION; /** @@ -112,21 +114,26 @@ public final class Numerics extends Static { public static final long HIGH_BITS_MASK = ~((1L << Integer.SIZE) - 1); /** - * Number of bits in the significand (mantissa) part of IEEE 754 {@code double} representation, + * Mask for bits in the significand (mantissa) part of IEEE 754 {@code double} representation, * <strong>not</strong> including the hidden bit. */ - public static final int SIGNIFICAND_SIZE = 52; + public static final long SIGNIFICAND_MASK = (1L << (DOUBLE_PRECISION - 1)) - 1; /** - * Number of bits in the significand (mantissa) part of IEEE 754 {@code float} representation, + * Mask for bits in the significand (mantissa) part of IEEE 754 {@code float} representation, * <strong>not</strong> including the hidden bit. */ - public static final int SIGNIFICAND_SIZE_OF_FLOAT = 23; + public static final int SIGNIFICAND_MASK_OF_FLOAT = (1 << (FLOAT_PRECISION - 1)) - 1; /** * Maximal integer value which is convertible to {@code float} type without lost of precision digits. */ - public static final int MAX_INTEGER_CONVERTIBLE_TO_FLOAT = 1 << (SIGNIFICAND_SIZE_OF_FLOAT + 1); + public static final int MAX_INTEGER_CONVERTIBLE_TO_FLOAT = 1 << FLOAT_PRECISION; + + /** + * Maximal integer value which is convertible to {@code double} type without lost of precision digits. + */ + public static final long MAX_INTEGER_CONVERTIBLE_TO_DOUBLE = 1L << DOUBLE_PRECISION; /** * Right shift to apply for a result equivalent to a division by {@value Long#SIZE} (ignoring negative numbers). @@ -200,42 +207,6 @@ public final class Numerics extends Static { return x == Math.rint(x); // `rint` is reported faster than `floor`. } - /** - * Returns the smallest (closest to negative infinity) integer value that is greater than or equals to x/y. - * - * @param x the dividend. - * @param y the divisor. - * @return x/y rounded toward positive infinity. - * - * @see Math#floorDiv(int, int) - * - * @todo Replace by {@link Math#ceilDiv(int, int)} in JDK18. - */ - public static int ceilDiv(final int x, final int y) { - int r = x / y; - if ((x ^ y) >= 0 && (r * y != x)) { - r++; - } - return r; - } - - /** - * Returns the smallest (closest to negative infinity) long value that is greater than or equals to x/y. - * - * @param x the dividend. - * @param y the divisor. - * @return x/y rounded toward positive infinity. - * - * @see Math#floorDiv(long, long) - */ - public static long ceilDiv(final long x, final long y) { - long r = x / y; - if ((x ^ y) >= 0 && (r * y != x)) { - r++; - } - return r; - } - /** * Returns x/y with the requirement that the division must be integer. * @@ -495,11 +466,11 @@ public final class Numerics extends Static { /** * Returns the significand <var>m</var> of the given value such as {@code value = m×2ⁿ} - * where <var>n</var> is {@link Math#getExponent(double)} - {@value #SIGNIFICAND_SIZE}. + * where <var>n</var> is {@link Math#getExponent(double)} - ({@link Double#PRECISION} - 1). * For any non-NaN values (including infinity), the following relationship holds: * * {@snippet lang="java" : - * assert Math.scalb(getSignificand(value), Math.getExponent(value) - SIGNIFICAND_SIZE) == Math.abs(value); + * assert Math.scalb(getSignificand(value), Math.getExponent(value) - (Double.PRECISION - 1)) == Math.abs(value); * } * * For negative values, this method behaves as if the value was positive. @@ -509,10 +480,10 @@ public final class Numerics extends Static { */ public static long getSignificand(final double value) { long bits = Double.doubleToRawLongBits(value); - final long exponent = bits & (0x7FFL << SIGNIFICAND_SIZE); - bits &= (1L << SIGNIFICAND_SIZE) - 1; + final long exponent = bits & (0x7FFL << (DOUBLE_PRECISION - 1)); + bits &= SIGNIFICAND_MASK; if (exponent != 0) { - bits |= (1L << SIGNIFICAND_SIZE); + bits |= (1L << (DOUBLE_PRECISION - 1)); // The IEEE754 implicit bit. } else { /* * Sub-normal value: compensate for the fact that Math.getExponent(value) returns @@ -525,11 +496,11 @@ public final class Numerics extends Static { /** * Returns the significand <var>m</var> of the given value such as {@code value = m×2ⁿ} where - * <var>n</var> is {@link Math#getExponent(float)} - {@value #SIGNIFICAND_SIZE_OF_FLOAT}. + * <var>n</var> is {@link Math#getExponent(float)} - ({@link Float#PRECISION} - 1). * For any non-NaN positive values (including infinity), the following relationship holds: * * {@snippet lang="java" : - * assert Math.scalb(getSignificand(value), Math.getExponent(value) - SIGNIFICAND_SIZE_OF_FLOAT) == value; + * assert Math.scalb(getSignificand(value), Math.getExponent(value) - (Float.PRECISION - 1)) == value; * } * * For negative values, this method behaves as if the value was positive. @@ -539,10 +510,10 @@ public final class Numerics extends Static { */ public static int getSignificand(final float value) { int bits = Float.floatToRawIntBits(value); - final int exponent = bits & (0xFF << SIGNIFICAND_SIZE_OF_FLOAT); - bits &= (1 << SIGNIFICAND_SIZE_OF_FLOAT) - 1; + final int exponent = bits & (0xFF << (FLOAT_PRECISION - 1)); + bits &= SIGNIFICAND_MASK_OF_FLOAT; if (exponent != 0) { - bits |= (1 << SIGNIFICAND_SIZE_OF_FLOAT); + bits |= (1 << (FLOAT_PRECISION - 1)); // The IEEE754 implicit bit. } else { bits <<= 1; } diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/math/MathFunctionsTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/math/MathFunctionsTest.java index 66ac9e2b9b..ae1445338f 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/math/MathFunctionsTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/math/MathFunctionsTest.java @@ -20,7 +20,7 @@ import java.util.Random; import static java.lang.Double.*; import static org.apache.sis.math.MathFunctions.*; import static org.apache.sis.util.ArraysExt.isSorted; -import static org.apache.sis.util.internal.Numerics.SIGNIFICAND_SIZE; +import static org.apache.sis.pending.jdk.JDK19.DOUBLE_PRECISION; // Test dependencies import org.junit.Test; @@ -144,22 +144,22 @@ public final class MathFunctionsTest extends TestCase { * getExponent(MIN_NORMAL / 8) == MIN_EXPONENT - 3 * etc. */ - for (int i=0; i<=SIGNIFICAND_SIZE; i++) { + for (int i=0; i<DOUBLE_PRECISION; i++) { assertEquals(MIN_EXPONENT - i, getExponent(MIN_NORMAL / (1L << i))); } assertEquals(MIN_EXPONENT - 1, getExponent(StrictMath.nextDown(MIN_NORMAL))); - assertEquals(MIN_EXPONENT - SIGNIFICAND_SIZE, getExponent(MIN_VALUE)); - assertEquals(MIN_EXPONENT - SIGNIFICAND_SIZE - 1, getExponent(0)); + assertEquals(MIN_EXPONENT - DOUBLE_PRECISION + 1, getExponent(MIN_VALUE)); + assertEquals(MIN_EXPONENT - DOUBLE_PRECISION, getExponent(0)); /* * Tests consistency with scalb, as documented in MathFunctions.getExponent(double) javadoc. */ - for (int i = MIN_EXPONENT - SIGNIFICAND_SIZE - 1; i <= MAX_EXPONENT + 1; i++) { + for (int i = MIN_EXPONENT - DOUBLE_PRECISION; i <= MAX_EXPONENT + 1; i++) { assertEquals(i, getExponent(StrictMath.scalb(1.0, i))); } /* * Tests consistency with log10, as documented in MathFunctions.getExponent(double) javadoc. */ - for (int i = MIN_EXPONENT - SIGNIFICAND_SIZE; i <= MAX_EXPONENT; i++) { + for (int i = MIN_EXPONENT - (DOUBLE_PRECISION - 1); i <= MAX_EXPONENT; i++) { assertEquals(StrictMath.floor(StrictMath.log10(StrictMath.scalb(1.0, i))), StrictMath.floor(LOG10_2 * i /* i = getExponent(value) */), STRICT); } diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/internal/NumericsTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/internal/NumericsTest.java index 358088b5dc..1453f6f132 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/internal/NumericsTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/internal/NumericsTest.java @@ -24,6 +24,9 @@ import static java.lang.Double.NEGATIVE_INFINITY; import org.apache.sis.math.MathFunctions; import org.apache.sis.util.ComparisonMode; import static org.apache.sis.util.internal.Numerics.*; +import static org.apache.sis.pending.jdk.JDK18.ceilDiv; +import static org.apache.sis.pending.jdk.JDK19.FLOAT_PRECISION; +import static org.apache.sis.pending.jdk.JDK19.DOUBLE_PRECISION; // Test dependencies import org.junit.Test; @@ -221,18 +224,18 @@ public final class NumericsTest extends TestCase { */ private static void assertSignificandEquals(final long expected, final double value) { assertEquals(expected, getSignificand(value)); - final int e = StrictMath.getExponent(value) - SIGNIFICAND_SIZE; + final int e = StrictMath.getExponent(value) - (DOUBLE_PRECISION - 1); final double recomposed = StrictMath.scalb((double) expected, e); assertEquals(value, StrictMath.copySign(recomposed, value), 0); } /** - * Asserts that {@link Numerics#getSignificand(float)} returns the expected value, - * then verify the {@link StrictMath#scalb(float, int)} identity. + * Asserts that {@link Numerics#getSignificand(float)} returns the expected value. + * Also verifies the {@link StrictMath#scalb(float, int)} identity. */ private static void assertSignificandEquals(final int expected, final float value) { assertEquals(expected, getSignificand(value)); - final int e = StrictMath.getExponent(value) - SIGNIFICAND_SIZE_OF_FLOAT; + final int e = StrictMath.getExponent(value) - (FLOAT_PRECISION - 1); final float recomposed = StrictMath.scalb((float) expected, e); assertEquals(value, StrictMath.copySign(recomposed, value), 0f); }