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 4108d967709f51b953627a789a63536856120f7f Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sat Dec 10 18:00:58 2022 +0100 Replace more `JDK9` placeholder. Those replacements are more risky because they introduce slight behavioral changes (range checks in `Arrays.equals(…)`, different iteration order in `Set` and `Map`). --- .../apache/sis/internal/gui/ImageConverter.java | 5 +- .../sis/coverage/grid/GridCoordinatesView.java | 5 +- .../java/org/apache/sis/image/BandSelectImage.java | 3 +- .../sis/image/PositionalConsistencyImage.java | 3 +- .../org/apache/sis/image/SourceAlignedImage.java | 3 +- .../internal/coverage/j2d/BatchComputedImage.java | 4 +- .../sis/internal/coverage/j2d/TiledImage.java | 4 +- .../apache/sis/internal/feature/j2d/Wrapper.java | 4 +- .../sis/internal/feature/jts/ShapeConverter.java | 5 +- .../apache/sis/coverage/grid/GridExtentTest.java | 4 +- .../org/apache/sis/geometry/CoordinateFormat.java | 3 +- .../internal/referencing/CoordinateOperations.java | 3 +- .../java/org/apache/sis/io/wkt/WKTDictionary.java | 3 +- .../java/org/apache/sis/referencing/CommonCRS.java | 3 +- .../sis/internal/referencing/WKTKeywordsTest.java | 5 +- .../operation/HardCodedConversions.java | 5 +- .../java/org/apache/sis/internal/jdk9/JDK9.java | 185 --------------------- .../main/java/org/apache/sis/math/ArrayVector.java | 13 +- .../src/main/java/org/apache/sis/math/Vector.java | 36 ++-- .../apache/sis/util/collection/IntegerList.java | 3 +- .../sis/internal/netcdf/impl/VariableInfo.java | 3 +- .../sis/internal/netcdf/ucar/VariableWrapper.java | 4 +- .../sis/internal/storage/StoreUtilities.java | 3 +- .../apache/sis/storage/event/StoreListeners.java | 3 +- 24 files changed, 54 insertions(+), 258 deletions(-) diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageConverter.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageConverter.java index 77bed28dd8..6a80e6b18c 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageConverter.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ImageConverter.java @@ -39,7 +39,6 @@ import org.apache.sis.internal.coverage.j2d.ColorModelFactory; import org.apache.sis.internal.coverage.j2d.ImageUtilities; import org.apache.sis.internal.system.Loggers; import org.apache.sis.internal.util.Numerics; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.util.logging.Logging; import org.apache.sis.measure.NumberRange; import org.apache.sis.math.Statistics; @@ -70,7 +69,7 @@ final class ImageConverter extends Task<Statistics[]> { * Colors to apply on the mask image when that image is overlay on top of another image. * Current value is a transparent yellow color. */ - private static final Map<NumberRange<?>,Color[]> MASK_TRANSPARENCY = JDK9.mapOf( + private static final Map<NumberRange<?>,Color[]> MASK_TRANSPARENCY = Map.of( NumberRange.create(0, true, 0, true), new Color[] {ColorModelFactory.TRANSPARENT}, NumberRange.create(1, true, 1, true), new Color[] {new Color(0x30FFFF00, true)}); @@ -187,7 +186,7 @@ final class ImageConverter extends Task<Statistics[]> { */ final ImageProcessor processor = new ImageProcessor(); final Statistics[] statistics = processor.valueOfStatistics(source, sourceAOI, (DoubleUnaryOperator[]) null); - final RenderedImage image = processor.stretchColorRamp(source, JDK9.mapOf("multStdDev", 3, "statistics", statistics)); + final RenderedImage image = processor.stretchColorRamp(source, Map.of("multStdDev", 3, "statistics", statistics)); final RenderedImage mask = getMask(processor); final BufferedImage buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE); final Graphics2D graphics = buffer.createGraphics(); diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java index 77afa5611c..92d67f4201 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java +++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java @@ -20,7 +20,6 @@ import java.util.Arrays; import org.opengis.coverage.grid.GridCoordinates; import org.apache.sis.util.resources.Errors; import org.apache.sis.util.ArgumentChecks; -import org.apache.sis.internal.jdk9.JDK9; /** @@ -129,8 +128,8 @@ final class GridCoordinatesView implements GridCoordinates { */ if (object instanceof GridCoordinatesView) { final GridCoordinatesView that = (GridCoordinatesView) object; - return JDK9.equals(this.coordinates, this.offset, this.offset + this.getDimension(), - that.coordinates, that.offset, that.offset + that.getDimension()); + return Arrays.equals(this.coordinates, this.offset, this.offset + this.getDimension(), + that.coordinates, that.offset, that.offset + that.getDimension()); } return false; } diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/BandSelectImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/BandSelectImage.java index 6d07a4e589..bc8c529794 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/image/BandSelectImage.java +++ b/core/sis-feature/src/main/java/org/apache/sis/image/BandSelectImage.java @@ -30,7 +30,6 @@ import org.apache.sis.util.ArraysExt; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.internal.coverage.j2d.ImageUtilities; import org.apache.sis.internal.coverage.j2d.ColorModelFactory; -import org.apache.sis.internal.jdk9.JDK9; /** @@ -48,7 +47,7 @@ final class BandSelectImage extends SourceAlignedImage { * * @see #getProperty(String) */ - private static final Set<String> INHERITED_PROPERTIES = JDK9.setOf( + private static final Set<String> INHERITED_PROPERTIES = Set.of( GRID_GEOMETRY_KEY, POSITIONAL_ACCURACY_KEY, // Properties to forward as-is. SAMPLE_RESOLUTIONS_KEY, STATISTICS_KEY); // Properties to forward after band reduction. diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/PositionalConsistencyImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/PositionalConsistencyImage.java index 69c0b3988b..f6d684fecf 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/image/PositionalConsistencyImage.java +++ b/core/sis-feature/src/main/java/org/apache/sis/image/PositionalConsistencyImage.java @@ -23,7 +23,6 @@ import java.awt.image.WritableRaster; import org.opengis.referencing.operation.MathTransform; import org.opengis.referencing.operation.TransformException; import org.apache.sis.internal.coverage.j2d.ColorModelFactory; -import org.apache.sis.internal.jdk9.JDK9; /** @@ -42,7 +41,7 @@ final class PositionalConsistencyImage extends SourceAlignedImage { * * @see #getPropertyNames() */ - private static final Set<String> INHERITED_PROPERTIES = JDK9.setOf( + private static final Set<String> INHERITED_PROPERTIES = Set.of( GRID_GEOMETRY_KEY, POSITIONAL_ACCURACY_KEY, MASK_KEY); /** diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java index 907a701d1a..519b9a1545 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java +++ b/core/sis-feature/src/main/java/org/apache/sis/image/SourceAlignedImage.java @@ -25,7 +25,6 @@ import java.awt.image.RenderedImage; import org.apache.sis.util.ArraysExt; import org.apache.sis.util.Disposable; import org.apache.sis.util.Workaround; -import org.apache.sis.internal.jdk9.JDK9; /** @@ -57,7 +56,7 @@ abstract class SourceAlignedImage extends ComputedImage { * May be used as the {@code inherit} argument in {@link #filterPropertyNames(String[], Set, String[])}. * Inheriting those properties make sense for operations that do not change pixel coordinates. */ - static final Set<String> POSITIONAL_PROPERTIES = JDK9.setOf(GRID_GEOMETRY_KEY, + static final Set<String> POSITIONAL_PROPERTIES = Set.of(GRID_GEOMETRY_KEY, POSITIONAL_ACCURACY_KEY, ResampledImage.POSITIONAL_CONSISTENCY_KEY); /** diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/BatchComputedImage.java b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/BatchComputedImage.java index 616affc40f..33a002a98c 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/BatchComputedImage.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/BatchComputedImage.java @@ -17,7 +17,6 @@ package org.apache.sis.internal.coverage.j2d; import java.util.Map; -import java.util.Collections; import java.awt.Rectangle; import java.awt.Image; import java.awt.image.Raster; @@ -26,7 +25,6 @@ import java.awt.image.RenderedImage; import java.awt.image.SampleModel; import java.awt.image.ImagingOpException; import org.apache.sis.image.ComputedImage; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.util.Disposable; import org.apache.sis.util.resources.Errors; @@ -96,7 +94,7 @@ public abstract class BatchComputedImage extends ComputedImage { */ protected BatchComputedImage(final SampleModel sampleModel, final Map<String,Object> properties, final RenderedImage... sources) { super(sampleModel, sources); - this.properties = (properties != null) ? JDK9.copyOf(properties) : Collections.emptyMap(); + this.properties = (properties != null) ? Map.copyOf(properties) : Map.of(); } /** diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TiledImage.java b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TiledImage.java index 4d6d65b3a1..c850435090 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TiledImage.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TiledImage.java @@ -17,13 +17,11 @@ package org.apache.sis.internal.coverage.j2d; import java.util.Map; -import java.util.Collections; import java.awt.Image; import java.awt.image.Raster; import java.awt.image.ColorModel; import java.awt.image.SampleModel; import org.apache.sis.image.PlanarImage; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.resources.Errors; @@ -95,7 +93,7 @@ public class TiledImage extends PlanarImage { this.minTileX = minTileX; this.minTileY = minTileY; this.tiles = tiles; - this.properties = (properties != null) ? JDK9.copyOf(properties) : Collections.emptyMap(); + this.properties = (properties != null) ? Map.copyOf(properties) : Map.of(); } /** diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/j2d/Wrapper.java b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/j2d/Wrapper.java index 33b9a44b62..63b7f46d6e 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/j2d/Wrapper.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/j2d/Wrapper.java @@ -17,6 +17,7 @@ package org.apache.sis.internal.feature.j2d; import java.util.List; +import java.util.Arrays; import java.util.Iterator; import java.util.function.BiPredicate; import java.awt.Shape; @@ -35,7 +36,6 @@ import org.apache.sis.internal.feature.GeometryWrapper; import org.apache.sis.internal.filter.sqlmm.SQLMM; import org.apache.sis.internal.referencing.j2d.ShapeUtilities; import org.apache.sis.internal.referencing.j2d.AbstractShape; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.util.ArraysExt; import org.apache.sis.util.Debug; @@ -328,7 +328,7 @@ add: for (;;) { case PathIterator.SEG_QUADTO: n=4; break; default: n=6; break; } - if (!JDK9.equals(p1, 0, n, p2, 0, n)) { + if (!Arrays.equals(p1, 0, n, p2, 0, n)) { return false; } } diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/ShapeConverter.java b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/ShapeConverter.java index c98cdad3dd..dd2ec5992f 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/ShapeConverter.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/jts/ShapeConverter.java @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.ArrayList; import java.awt.geom.PathIterator; import java.awt.geom.IllegalPathStateException; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.internal.referencing.j2d.AbstractShape; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryFactory; @@ -162,7 +161,7 @@ abstract class ShapeConverter { /** Returns a copy of current coordinate values as a JTS coordinate sequence. */ @Override PackedCoordinateSequence toSequence(final boolean close) { - if (close && !JDK9.equals(buffer, 0, 2, buffer, length - 2, length)) { + if (close && !Arrays.equals(buffer, 0, 2, buffer, length - 2, length)) { addPoint(buffer); } return new PackedCoordinateSequence.Double(buffer, length); @@ -208,7 +207,7 @@ abstract class ShapeConverter { /** Returns a copy of current coordinate values as a JTS coordinate sequence. */ @Override PackedCoordinateSequence toSequence(final boolean close) { - if (close && !JDK9.equals(buffer, 0, 2, buffer, length - 2, length)) { + if (close && !Arrays.equals(buffer, 0, 2, buffer, length - 2, length)) { addPoint(buffer); } return new PackedCoordinateSequence.Float(buffer, length); 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 30c198236c..bc401d52fb 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 @@ -16,6 +16,7 @@ */ package org.apache.sis.coverage.grid; +import java.util.Map; import java.util.Locale; import java.io.IOException; import org.opengis.geometry.Envelope; @@ -35,7 +36,6 @@ import org.apache.sis.referencing.operation.matrix.Matrix3; import org.apache.sis.referencing.crs.HardCodedCRS; import org.apache.sis.util.resources.Vocabulary; import org.apache.sis.internal.util.Numerics; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.test.TestCase; import org.junit.Test; @@ -357,7 +357,7 @@ public final strictfp class GridExtentTest extends TestCase { @Test public void testGetSubspaceDimensions() { final GridExtent extent = new GridExtent(null, new long[] {100, 5, 200, 40}, new long[] {500, 5, 800, 40}, true); - assertMapEquals(JDK9.mapOf(1, 5L, 3, 40L), extent.getSliceCoordinates()); + assertMapEquals(Map.of(1, 5L, 3, 40L), extent.getSliceCoordinates()); assertArrayEquals(new int[] {0, 2 }, extent.getSubspaceDimensions(2)); assertArrayEquals(new int[] {0,1,2 }, extent.getSubspaceDimensions(3)); assertArrayEquals(new int[] {0,1,2,3}, extent.getSubspaceDimensions(4)); diff --git a/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java b/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java index 70df514e1d..ebd28b8b9d 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/geometry/CoordinateFormat.java @@ -52,7 +52,6 @@ import org.apache.sis.internal.referencing.ReferencingUtilities; import org.apache.sis.internal.system.Loggers; import org.apache.sis.internal.util.LocalizedParseException; import org.apache.sis.internal.util.Numerics; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.math.DecimalFunctions; import org.apache.sis.util.logging.Logging; import org.apache.sis.util.resources.Errors; @@ -135,7 +134,7 @@ public class CoordinateFormat extends CompoundFormat<DirectPosition> { * For example if the unit of measurement of an axis is meter but the precision is 1000 metres, * then {@code CoordinateFormat} will automatically uses kilometres units instead of metres. */ - private static final Set<Unit<?>> SCALABLES = JDK9.setOf(Units.METRE, Units.PASCAL); + private static final Set<Unit<?>> SCALABLES = Set.of(Units.METRE, Units.PASCAL); /** * The separator between each coordinate values to be formatted. diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/CoordinateOperations.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/CoordinateOperations.java index daeef71fe4..018b5db1c0 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/CoordinateOperations.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/CoordinateOperations.java @@ -42,7 +42,6 @@ import org.apache.sis.internal.system.DefaultFactories; import org.apache.sis.internal.system.Modules; import org.apache.sis.internal.system.SystemListener; import org.apache.sis.internal.util.Numerics; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.util.Deprecable; import org.apache.sis.util.collection.Containers; @@ -293,7 +292,7 @@ public final class CoordinateOperations extends SystemListener { indices[i] = dim; r &= ~(1L << dim); } - final Set<Integer> dimensions = JDK9.setOf(indices); + final Set<Integer> dimensions = Set.of(indices); if (useCache) { synchronized (CACHE) { final Set<Integer> existing = CACHE[(int) changes]; diff --git a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTDictionary.java b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTDictionary.java index 050fd37a5c..a3397abd62 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTDictionary.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTDictionary.java @@ -46,7 +46,6 @@ import org.apache.sis.internal.referencing.WKTKeywords; import org.apache.sis.internal.util.CollectionsExt; import org.apache.sis.internal.util.Constants; import org.apache.sis.internal.util.Strings; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.metadata.iso.DefaultIdentifier; import org.apache.sis.metadata.iso.citation.Citations; import org.apache.sis.util.CharSequences; @@ -883,7 +882,7 @@ public class WKTDictionary extends GeodeticAuthorityFactory { public Set<String> getCodeSpaces() { lock.readLock().lock(); try { - return JDK9.copyOf(codespaces); + return Set.copyOf(codespaces); } finally { lock.readLock().unlock(); } diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java index a8e33e6ddd..ed26242904 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java @@ -75,7 +75,6 @@ import org.apache.sis.internal.system.SystemListener; import org.apache.sis.internal.system.Modules; import org.apache.sis.internal.system.Loggers; import org.apache.sis.internal.util.Constants; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.util.OptionalCandidate; import org.apache.sis.util.resources.Vocabulary; import org.apache.sis.util.resources.Errors; @@ -1869,7 +1868,7 @@ public enum CommonCRS { * <tr><th>Unit:</th> <td>{@link Units#PIXEL}</td></tr> * </table></blockquote> */ - GEODISPLAY(new DefaultEngineeringDatum(JDK9.mapOf( + GEODISPLAY(new DefaultEngineeringDatum(Map.of( EngineeringDatum.NAME_KEY, "Computer display", EngineeringDatum.ANCHOR_POINT_KEY, "Origin is in upper left."))), diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WKTKeywordsTest.java b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WKTKeywordsTest.java index 88c7aa0a88..1cbab2ca1a 100644 --- a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WKTKeywordsTest.java +++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WKTKeywordsTest.java @@ -21,7 +21,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import org.opengis.referencing.crs.*; import org.opengis.referencing.datum.*; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.test.TestCase; import org.junit.Test; @@ -83,10 +82,10 @@ public final strictfp class WKTKeywordsTest extends TestCase { */ @SafeVarargs private static <T> void verifyTypeHierarchy(final Class<T> base, final Class<? extends T>... subtypes) { - final Set<String> all = JDK9.setOf(WKTKeywords.forType(base)); + final Set<String> all = Set.of(WKTKeywords.forType(base)); assertNotNull(base.getName(), all); for (final Class<? extends T> subtype : subtypes) { - final Set<String> specialized = JDK9.setOf(WKTKeywords.forType(subtype)); + final Set<String> specialized = Set.of(WKTKeywords.forType(subtype)); final String name = subtype.getName(); assertNotNull(name, specialized); assertTrue(name, all.size() > specialized.size()); diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/HardCodedConversions.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/HardCodedConversions.java index 5d65d9e0d4..db00e7f5f4 100644 --- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/HardCodedConversions.java +++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/HardCodedConversions.java @@ -18,7 +18,6 @@ package org.apache.sis.referencing.operation; import java.util.Map; import java.util.Collections; -import org.apache.sis.internal.jdk9.JDK9; import org.opengis.parameter.ParameterValueGroup; import org.opengis.referencing.crs.GeographicCRS; import org.opengis.referencing.crs.ProjectedCRS; @@ -182,8 +181,8 @@ public final strictfp class HardCodedConversions { final DefaultConversion c = create("Lambert Conic Conformal", method, pg); final ImmutableIdentifier id = new ImmutableIdentifier(Citations.ESRI, "ESRI", "102110"); return new DefaultProjectedCRS( - JDK9.mapOf(ProjectedCRS.NAME_KEY, "RGF 1993 Lambert", - ProjectedCRS.IDENTIFIERS_KEY, id), + Map.of(ProjectedCRS.NAME_KEY, "RGF 1993 Lambert", + ProjectedCRS.IDENTIFIERS_KEY, id), HardCodedCRS.GRS80, c, HardCodedCS.PROJECTED); } diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/jdk9/JDK9.java b/core/sis-utility/src/main/java/org/apache/sis/internal/jdk9/JDK9.java index 8d89029b27..8a370de64c 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/internal/jdk9/JDK9.java +++ b/core/sis-utility/src/main/java/org/apache/sis/internal/jdk9/JDK9.java @@ -17,16 +17,8 @@ package org.apache.sis.internal.jdk9; import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.Set; import java.util.List; -import java.util.Collections; -import java.util.HashSet; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; import java.util.stream.Stream; -import org.apache.sis.internal.util.CollectionsExt; import org.apache.sis.internal.util.UnmodifiableArrayList; @@ -46,57 +38,6 @@ public final class JDK9 { private JDK9() { } - /** - * Placeholder for {@code Set.of(...)}. - * - * @param <E> type of elements. - * @param elements the elements to put in an unmodifiable set. - * @return an unmodifiable set of the given elements. - */ - @SafeVarargs - public static <E> Set<E> setOf(final E... elements) { - switch (elements.length) { - case 0: return Collections.emptySet(); - case 1: return Collections.singleton(elements[0]); - } - final Set<E> c = new LinkedHashSet<>(Arrays.asList(elements)); - if (c.size() != elements.length) { - throw new IllegalArgumentException("Duplicated elements."); - } - return Collections.unmodifiableSet(c); - } - - /** - * Placeholder for {@code Map.of(...)}. - */ - public static <K,V> Map<K,V> mapOf(final Object... entries) { - final Map map = new HashMap(); - for (int i=0; i<entries.length;) { - if (map.put(entries[i++], entries[i++]) != null) { - throw new IllegalArgumentException("Duplicated elements."); - } - } - return map; - } - - /** - * Placeholder for {@code Set.copyOf(...)} (actually a JDK10 method). - */ - public static <V> Set<V> copyOf(final Set<V> set) { - switch (set.size()) { - case 0: return Collections.emptySet(); - case 1: return Collections.singleton(set.iterator().next()); - default: return new HashSet<>(set); - } - } - - /** - * Placeholder for {@code Map.copyOf(...)} (actually a JDK10 method). - */ - public static <K,V> Map<K,V> copyOf(final Map<K,V> map) { - return map.size() < 2 ? CollectionsExt.compact(map) : new HashMap<>(map); - } - /** * Place holder for {@code ByteBuffer.get(int, byte[])}. * @@ -123,132 +64,6 @@ public final class JDK9 { } } - /** - * Place holder for {@link java.util.Arrays} method added in JDK9. - * This placeholder does not perform range check (JDK9 method does). - */ - public static boolean equals(final char[] a, int ai, final int aUp, - final char[] b, int bi, final int bUp) - { - if (aUp - ai != bUp - bi) { - return false; - } - while (ai < aUp) { - if (a[ai++] != b[bi++]) { - return false; - } - } - return true; - } - - /** - * Place holder for {@link java.util.Arrays} method added in JDK9. - * This placeholder does not perform range check (JDK9 method does). - */ - public static boolean equals(final byte[] a, int ai, final int aUp, - final byte[] b, int bi, final int bUp) - { - if (aUp - ai != bUp - bi) { - return false; - } - while (ai < aUp) { - if (a[ai++] != b[bi++]) { - return false; - } - } - return true; - } - - /** - * Place holder for {@link java.util.Arrays} method added in JDK9. - * This placeholder does not perform range check (JDK9 method does). - */ - public static boolean equals(final short[] a, int ai, final int aUp, - final short[] b, int bi, final int bUp) - { - if (aUp - ai != bUp - bi) { - return false; - } - while (ai < aUp) { - if (a[ai++] != b[bi++]) { - return false; - } - } - return true; - } - - /** - * Place holder for {@link java.util.Arrays} method added in JDK9. - * This placeholder does not perform range check (JDK9 method does). - */ - public static boolean equals(final int[] a, int ai, final int aUp, - final int[] b, int bi, final int bUp) - { - if (aUp - ai != bUp - bi) { - return false; - } - while (ai < aUp) { - if (a[ai++] != b[bi++]) { - return false; - } - } - return true; - } - - /** - * Place holder for {@link java.util.Arrays} method added in JDK9. - * This placeholder does not perform range check (JDK9 method does). - */ - public static boolean equals(final long[] a, int ai, final int aUp, - final long[] b, int bi, final int bUp) - { - if (aUp - ai != bUp - bi) { - return false; - } - while (ai < aUp) { - if (a[ai++] != b[bi++]) { - return false; - } - } - return true; - } - - /** - * Place holder for {@link java.util.Arrays} method added in JDK9. - * This placeholder does not perform range check (JDK9 method does). - */ - public static boolean equals(final float[] a, int ai, final int aUp, - final float[] b, int bi, final int bUp) - { - if (aUp - ai != bUp - bi) { - return false; - } - while (ai < aUp) { - if (Float.floatToIntBits(a[ai++]) != Float.floatToIntBits(b[bi++])) { - return false; - } - } - return true; - } - - /** - * Place holder for {@link java.util.Arrays} method added in JDK9. - * This placeholder does not perform range check (JDK9 method does). - */ - public static boolean equals(final double[] a, int ai, final int aUp, - final double[] b, int bi, final int bUp) - { - if (aUp - ai != bUp - bi) { - return false; - } - while (ai < aUp) { - if (Double.doubleToLongBits(a[ai++]) != Double.doubleToLongBits(b[bi++])) { - return false; - } - } - return true; - } - /** * Place holder for {@link Stream#toList()} method added in JDK16. */ diff --git a/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java b/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java index a2c32d8043..d4a5e5eb9a 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java +++ b/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java @@ -33,7 +33,6 @@ import org.apache.sis.util.ArraysExt; import org.apache.sis.util.resources.Errors; import org.apache.sis.util.collection.CheckedContainer; import org.apache.sis.internal.util.Numerics; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.measure.NumberRange; @@ -281,7 +280,7 @@ abstract class ArrayVector<E extends Number> extends Vector implements CheckedCo /** Returns whether this vector in the given range is equal to the specified vector. */ @Override boolean equals(final int lower, final int upper, final Vector other, final int otherOffset) { if (other instanceof Doubles) { - return JDK9.equals(array, lower, upper, + return Arrays.equals(array, lower, upper, ((Doubles) other).array, otherOffset, otherOffset + (upper - lower)); } return super.equals(lower, upper, other, otherOffset); @@ -401,7 +400,7 @@ abstract class ArrayVector<E extends Number> extends Vector implements CheckedCo /** Returns whether this vector in the given range is equal to the specified vector. */ @Override final boolean equals(final int lower, final int upper, final Vector other, final int otherOffset) { if (other.getClass() == getClass()) { - return JDK9.equals(array, lower, upper, + return Arrays.equals(array, lower, upper, ((Floats) other).array, otherOffset, otherOffset + (upper - lower)); } return super.equals(lower, upper, other, otherOffset); @@ -561,7 +560,7 @@ abstract class ArrayVector<E extends Number> extends Vector implements CheckedCo /** Returns whether this vector in the given range is equal to the specified vector. */ @Override final boolean equals(final int lower, final int upper, final Vector other, final int otherOffset) { if (other.getClass() == getClass()) { - return JDK9.equals(array, lower, upper, + return Arrays.equals(array, lower, upper, ((Longs) other).array, otherOffset, otherOffset + (upper - lower)); } return super.equals(lower, upper, other, otherOffset); @@ -691,7 +690,7 @@ abstract class ArrayVector<E extends Number> extends Vector implements CheckedCo /** Returns whether this vector in the given range is equal to the specified vector. */ @Override final boolean equals(final int lower, final int upper, final Vector other, final int otherOffset) { if (other.getClass() == getClass()) { - return JDK9.equals(array, lower, upper, + return Arrays.equals(array, lower, upper, ((Integers) other).array, otherOffset, otherOffset + (upper - lower)); } return super.equals(lower, upper, other, otherOffset); @@ -825,7 +824,7 @@ abstract class ArrayVector<E extends Number> extends Vector implements CheckedCo /** Returns whether this vector in the given range is equal to the specified vector. */ @Override final boolean equals(final int lower, final int upper, final Vector other, final int otherOffset) { if (other.getClass() == getClass()) { - return JDK9.equals(array, lower, upper, + return Arrays.equals(array, lower, upper, ((Shorts) other).array, otherOffset, otherOffset + (upper - lower)); } return super.equals(lower, upper, other, otherOffset); @@ -934,7 +933,7 @@ abstract class ArrayVector<E extends Number> extends Vector implements CheckedCo /** Returns whether this vector in the given range is equal to the specified vector. */ @Override final boolean equals(int lower, final int upper, final Vector other, int otherOffset) { if (other.getClass() == getClass()) { - return JDK9.equals(array, lower, upper, + return Arrays.equals(array, lower, upper, ((Bytes) other).array, otherOffset, otherOffset + (upper - lower)); } return super.equals(lower, upper, other, otherOffset); diff --git a/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java b/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java index 759d58d1ec..ef37c021f1 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java +++ b/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java @@ -162,9 +162,9 @@ public abstract class Vector extends AbstractList<Number> implements RandomAcces public static Vector create(final double[] array) { /* * NOTE: we do not use variable-length argument (double...) because doing so may force us to - * declare 'create' methods for all other primitive types, otherwise some developers may be - * surprised that 'create(0, 1, 2, 3)' converts the integer values to doubles. We do not yet - * provide explicit 'create(...)' methods for other primitive types because it is not needed + * declare `create` methods for all other primitive types, otherwise some developers may be + * surprised that `create(0, 1, 2, 3)` converts the integer values to doubles. We do not yet + * provide explicit `create(...)` methods for other primitive types because it is not needed * by Apache SIS and it would lost a feature of current API, which is to force developers to * think whether their integers are signed or unsigned. */ @@ -650,7 +650,7 @@ public abstract class Vector extends AbstractList<Number> implements RandomAcces /* * For the first level of repetitions, we rely on a method to be overridden by subclasses * for detecting the length of consecutive identical numbers. We could have used the more - * generic algorithm based on 'equals(int, int, Vector, int)' instead, but this approach + * generic algorithm based on `equals(int, int, Vector, int)` instead, but this approach * is faster. */ int r0 = 0; @@ -667,7 +667,7 @@ public abstract class Vector extends AbstractList<Number> implements RandomAcces * and shall not be modified anymore for the rest of this method. This is the first integer value in the * array to be returned. Following algorithm applies to deeper levels. * - * The 'skip' variable is an optimization. Code below would work with skip = 0 all the times, but this is + * The `skip` variable is an optimization. Code below would work with skip = 0 all the times, but this is * very slow when r0 = 1 because equals(…) is invoked for all values. Computing an amount of values that * we can skip in the special case where r0 = 1 increases the speed a lot. */ @@ -690,11 +690,11 @@ search: for (;;) { if (skip != 0) { /* * Optimization for reducing the number of method calls when r0 = 1: the default algorithm is to - * search for a position multiple of 'r0' where all values since the beginning of the vector are - * repeated. But if 'r0' is 1, the default algorithms perform a costly check at every positions. - * To avoid that, we use 'indexOf' for searching the index of the next position where a match may + * search for a position multiple of `r0` where all values since the beginning of the vector are + * repeated. But if `r0` is 1, the default algorithms perform a costly check at every positions. + * To avoid that, we use `indexOf` for searching the index of the next position where a match may * exist (we don't care anymore about multiples of r0 since r0 is 1). If the first expected values - * are constants, we use 'indexOf' again for checking efficiently those constants. + * are constants, we use `indexOf` again for checking efficiently those constants. */ r = indexOf(0, r, true); if (skip != 1) { @@ -708,10 +708,11 @@ search: for (;;) { } if (r >= size) break; } - if (equals(skip, Math.min(r0, size - r), this, r + skip)) { + final int base = Math.min(r0, size - r); + if (base < skip || equals(skip, base, this, r + skip)) { /* - * Found a possible repetition of length r. Verify if this repetition pattern is observed until - * the end of the vector. If not, we will search for the next possible repetition. + * Found a possible repetition of length r. Verify if this repetition pattern is observed + * until the end of the vector. If not, we will search for the next possible repetition. */ for (int i=r; i<size; i += r) { if (!equals(0, Math.min(r, size - i), this, i)) { @@ -773,7 +774,7 @@ search: for (;;) { final int type = Numbers.getEnumConstant(getElementType()); /* * For integer types, verify if the increment is constant. We do not use the "first + inc*i" - * formula because some 'long' values cannot be represented accurately as 'double' values. + * formula because some `long` values cannot be represented accurately as `double` values. * The result will be converted to the same type than the vector element type if possible, * or the next wider type if the increment is an unsigned value too big for the element type. */ @@ -818,7 +819,7 @@ search: for (;;) { final float value = floatValue(i); final double delta = Math.abs(first + inc*i-- - value); final double accur = Math.ulp(value); - if (!((accur > tolerance) ? (delta < accur) : (delta <= tolerance))) { // Use '!' for catching NaN. + if (!((accur > tolerance) ? (delta < accur) : (delta <= tolerance))) { // Use `!` for catching NaN. return null; } } @@ -827,7 +828,7 @@ search: for (;;) { } else { while (i >= 1) { final double delta = Math.abs(first + inc*i - doubleValue(i--)); - if (!(delta <= tolerance)) { // Use '!' for catching NaN. + if (!(delta <= tolerance)) { // Use `!` for catching NaN. return null; } } @@ -1419,8 +1420,8 @@ search: for (;;) { return createSequence(getElementType(), get(0), inc, length); } /* - * Verify if the vector contains only NaN values. This extra check is useful because 'increment()' - * returns null if the array contains NaN. Note that for array of integers, 'isNaN(int)' is very + * Verify if the vector contains only NaN values. This extra check is useful because `increment()` + * returns null if the array contains NaN. Note that for array of integers, `isNaN(int)` is very * efficient and the loop will stop immediately after the first iteration. */ int i = 0; @@ -1670,6 +1671,7 @@ search: for (;;) { * @param other the other vector to compare values with this vector. May be {@code this}. * @param otherOffset index of the first element to compare in the other vector. * @return whether values over the specified range of the two vectors are equal. + * @throws IllegalArgumentException if {@code lower} is greater than {@code upper}. */ boolean equals(int lower, final int upper, final Vector other, int otherOffset) { while (lower < upper) { diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/collection/IntegerList.java b/core/sis-utility/src/main/java/org/apache/sis/util/collection/IntegerList.java index ced2161d52..c15e26d80e 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/util/collection/IntegerList.java +++ b/core/sis-utility/src/main/java/org/apache/sis/util/collection/IntegerList.java @@ -32,7 +32,6 @@ import java.io.Serializable; import java.io.ObjectOutputStream; import org.apache.sis.util.ArraysExt; import org.apache.sis.util.ArgumentChecks; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.internal.util.Numerics; @@ -701,7 +700,7 @@ public class IntegerList extends AbstractList<Integer> implements RandomAccess, int n = size * bitCount; final int nr = n & OFFSET_MASK; // Number of remaining values. n >>>= BASE_SHIFT; - if (!JDK9.equals(values, 0, n, that.values, 0, n)) { + if (!Arrays.equals(values, 0, n, that.values, 0, n)) { return false; } if (nr == 0) return true; diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java index 3c05da7641..cf36e097d4 100644 --- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java +++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java @@ -33,7 +33,6 @@ import ucar.nc2.constants.CF; import ucar.nc2.constants.CDM; import ucar.nc2.constants._Coordinate; import org.apache.sis.coverage.grid.GridExtent; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.internal.netcdf.Decoder; import org.apache.sis.internal.netcdf.DataType; import org.apache.sis.internal.netcdf.Dimension; @@ -796,7 +795,7 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo> { for (int j=upper; --j >= lower;) { if (Byte.toUnsignedInt(chars[j]) > ' ') { while (Byte.toUnsignedInt(chars[lower]) <= ' ') lower++; - if (JDK9.equals(chars, lower, ++j, chars, plo, phi)) { + if (Arrays.equals(chars, lower, ++j, chars, plo, phi)) { element = previous; } else { element = new String(chars, lower, j - lower, encoding); diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java index bc7da531ec..26d4fe7f8f 100644 --- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java +++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java @@ -18,6 +18,7 @@ package org.apache.sis.internal.netcdf.ucar; import java.util.Map; import java.util.List; +import java.util.Arrays; import java.util.ArrayList; import java.util.Collection; import java.io.File; @@ -47,7 +48,6 @@ import org.apache.sis.internal.netcdf.Decoder; import org.apache.sis.internal.netcdf.Grid; import org.apache.sis.internal.netcdf.GridAdjustment; import org.apache.sis.internal.util.Strings; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.storage.DataStoreException; import org.apache.sis.measure.MeasurementRange; import org.apache.sis.measure.NumberRange; @@ -575,7 +575,7 @@ final class VariableWrapper extends org.apache.sis.internal.netcdf.Variable { for (int j=upper; --j >= lower;) { if (chars[j] > ' ') { while (chars[lower] <= ' ') lower++; - if (JDK9.equals(chars, lower, ++j, chars, plo, phi)) { + if (Arrays.equals(chars, lower, ++j, chars, plo, phi)) { element = previous; } else { element = new String(chars, lower, j - lower); diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/StoreUtilities.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/StoreUtilities.java index 11e580bfdf..c0a2bdc77d 100644 --- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/StoreUtilities.java +++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/StoreUtilities.java @@ -45,7 +45,6 @@ import org.apache.sis.storage.WritableFeatureSet; import org.apache.sis.storage.UnsupportedStorageException; import org.apache.sis.storage.event.StoreListeners; import org.apache.sis.geometry.GeneralEnvelope; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.internal.metadata.Identifiers; import org.apache.sis.internal.system.Modules; import org.apache.sis.util.resources.Errors; @@ -95,7 +94,7 @@ public final class StoreUtilities extends Static { * * @see #basedOnASCII(Charset) */ - private static final Set<String> basedOnASCII = JDK9.setOf("US-ASCII", "ISO-8859-1", "UTF-8"); + private static final Set<String> basedOnASCII = Set.of("US-ASCII", "ISO-8859-1", "UTF-8"); /** * Do not allow instantiation of this class. diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java index 8e89dbae11..ab90b1c4b7 100644 --- a/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java +++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/event/StoreListeners.java @@ -36,7 +36,6 @@ import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.logging.Logging; import org.apache.sis.util.resources.Vocabulary; import org.apache.sis.util.collection.Containers; -import org.apache.sis.internal.jdk9.JDK9; import org.apache.sis.internal.system.Modules; import org.apache.sis.internal.storage.Resources; import org.apache.sis.internal.storage.StoreResource; @@ -122,7 +121,7 @@ public class StoreListeners implements Localized { * @see #useReadOnlyEvents() */ private static final Set<Class<? extends StoreEvent>> READ_EVENT_TYPES = - JDK9.setOf(WarningEvent.class, CloseEvent.class); + Set.of(WarningEvent.class, CloseEvent.class); /** * The {@link CascadedStoreEvent.ParentListener}s registered on {@link #parent}.