sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: Small initial round of cleanup for JDK 9 (no modularization yet).
Date Wed, 15 Aug 2018 13:13:36 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch JDK9
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 149b67ad998c6a29fac5a47fb2c9a5c2695be5a8
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Aug 13 11:24:21 2018 +0200

    Small initial round of cleanup for JDK 9 (no modularization yet).
---
 .../main/java/org/apache/sis/xml/TransformingNamespaces.java |  2 --
 .../src/main/java/org/apache/sis/xml/TransformingReader.java |  1 -
 .../src/main/java/org/apache/sis/xml/TransformingWriter.java |  1 -
 .../java/org/apache/sis/xml/TransformingNamespacesTest.java  |  1 -
 .../org/apache/sis/coverage/grid/GridCoordinatesView.java    | 12 ++----------
 .../src/main/java/org/apache/sis/internal/jdk9/JDK9.java     |  2 ++
 .../java/org/apache/sis/internal/util/FinalFieldSetter.java  |  4 ++--
 .../src/main/java/org/apache/sis/math/Fraction.java          |  4 ++--
 .../main/java/org/apache/sis/measure/LinearConverter.java    |  3 +--
 .../java/org/apache/sis/measure/LinearConverterTest.java     |  1 -
 .../java/org/apache/sis/storage/sql/SQLStoreProvider.java    |  5 +----
 11 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingNamespaces.java
b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingNamespaces.java
index e80e0f4..ac97303 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingNamespaces.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingNamespaces.java
@@ -147,7 +147,6 @@ class TransformingNamespaces implements NamespaceContext {
          * many prefixes can be created from the same namespace.</p>
          */
         @Override
-        @SuppressWarnings("unchecked")      // TODO: remove with JDK9
         public Iterator<String> getPrefixes(final String namespaceURI) {
             return context.getPrefixes(version.exportNS(namespaceURI));
         }
@@ -232,7 +231,6 @@ class TransformingNamespaces implements NamespaceContext {
          * Invoking this method fetched at most one prefix from the wrapped context.
          */
         @Override
-        @SuppressWarnings("unchecked")          // TODO: remove on JDK9
         public boolean hasNext() {
             while (next == null) {
                 while (prefixes == null) {
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingReader.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingReader.java
index 34a0a1f..cc5d34d 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingReader.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingReader.java
@@ -209,7 +209,6 @@ final class TransformingReader extends Transformer implements XMLEventReader
{
      * @param  event  the event read from the underlying event reader.
      * @return the converted event (may be the same instance).
      */
-    @SuppressWarnings("unchecked")      // TODO: remove on JDK9
     private XMLEvent convert(XMLEvent event) throws XMLStreamException {
         switch (event.getEventType()) {
             case ATTRIBUTE: {
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java
index ca570d2..601ca00 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java
@@ -338,7 +338,6 @@ final class TransformingWriter extends Transformer implements XMLEventWriter
{
      * @param  event  the event using JAXB namespaces.
      */
     @Override
-    @SuppressWarnings("unchecked")      // TODO: remove on JDK9
     public void add(XMLEvent event) throws XMLStreamException {
         switch (event.getEventType()) {
             case ATTRIBUTE: {
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/xml/TransformingNamespacesTest.java
b/core/sis-metadata/src/test/java/org/apache/sis/xml/TransformingNamespacesTest.java
index 57708a2..d433dab 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/xml/TransformingNamespacesTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/xml/TransformingNamespacesTest.java
@@ -50,7 +50,6 @@ public final strictfp class TransformingNamespacesTest extends TestCase
implemen
      * Tests {@link TransformingNamespaces#getPrefixes(String)}.
      */
     @Test
-    @SuppressWarnings("unchecked")      // TODO: remove with JDK9
     public void testGetPrefixes() {
         final NamespaceContext fns = TransformingNamespaces.asXML(this, TransformVersion.ISO19139);
         final Iterator<String> it = fns.getPrefixes(LegacyNamespaces.GMD);
diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java
index 3e68c4e..d9e7c4e 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java
@@ -120,16 +120,8 @@ final class GridCoordinatesView /* implements GridCoordinates */ {
          */
         if (object instanceof GridCoordinatesView) {
             final GridCoordinatesView that = (GridCoordinatesView) object;
-            final int dimension = getDimension();
-            if (dimension == that.getDimension()) {
-                // TODO: use Arrays.equals(...) with JDK9 instead.
-                for (int i=0; i<dimension; i++) {
-                    if (ordinates[offset + i] != that.ordinates[that.offset + i]) {
-                        return false;
-                    }
-                }
-                return true;
-            }
+            return Arrays.equals(this.ordinates, this.offset, this.offset + this.getDimension(),
+                                 that.ordinates, that.offset, that.offset + that.getDimension());
         }
         return false;
     }
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 8f20a5d..0f71fed 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
@@ -62,6 +62,8 @@ public final class JDK9 {
      * @param  <E>       type of elements.
      * @param  elements  the elements to put in an unmodifiable set.
      * @return an unmodifiable set of the given elements.
+     *
+     * @todo before to replace by JDK9 method, verify if order is preserved.
      */
     @SafeVarargs
     public static <E> Set<E> setOf(final E... elements) {
diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/util/FinalFieldSetter.java
b/core/sis-utility/src/main/java/org/apache/sis/internal/util/FinalFieldSetter.java
index 929767a..9212f89 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/util/FinalFieldSetter.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/util/FinalFieldSetter.java
@@ -17,6 +17,7 @@
 package org.apache.sis.internal.util;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.InaccessibleObjectException;
 import java.io.InvalidClassException;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -151,7 +152,6 @@ public final class FinalFieldSetter<T> implements PrivilegedAction<FinalFieldSet
      * @return the exception to throw.
      */
     public static RuntimeException cloneFailure(final ReflectiveOperationException cause)
{
-        return new RuntimeException(cause);
-        // TODO: use InaccessibleObjectException in JDK9.
+        return (InaccessibleObjectException) new InaccessibleObjectException().initCause(cause);
     }
 }
diff --git a/core/sis-utility/src/main/java/org/apache/sis/math/Fraction.java b/core/sis-utility/src/main/java/org/apache/sis/math/Fraction.java
index 92846f5..e529914 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/math/Fraction.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/math/Fraction.java
@@ -527,8 +527,8 @@ public final class Fraction extends Number implements Comparable<Fraction>,
Seri
                 case '⁄':
                 case '/':
                 case '∕': {
-                    numerator   = Integer.parseInt(s.substring(0,i));       // TODO: revisit
with JDK9.
-                    denominator = Integer.parseInt(s.substring(i+1));
+                    numerator   = Integer.parseInt(s, 0, i, 10);
+                    denominator = Integer.parseInt(s, i+1, length, 10);
                     return;
                 }
             }
diff --git a/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java b/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java
index e5b6863..ccf4a8e 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java
@@ -281,8 +281,7 @@ final class LinearConverter extends AbstractConverter implements LenientComparab
      */
     @Override
     public double convert(final double value) {
-        // TODO: use JDK9' Math.fma(…) and verify if it solve the accuracy issue in LinearConverterTest.inverse().
-        return (value * scale + offset) / divisor;
+        return Math.fma(value, scale, offset) / divisor;
     }
 
     /**
diff --git a/core/sis-utility/src/test/java/org/apache/sis/measure/LinearConverterTest.java
b/core/sis-utility/src/test/java/org/apache/sis/measure/LinearConverterTest.java
index c4b3ca0..401c244 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/measure/LinearConverterTest.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/measure/LinearConverterTest.java
@@ -177,7 +177,6 @@ public final strictfp class LinearConverterTest extends TestCase {
         c = LinearConverter.offset(27315, 100);
         inv = (LinearConverter) c.inverse();
         assertEquals(12.3, c.convert(inv.convert(12.3)), 1E-13);
-        // TODO: use JDK9' Math.fma(…) in LinearConverter.convert(double) and verify if
it solve the accuracy issue.
     }
 
     /**
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java
index a03a1b2..0cdacde 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java
@@ -17,7 +17,6 @@
 package org.apache.sis.storage.sql;
 
 import java.util.Map;
-import java.util.HashMap;
 import java.sql.Connection;
 import java.sql.SQLException;
 import javax.sql.DataSource;
@@ -144,9 +143,7 @@ public class SQLStoreProvider extends DataStoreProvider {
         final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
         NameSpace ns = tableNS;
         if (ns == null) {
-            final Map<String,String> properties = new HashMap<>(4);     // TODO:
use Map.of with JDK9.
-            properties.put("separator",      ".");
-            properties.put("separator.head", ":");
+            final Map<String,String> properties = Map.of("separator", ".", "separator.head",
":");
             tableNS = ns = factory.createNameSpace(factory.createLocalName(null, "database"),
properties);
         }
         return factory.createGenericName(ns, names);


Mime
View raw message