sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1799686 - in /sis/branches/JDK8: application/sis-console/src/main/java/org/apache/sis/console/ core/sis-feature/src/test/java/org/apache/sis/feature/ core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ core/sis-referenci...
Date Fri, 23 Jun 2017 16:43:00 GMT
Author: desruisseaux
Date: Fri Jun 23 16:43:00 2017
New Revision: 1799686

URL: http://svn.apache.org/viewvc?rev=1799686&view=rev
Log:
Define constants for conversions between seconds, milliseconds and nanoseconds (for clarity),
and other minor editions.

Modified:
    sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/AboutCommand.java
    sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureMemoryBenchmark.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/Benchmark.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorMethodComparison.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StandardDateFormat.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/StandardDateFormatTest.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/TimeEncoding.java

Modified: sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/AboutCommand.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/AboutCommand.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/AboutCommand.java
[UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/AboutCommand.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -28,7 +28,6 @@ import javax.management.MBeanServerConne
 import javax.management.remote.JMXServiceURL;
 import javax.management.remote.JMXConnector;
 import javax.management.remote.JMXConnectorFactory;
-import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.setup.About;
 import org.apache.sis.util.Version;
 import org.apache.sis.util.logging.Logging;
@@ -37,8 +36,10 @@ import org.apache.sis.util.resources.Mes
 import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.util.collection.TreeTable;
 import org.apache.sis.util.collection.TableColumn;
+import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.system.Supervisor;
 import org.apache.sis.internal.system.SupervisorMBean;
+import org.apache.sis.internal.util.StandardDateFormat;
 import org.apache.sis.internal.util.X364;
 
 
@@ -135,7 +136,7 @@ final class AboutCommand extends Command
                  * Logs a message telling how long it took to receive the reply.
                  * Sometime the delay gives a hint about the server charge.
                  */
-                double delay = (System.nanoTime() - time) / 1E+9;   // In seconds.
+                double delay = (System.nanoTime() - time) / (double) StandardDateFormat.NANOS_PER_SECOND;
  // In seconds.
                 if (delay >= 0.1) {
                     final double scale = (delay >= 10) ? 1 : (delay >= 1) ? 10 : 100;
                     delay = Math.rint(delay * scale) / scale;

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureMemoryBenchmark.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureMemoryBenchmark.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureMemoryBenchmark.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/feature/FeatureMemoryBenchmark.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Random;
 import org.opengis.feature.Feature;
+import org.apache.sis.internal.util.StandardDateFormat;
 
 import static java.util.Collections.singletonMap;
 
@@ -179,7 +180,7 @@ public final class FeatureMemoryBenchmar
                 long time = System.nanoTime();
                 b.run();
                 time = System.nanoTime() - time;
-                System.console().printf("Ellapsed time: %f%n", time / 1E+9);
+                System.console().printf("Ellapsed time: %f%n", time / (float) StandardDateFormat.NANOS_PER_SECOND);
                 return;
             }
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -56,6 +56,7 @@ import org.apache.sis.internal.system.De
 import org.apache.sis.internal.system.Shutdown;
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.util.CollectionsExt;
+import org.apache.sis.internal.util.StandardDateFormat;
 import org.apache.sis.util.logging.PerformanceLevel;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Messages;
@@ -189,7 +190,7 @@ public abstract class ConcurrentAuthorit
                 value = depth;
             } else {
                 text = "%s made available %d seconds ago";
-                value = Math.round((System.nanoTime() - timestamp) / 1E+9);   // Convert
nanoseconds to seconds.
+                value = Math.round((System.nanoTime() - timestamp) / (double) StandardDateFormat.NANOS_PER_SECOND);
             }
             return String.format(text, Classes.getShortClassName(factory), value);
         }
@@ -447,8 +448,8 @@ public abstract class ConcurrentAuthorit
                 if (caller == null) {
                     caller = "create".concat(type.getSimpleName());
                 }
-                final Double duration = time / 1E+9;
                 final PerformanceLevel level = PerformanceLevel.forDuration(time, TimeUnit.NANOSECONDS);
+                final Double duration = time / (double) StandardDateFormat.NANOS_PER_SECOND;
                 final Messages resources = Messages.getResources(null);
                 final LogRecord record;
                 if (code != null) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -30,6 +30,7 @@ import org.apache.sis.util.StringBuilder
 import org.apache.sis.internal.metadata.sql.ScriptRunner;
 import org.apache.sis.internal.metadata.sql.SQLUtilities;
 import org.apache.sis.internal.system.DefaultFactories;
+import org.apache.sis.internal.util.StandardDateFormat;
 import org.apache.sis.internal.util.Fallback;
 import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.resources.Messages;
@@ -249,7 +250,7 @@ final class EPSGInstaller extends Script
         time = System.nanoTime() - time;
         InstallationScriptProvider.log(Messages.getResources(locale).getLogRecord(
                 PerformanceLevel.forDuration(time, TimeUnit.NANOSECONDS),
-                Messages.Keys.InsertDuration_2, numRows, time / 1E9f));
+                Messages.Keys.InsertDuration_2, numRows, time / (float) StandardDateFormat.NANOS_PER_SECOND));
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/Benchmark.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/Benchmark.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/Benchmark.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/Benchmark.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -28,6 +28,7 @@ import org.apache.sis.math.StatisticsFor
 import org.apache.sis.measure.Latitude;
 import org.apache.sis.parameter.Parameters;
 import org.apache.sis.internal.util.Constants;
+import org.apache.sis.internal.util.StandardDateFormat;
 import org.apache.sis.internal.referencing.provider.AbstractProvider;
 import org.apache.sis.referencing.operation.transform.LinearTransform;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
@@ -216,7 +217,7 @@ public final class Benchmark {
             long time = System.nanoTime();
             projection.transform(sources, 0, targets, 0, NUM_POINTS);
             time = System.nanoTime() - time;
-            final double seconds = time * NANOS_TO_SECONDS;
+            final double seconds = time / (double) StandardDateFormat.NANOS_PER_SECOND;
             System.out.printf("%s time: %1.4f%n", performance.name(), seconds);
             performance.accept(seconds);
         }
@@ -231,15 +232,10 @@ public final class Benchmark {
             kernel.transform(targets, 0, targets, 0, NUM_POINTS);
             time = System.nanoTime() - time;
             denormalize.transform(targets, 0, targets, 0, NUM_POINTS);
-            final double seconds = time * NANOS_TO_SECONDS;
+            final double seconds = time / (double) StandardDateFormat.NANOS_PER_SECOND;
             System.out.printf("%s time: %1.4f%n", performance.name(), seconds);
             performance.accept(seconds);
         }
-
-        /**
-         * For reporting the time measured by {@link System#nanoTime()}.
-         */
-        private static final double NANOS_TO_SECONDS = 1E-9;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorMethodComparison.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorMethodComparison.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorMethodComparison.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorMethodComparison.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -27,6 +27,7 @@ import org.apache.sis.internal.referenci
 import org.apache.sis.internal.metadata.ReferencingServices;
 
 import static java.lang.Math.*;     // Not StrictMath in this particular case.
+import static org.apache.sis.internal.util.StandardDateFormat.NANOS_PER_SECOND;
 
 
 /**
@@ -323,9 +324,9 @@ public final class MercatorMethodCompari
         }
         final long t3 = System.nanoTime();
         final float c = (t1 - t0) / 100f;
-        out.println("Iterative method:         " + ((t1 - t0) / 1E9f) + " seconds (" + round((t1
- t0) / c) + "%).");
-        out.println("Series expansion:         " + ((t2 - t1) / 1E9f) + " seconds (" + round((t2
- t1) / c) + "%).");
-        out.println("Trigonometric identities: " + ((t3 - t2) / 1E9f) + " seconds (" + round((t3
- t2) / c) + "%).");
+        out.println("Iterative method:         " + ((t1 - t0) / (float) NANOS_PER_SECOND)
+ " seconds (" + round((t1 - t0) / c) + "%).");
+        out.println("Series expansion:         " + ((t2 - t1) / (float) NANOS_PER_SECOND)
+ " seconds (" + round((t2 - t1) / c) + "%).");
+        out.println("Trigonometric identities: " + ((t3 - t2) / (float) NANOS_PER_SECOND)
+ " seconds (" + round((t3 - t2) / c) + "%).");
         out.println("Mean φ values: " + (s0 / t.length) + ", "
                                       + (s1 / t.length) + " and "
                                       + (s2 / t.length) + ".");

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StandardDateFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StandardDateFormat.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StandardDateFormat.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StandardDateFormat.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -132,6 +132,16 @@ public final class StandardDateFormat ex
     public static final int MILLISECONDS_PER_DAY = 24*60*60*1000;
 
     /**
+     * Number of nanoseconds in one millisecond.
+     */
+    public static final long NANOS_PER_MILLISECOND = 1000000;
+
+    /**
+     * Number of nanoseconds in one second.
+     */
+    public static final long NANOS_PER_SECOND = 1000000000;
+
+    /**
      * Converts the given legacy {@code Date} object into a {@code java.time} implementation
in given timezone.
      * The method performs the following choice:
      *

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/StandardDateFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/StandardDateFormatTest.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/StandardDateFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/util/StandardDateFormatTest.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -17,6 +17,7 @@
 package org.apache.sis.internal.util;
 
 import java.util.Date;
+import java.util.concurrent.TimeUnit;
 import java.text.ParseException;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -40,6 +41,17 @@ import java.time.LocalDateTime;
  */
 public final strictfp class StandardDateFormatTest extends TestCase {
     /**
+     * Verifies the {@link StandardDateFormat#MILLISECONDS_PER_DAY}, {@link StandardDateFormat#NANOS_PER_MILLISECOND}
+     * and {@link StandardDateFormat#NANOS_PER_SECOND} constant values.
+     */
+    @Test
+    public void verifyConstantValues() {
+        assertEquals("MILLISECONDS_PER_DAY",  TimeUnit.DAYS.toMillis(1),        StandardDateFormat.MILLISECONDS_PER_DAY);
+        assertEquals("NANOS_PER_MILLISECOND", TimeUnit.MILLISECONDS.toNanos(1), StandardDateFormat.NANOS_PER_MILLISECOND);
+        assertEquals("NANOS_PER_SECOND",      TimeUnit.SECONDS.toNanos(1),      StandardDateFormat.NANOS_PER_SECOND);
+    }
+
+    /**
      * Tests parsing a date.
      * Since the implementation is completely different in JDK8 branch than in previous branch,
      * a key purpose of this test is to ensure that the parsing is consistent between the
branches.

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -25,6 +25,7 @@ import java.io.PrintWriter;
 
 import org.apache.sis.math.Statistics;
 import org.apache.sis.math.StatisticsFormat;
+import org.apache.sis.internal.util.StandardDateFormat;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.test.TestUtilities;
 import org.apache.sis.test.TestCase;
@@ -284,7 +285,8 @@ public final strictfp class CacheTest ex
         long time = System.nanoTime();
         for (int i=0; i<10; i++) {
             final long t = System.nanoTime();
-            out.printf("Cache size: %4d (after %3d ms)%n", cache.size(), round((t - time)
/ 1E+6));
+            out.printf("Cache size: %4d (after %3d ms)%n", cache.size(),
+                       round((t - time) / (double) StandardDateFormat.NANOS_PER_MILLISECOND));
             time = t;
             Thread.sleep(250);
             if (i >= 2) {

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -35,6 +35,7 @@ import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
 import static org.apache.sis.internal.util.StandardDateFormat.MILLISECONDS_PER_DAY;
+import static org.apache.sis.internal.util.StandardDateFormat.NANOS_PER_SECOND;
 
 
 /**
@@ -559,7 +560,7 @@ public final strictfp class RangeSetTest
                     set.remove(lower, upper);
                 }
             }
-            out.print((System.nanoTime() - start) / 1E9);
+            out.print((System.nanoTime() - start) / (float) NANOS_PER_SECOND);
             out.print(" seconds for a size of ");
             out.println(set.size());
             Thread.sleep(1000);

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -179,7 +179,7 @@ final class GridGeometryInfo extends Gri
     @Override
     protected double coordinateForAxis(final Object axis, final int j, final int i) throws
IOException, DataStoreException {
         final VariableInfo v = ((VariableInfo) axis);
-        final int n = v.getGridEnvelope()[0];
+        final int n = v.dimensions[0].length;
         return v.read().doubleValue(j + n*i);
     }
 }

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/TimeEncoding.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/TimeEncoding.java?rev=1799686&r1=1799685&r2=1799686&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/TimeEncoding.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/TimeEncoding.java
[UTF-8] Fri Jun 23 16:43:00 2017
@@ -20,6 +20,7 @@ import javax.measure.Unit;
 import javax.measure.quantity.Time;
 import org.opengis.referencing.datum.TemporalDatum;
 import org.apache.sis.internal.converter.SurjectiveConverter;
+import org.apache.sis.internal.util.StandardDateFormat;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.measure.Units;
 
@@ -96,7 +97,12 @@ class TimeEncoding extends SurjectiveCon
     public Instant apply(final String time) {
         final double value = Double.parseDouble(time) * interval;
         final long millis = Math.round(value);
-        return Instant.ofEpochMilli(millis + origin).plusNanos(Math.round((value - millis)*1E6));
+        return Instant.ofEpochMilli(millis + origin)
+                      .plusNanos(Math.round((value - millis) * StandardDateFormat.NANOS_PER_MILLISECOND));
+        /*
+         * Performance note: the call to .plusNano(…) will usually return 'this'
+         * since the time granularity is rarely finer than milliseconds.
+         */
     }
 
     /**



Mime
View raw message