sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1755442 - in /sis/branches/JDK8: core/sis-utility/src/main/java/org/apache/sis/internal/util/ core/sis-utility/src/main/java/org/apache/sis/math/ core/sis-utility/src/test/java/org/apache/sis/math/ storage/sis-geotiff/src/main/java/org/apa...
Date Sun, 07 Aug 2016 15:16:30 GMT
Author: desruisseaux
Date: Sun Aug  7 15:16:30 2016
New Revision: 1755442

URL: http://svn.apache.org/viewvc?rev=1755442&view=rev
Log:
Review Vector API and javadoc.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/package-info.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/math/VectorTest.java
    sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java?rev=1755442&r1=1755441&r2=1755442&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
[UTF-8] Sun Aug  7 15:16:30 2016
@@ -31,7 +31,7 @@ import static java.lang.Math.abs;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.6
+ * @version 0.8
  * @module
  */
 public final class Numerics extends Static {
@@ -133,9 +133,9 @@ public final class Numerics extends Stat
      * If the given value is presents in the cache, returns the cached value.
      * Otherwise returns the given value as-is.
      *
-     * @param  <T> The type of the given value.
-     * @param  value The given value for which to get a cached instance, if one exists.
-     * @return An object equals to the given value (may be the given instance itself).
+     * @param  <T>    the type of the given value.
+     * @param  value  the given value for which to get a cached instance, if one exists.
+     * @return an object equals to the given value (may be the given instance itself).
      */
     @SuppressWarnings("unchecked")
     public static <T> T cached(final T value) {
@@ -146,8 +146,8 @@ public final class Numerics extends Stat
     /**
      * Wraps the given {@code value} in a {@link Double} wrapper, using one of the cached
instance if possible.
      *
-     * @param  value The value to get as a {@code Double}.
-     * @return The given value as a {@code Double}.
+     * @param  value  the value to get as a {@code Double}.
+     * @return the given value as a {@code Double}.
      */
     public static Double valueOf(final double value) {
         final Double boxed = value;
@@ -158,9 +158,9 @@ public final class Numerics extends Stat
     /**
      * Returns a copy of the given array where each value has been casted to the {@code float}
type.
      *
-     * @param  data The array to copy, or {@code null}.
-     * @return A copy of the given array with values casted to the {@code float} type, or
-     *         {@code null} if the given array was null.
+     * @param  data  the array to copy, or {@code null}.
+     * @return a copy of the given array with values casted to the {@code float} type,
+     *         or {@code null} if the given array was null.
      */
     public static float[] copyAsFloats(final double[] data) {
         if (data == null) return null;
@@ -175,9 +175,9 @@ public final class Numerics extends Stat
      * Returns a copy of the given array where each value has been
      * {@linkplain Math#round(double) rounded} to the {@code int} type.
      *
-     * @param  data The array to copy, or {@code null}.
-     * @return A copy of the given array with values rounded to the {@code int} type, or
-     *         {@code null} if the given array was null.
+     * @param  data  the array to copy, or {@code null}.
+     * @return a copy of the given array with values rounded to the {@code int} type,
+     *         or {@code null} if the given array was null.
      */
     public static int[] copyAsInts(final double[] data) {
         if (data == null) return null;
@@ -192,8 +192,8 @@ public final class Numerics extends Stat
      * Returns {@code true} if the given floats are equals. Positive and negative zero are
      * considered different, while a NaN value is considered equal to all other NaN values.
      *
-     * @param  v1 The first value to compare.
-     * @param  v2 The second value to compare.
+     * @param  v1  the first value to compare.
+     * @param  v2  the second value to compare.
      * @return {@code true} if both values are equal.
      *
      * @see Float#equals(Object)
@@ -207,8 +207,8 @@ public final class Numerics extends Stat
      * Positive and negative zeros are considered different.
      * NaN values are considered equal to all other NaN values.
      *
-     * @param  v1 The first value to compare.
-     * @param  v2 The second value to compare.
+     * @param  v1  the first value to compare.
+     * @param  v2  the second value to compare.
      * @return {@code true} if both values are equal.
      *
      * @see Double#equals(Object)
@@ -221,8 +221,8 @@ public final class Numerics extends Stat
      * Returns {@code true} if the given doubles are equal, ignoring the sign of zero values.
      * NaN values are considered equal to all other NaN values.
      *
-     * @param  v1 The first value to compare.
-     * @param  v2 The second value to compare.
+     * @param  v1  the first value to compare.
+     * @param  v2  the second value to compare.
      * @return {@code true} if both values are equal.
      */
     public static boolean equalsIgnoreZeroSign(final double v1, final double v2) {
@@ -232,9 +232,9 @@ public final class Numerics extends Stat
     /**
      * Returns {@code true} if the given values are approximatively equal, up to the given
comparison threshold.
      *
-     * @param  v1 The first value to compare.
-     * @param  v2 The second value to compare.
-     * @param  threshold The comparison threshold.
+     * @param  v1  the first value to compare.
+     * @param  v2  the second value to compare.
+     * @param  threshold  the comparison threshold.
      * @return {@code true} if both values are approximatively equal.
      */
     public static boolean epsilonEqual(final double v1, final double v2, final double threshold)
{
@@ -249,9 +249,9 @@ public final class Numerics extends Stat
      * <p>This method does not thrown {@link AssertionError} in {@link ComparisonMode#DEBUG}.
      * It is caller responsibility to handle the {@code DEBUG} case.</p>
      *
-     * @param  v1   The first value to compare.
-     * @param  v2   The second value to compare.
-     * @param  mode The comparison mode to use for comparing the numbers.
+     * @param  v1    the first value to compare.
+     * @param  v2    the second value to compare.
+     * @param  mode  the comparison mode to use for comparing the numbers.
      * @return {@code true} if both values are considered equal for the given comparison
mode.
      */
     public static boolean epsilonEqual(final double v1, final double v2, final ComparisonMode
mode) {
@@ -268,10 +268,10 @@ public final class Numerics extends Stat
      * Creates a messages to put in {@link AssertionError} when two values differ in an unexpected
way.
      * This is a helper method for debugging purpose only, typically used with {@code assert}
statements.
      *
-     * @param name The name of the property which differ, or {@code null} if unknown.
-     * @param v1   The first value.
-     * @param v2   The second value.
-     * @return The message to put in {@code AssertionError}.
+     * @param  name  the name of the property which differ, or {@code null} if unknown.
+     * @param  v1    the first value.
+     * @param  v2    the second value.
+     * @return the message to put in {@code AssertionError}.
      *
      * @since 0.6
      */
@@ -292,14 +292,48 @@ public final class Numerics extends Stat
     /**
      * Returns a hash code value for the given long.
      *
-     * @param  c The value to hash.
-     * @return Hash code value for the given long.
+     * @param  c  the value to hash.
+     * @return hash code value for the given long.
      */
     public static int hashCode(final long c) {
         return ((int) c) ^ (int) (c >>> Integer.SIZE);
     }
 
     /**
+     * Converts an unsigned {@code long} to a {@code float} value.
+     *
+     * @param  value  the unsigned {@code long} value.
+     * @return the given unsigned {@code long} as a {@code float} value.
+     *
+     * @since 0.8
+     */
+    public static float toUnsignedFloat(final long value) {
+        if (value >= 0) {
+            return value;
+        } else {
+            // Following hack is inefficient, but should rarely be needed.
+            return Float.parseFloat(Long.toUnsignedString(value));
+        }
+    }
+
+    /**
+     * Converts an unsigned {@code long} to a {@code double} value.
+     *
+     * @param  value  the unsigned {@code long} value.
+     * @return the given unsigned {@code long} as a {@code double} value.
+     *
+     * @since 0.8
+     */
+    public static double toUnsignedDouble(final long value) {
+        if (value >= 0) {
+            return value;
+        } else {
+            // Following hack is inefficient, but should rarely be needed.
+            return Double.parseDouble(Long.toUnsignedString(value));
+        }
+    }
+
+    /**
      * Converts a power of 2 to a power of 10, rounded toward negative infinity.
      * This method is equivalent to the following code, but using only integer arithmetic:
      *
@@ -317,8 +351,8 @@ public final class Numerics extends Stat
      * which must be compensated by a smaller {@code exp2} value such as {@code toExp10(exp2)
< n}. Note that if the
      * {@code getExponent(…)} argument is not a power of 10, then the result can be either
<var>n</var> or <var>n</var>-1.
      *
-     * @param  exp2 The power of 2 to convert Must be in the [-2620 … 2620] range.
-     * @return The power of 10, rounded toward negative infinity.
+     * @param  exp2  the power of 2 to convert Must be in the [-2620 … 2620] range.
+     * @return the power of 10, rounded toward negative infinity.
      *
      * @see org.apache.sis.math.MathFunctions#LOG10_2
      * @see org.apache.sis.math.MathFunctions#getExponent(double)
@@ -350,8 +384,8 @@ public final class Numerics extends Stat
      *
      * For negative values, this method behaves as if the value was positive.
      *
-     * @param  value The value for which to get the significand.
-     * @return The significand of the given value.
+     * @param  value  the value for which to get the significand.
+     * @return the significand of the given value.
      */
     public static long getSignificand(final double value) {
         long bits = Double.doubleToRawLongBits(value);
@@ -380,8 +414,8 @@ public final class Numerics extends Stat
      *
      * For negative values, this method behaves as if the value was positive.
      *
-     * @param  value The value for which to get the significand.
-     * @return The significand of the given value.
+     * @param  value  the value for which to get the significand.
+     * @return the significand of the given value.
      */
     public static int getSignificand(final float value) {
         int bits = Float.floatToRawIntBits(value);

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java?rev=1755442&r1=1755441&r2=1755442&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java
[UTF-8] Sun Aug  7 15:16:30 2016
@@ -20,6 +20,7 @@ import java.io.Serializable;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.collection.CheckedContainer;
+import org.apache.sis.internal.util.Numerics;
 
 
 /**
@@ -326,22 +327,12 @@ abstract class ArrayVector<E extends Num
 
         /** Returns the unsigned long as a {@code double} value. */
         @Override public double doubleValue(final int index) {
-            final long value = super.longValue(index);
-            if (value >= 0) {
-                return value;
-            }
-            // This hack is inefficient, but should be rarely needed.
-            return java.lang.Double.parseDouble(java.lang.Long.toUnsignedString(value));
+            return Numerics.toUnsignedDouble(super.longValue(index));
         }
 
         /** Returns the unsigned long as a {@code float} value. */
         @Override public float floatValue(final int index) {
-            final long value = super.longValue(index);
-            if (value >= 0) {
-                return value;
-            }
-            // This hack is inefficient, but should be rarely needed.
-            return java.lang.Float.parseFloat(java.lang.Long.toUnsignedString(value));
+            return Numerics.toUnsignedFloat(super.longValue(index));
         }
 
         /** Returns the unsigned long as a {@code long} value, if possible. */

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java?rev=1755442&r1=1755441&r2=1755442&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java [UTF-8]
Sun Aug  7 15:16:30 2016
@@ -36,9 +36,8 @@ import static org.apache.sis.util.Argume
  *   <li><var>y[i]</var> is the measurement of a phenomenon at time <var>x[i]</var>.</li>
  * </ul>
  *
- * Instances of {@code Vector} are created by calls to the {@link #create(Object)} static
method.
- * The supplied array is not cloned – changes to the primitive array are reflected in the
vector,
- * and vis-versa.
+ * Instances of {@code Vector} are created by calls to the {@link #create(Object, boolean)}
static method.
+ * The supplied array is not cloned – changes to the primitive array are reflected in the
vector, and vis-versa.
  *
  * Vectors can be created over a subrange of an array, provides a view of the elements in
reverse
  * order, <i>etc</i>. The example below creates a view over a subrange:
@@ -80,10 +79,16 @@ public abstract class Vector extends Abs
      * The given argument is not cloned.
      * Consequently changes in the underlying array are reflected in this vector, and vis-versa.
      *
+     * <div class="section">Unsigned integers</div>
+     * Java has no primitive support for unsigned integers. But some file formats use unsigned
integers,
+     * which can be simulated in Java by the use of bit masks or methods like {@link Integer#toUnsignedLong(int)}.
+     * This {@code Vector} class applies automatically those masks (unless otherwise noticed
in method Javadoc)
+     * if the {@code isUnsigned} argument is {@code true}.
+     * That argument applies only to {@code byte[]}, {@code short[]}, {@code int[]} or {@code
long[]} arrays
+     * and is ignored for all other kind of arrays.
+     *
      * @param  array       the object to wrap in a vector, or {@code null}.
      * @param  isUnsigned  {@code true} if integer types should be interpreted as unsigned
integers.
-     *         This argument is ignored if the given array is not a {@code byte[]}, {@code
short[]},
-     *         {@code int[]} or {@code long[]} array.
      * @return the given object wrapped in a vector, or {@code null} if the argument was
{@code null}.
      * @throws IllegalArgumentException if the type of the given object is not recognized
by the method.
      */
@@ -159,14 +164,21 @@ public abstract class Vector extends Abs
      * is backed by an array of type {@code float[]}, then this method returns {@code Float.class},
      * not {@link Float#TYPE}.
      *
+     * <p>Users of the {@link #doubleValue(int)} method do not need to care about this
information since
+     * {@code Vector} will perform automatically the type conversion. Users of other methods
may want to
+     * verify this information for avoiding {@link ClassCastException}.</p>
+     *
      * @return the type of elements in this vector.
      */
     public abstract Class<? extends Number> getElementType();
 
     /**
      * Returns {@code true} if integer values shall be interpreted as unsigned values.
-     * Java has no primitive type for unsigned integers, but {@code Vector} implementations
-     * can simulate them by applying the necessary bit masks.
+     * This method may return {@code true} only for data stored in {@code byte[]},
+     * {@code short[]}, {@code int[]} or {@code long[]} arrays.
+     *
+     * <p>Unless otherwise noticed in Javadoc, users do not need to care about this
information since
+     * {@code Vector} methods will perform automatically the operations needed for unsigned
integers.</p>
      *
      * @return {@code true} if the integer values shall be interpreted as unsigned values.
      */
@@ -191,14 +203,14 @@ public abstract class Vector extends Abs
 
     /**
      * Returns the value at the given index as a {@code double}.
+     * This is the safest method since all primitive types supported by {@code Vector}
+     * are convertible to the {@code double} type.
      *
      * @param  index the index in the [0 … {@linkplain #size size}-1] range.
      * @return the value at the given index.
      * @throws IndexOutOfBoundsException if the given index is out of bounds.
-     * @throws ClassCastException if the component type can not be converted to a
-     *         {@code double} by an identity or widening conversion.
      */
-    public abstract double doubleValue(final int index) throws IndexOutOfBoundsException,
ClassCastException;
+    public abstract double doubleValue(final int index) throws IndexOutOfBoundsException;
 
     /**
      * Returns the value at the given index as a {@code float}.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/package-info.java?rev=1755442&r1=1755441&r2=1755442&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/package-info.java
[UTF-8] Sun Aug  7 15:16:30 2016
@@ -25,6 +25,9 @@
  *       and {@linkplain org.apache.sis.math.StatisticsFormat tabular formatting}.</li>
  *   <li>Simple equations for {@link org.apache.sis.math.Line} and {@link org.apache.sis.math.Plane}
  *       with capability to determine the coefficients from a set of coordinates.</li>
+ *   <li>{@link org.apache.sis.math.Vector} as views over arrays of primitive types.
+ *       Those views make abstraction of the data type (e.g. {@code float} or {@code double})
+ *       and whether the integer types are signed or unsigned.</li>
  * </ul>
  *
  * <div class="note"><b>Note:</b>

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/math/VectorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/math/VectorTest.java?rev=1755442&r1=1755441&r2=1755442&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/math/VectorTest.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/math/VectorTest.java [UTF-8]
Sun Aug  7 15:16:30 2016
@@ -32,19 +32,28 @@ import static org.junit.Assert.*;
  */
 public final strictfp class VectorTest extends TestCase {
     /**
-     * Tests {@link SequenceVector}.
+     * The tested vector.
+     */
+    private Vector vector;
+
+    /**
+     * Tests {@link SequenceVector} with byte values.
      */
     @Test
-    public void testSequence() {
-        Vector vector = Vector.createSequence(100, 2, 10);
+    public void testSequenceOfBytes() {
+        vector = Vector.createSequence(100, 2, 10);
         assertEquals(Byte.class, vector.getElementType());
         assertEquals(10, vector.size());
         for (int i=0; i<vector.size(); i++) {
             assertEquals(100 + 2*i, vector.byteValue(i));
         }
-        /*
-         * Same tests, using double values.
-         */
+    }
+
+    /**
+     * Tests {@link SequenceVector} with float values.
+     */
+    @Test
+    public void testSequenceOfFloats() {
         vector = Vector.createSequence(100, 0.1, 10);
         assertEquals(Double.class, vector.getElementType());
         assertEquals(10, vector.size());
@@ -55,32 +64,29 @@ public final strictfp class VectorTest e
 
     /**
      * Tests {@link ArrayVector} backed by an array of primitive type.
-     * We use the {@code short} type since it doesn't have specialized
-     * vector implementation.
+     * We use the {@code short} type for this test.
      */
     @Test
-    public void testPrimitiveTypeArray() {
+    public void testShortArray() {
         final short[] array = new short[400];
         for (int i=0; i<array.length; i++) {
             array[i] = (short) ((i + 100) * 10);
         }
-        Vector vector = Vector.create(array, false);
+        vector = Vector.create(array, false);
         assertTrue(vector instanceof ArrayVector);
         assertSame(vector, Vector.create(vector, false));
         assertEquals(array.length, vector.size());
         assertEquals(Short.class, vector.getElementType());
-        /*
-         * Tests element values.
-         */
+
+        // Verifies element values.
         for (int i=0; i<array.length; i++) {
             assertEquals(array[i], vector.shortValue (i));
             assertEquals(array[i], vector.intValue   (i));
-            assertEquals(array[i], vector.floatValue (i), 0);
-            assertEquals(array[i], vector.doubleValue(i), 0);
+            assertEquals(array[i], vector.floatValue (i), 0f);
+            assertEquals(array[i], vector.doubleValue(i), STRICT);
         }
-        /*
-         * Tests exception.
-         */
+
+        // Tests exception.
         try {
             vector.floatValue(array.length);
             fail("Expected an IndexOutOfBoundsException");
@@ -93,13 +99,12 @@ public final strictfp class VectorTest e
         } catch (ClassCastException e) {
             // This is the expected exception.
         }
-        /*
-         * Tests subvector in the range [100:2:298].
-         */
+
+        // Tests subvector in the range [100:2:298].
         vector = vector.subList(100, 2, 100);
         assertEquals(100, vector.size());
         for (int i=0; i<100; i++) {
-            assertEquals(array[i*2 + 100], vector.shortValue(i), 0);
+            assertEquals(array[i*2 + 100], vector.shortValue(i));
         }
         try {
             vector.shortValue(100);
@@ -107,14 +112,13 @@ public final strictfp class VectorTest e
         } catch (IndexOutOfBoundsException e) {
             // This is the expected exception.
         }
-        /*
-         * Tests subvector at specific indexes.
-         */
+
+        // Tests subvector at specific indexes.
         vector = vector.view(10, 20, 25);
         assertEquals(3, vector.size());
-        assertEquals(array[120], vector.shortValue(0), 0);
-        assertEquals(array[140], vector.shortValue(1), 0);
-        assertEquals(array[150], vector.shortValue(2), 0);
+        assertEquals(array[120], vector.shortValue(0));
+        assertEquals(array[140], vector.shortValue(1));
+        assertEquals(array[150], vector.shortValue(2));
     }
 
     /**
@@ -126,7 +130,7 @@ public final strictfp class VectorTest e
         for (int i=0; i<array.length; i++) {
             array[i] = (i + 100) * 10;
         }
-        Vector vector = Vector.create(array, false);
+        vector = Vector.create(array, false);
         assertTrue(vector instanceof ArrayVector.Float);
         assertSame(vector, Vector.create(vector, false));
         assertEquals(array.length, vector.size());
@@ -135,8 +139,8 @@ public final strictfp class VectorTest e
          * Tests element values.
          */
         for (int i=0; i<array.length; i++) {
-            assertEquals(array[i], vector.floatValue (i), 0);
-            assertEquals(array[i], vector.doubleValue(i), 0);
+            assertEquals(array[i], vector.floatValue (i), 0f);
+            assertEquals(array[i], vector.doubleValue(i), STRICT);
         }
     }
 
@@ -149,7 +153,7 @@ public final strictfp class VectorTest e
         for (int i=0; i<array.length; i++) {
             array[i] = (i + 100) * 10;
         }
-        Vector vector = Vector.create(array, false);
+        vector = Vector.create(array, false);
         assertTrue(vector instanceof ArrayVector.Double);
         assertSame(vector, Vector.create(vector, false));
         assertEquals(array.length, vector.size());
@@ -158,8 +162,8 @@ public final strictfp class VectorTest e
          * Tests element values.
          */
         for (int i=0; i<array.length; i++) {
-            assertEquals(array[i], vector.floatValue (i), 0);
-            assertEquals(array[i], vector.doubleValue(i), 0);
+            assertEquals(array[i], vector.floatValue (i), 0f);
+            assertEquals(array[i], vector.doubleValue(i), STRICT);
         }
     }
 

Modified: sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java?rev=1755442&r1=1755441&r2=1755442&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/Type.java
[UTF-8] Sun Aug  7 15:16:30 2016
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import org.apache.sis.internal.storage.ChannelDataInput;
+import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.math.Vector;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.resources.Errors;
@@ -191,11 +192,7 @@ enum Type {
 
         @Override double readDouble(final ChannelDataInput input, final long count) throws
IOException {
             ensureSingleton(count);
-            final long value = input.readLong();
-            if (value >= 0) {
-                return value;
-            }
-            return Double.parseDouble(Long.toUnsignedString(value));    // Inefficient but
should be very rare.
+            return Numerics.toUnsignedDouble(input.readLong());
         }
 
         @Override Object readArray(final ChannelDataInput input, final int count) throws
IOException {



Mime
View raw message