sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1801816 - /sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/DateList.java
Date Thu, 13 Jul 2017 09:00:04 GMT
Author: desruisseaux
Date: Thu Jul 13 09:00:04 2017
New Revision: 1801816

URL: http://svn.apache.org/viewvc?rev=1801816&view=rev
Log:
Use the compression provided by Vector instead of duplication the code here.

Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/DateList.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/DateList.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/DateList.java?rev=1801816&r1=1801815&r2=1801816&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/DateList.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/internal/feature/DateList.java
[UTF-8] Thu Jul 13 09:00:04 2017
@@ -17,7 +17,7 @@
 package org.apache.sis.internal.feature;
 
 import java.util.AbstractList;
-import org.apache.sis.util.collection.IntegerList;
+import org.apache.sis.math.Vector;
 import org.apache.sis.util.collection.CheckedContainer;
 
 // Branch-dependent imports
@@ -34,51 +34,15 @@ import java.time.Instant;
  */
 final class DateList extends AbstractList<Instant> implements CheckedContainer<Instant>
{
     /**
-     * The times in multiples of {@link #increment} milliseconds since the {@link #epoch}.
+     * The times in milliseconds since the epoch.
      */
-    private final IntegerList times;
+    private final Vector times;
 
     /**
-     * The value by which to multiply the {@link #times} values in order to get milliseconds.
-     */
-    private final long increment;
-
-    /**
-     * The epoch in milliseconds since January 1st, 1970 midnight UTC.
-     */
-    private final long epoch;
-
-    /**
-     * Creates a new list for the given times. The given array shall be a temporary one
-     * since this constructor modifies the array values for computational purpose.
+     * Creates a new list for the given times.
      */
     DateList(final long[] millis) {
-        long min = Long.MAX_VALUE;
-        for (final long t : millis) {
-            if (t < min) min = t;
-        }
-        long max = 1;
-        for (int i=0; i<millis.length; i++) {
-            final long t = (millis[i] -= min);
-            if (t > max) max = t;
-        }
-        long inc = max;
-        for (long t : millis) {
-            if ((t % inc) != 0) {
-                do {
-                    final long r = (inc % t);       // Search for greatest common divisor
with Euclid's algorithm.
-                    inc = t;
-                    t = r;
-                } while (t != 0);
-                if (inc == 1) break;                // No need to check other values.
-            }
-        }
-        epoch = min;
-        increment = inc;
-        times = new IntegerList(millis.length, Math.toIntExact(max / inc));
-        for (final long t : millis) {
-            times.add(Math.toIntExact(t / inc));
-        }
+        times = Vector.create(millis, false).compress(0);
     }
 
     /**
@@ -102,6 +66,6 @@ final class DateList extends AbstractLis
      */
     @Override
     public Instant get(final int index) {
-        return Instant.ofEpochMilli(times.getInt(index)*increment + epoch);
+        return Instant.ofEpochMilli(times.longValue(index));
     }
 }



Mime
View raw message