sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1554592 [2/2] - in /sis/branches/JDK6: ./ core/sis-referencing/src/main/java/org/apache/sis/geometry/ core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/ core/sis-referencing/src/main/java/org/apache/sis/io/wkt/ co...
Date Tue, 31 Dec 2013 23:50:04 GMT
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -226,7 +226,7 @@ public class BursaWolfParameters extends
     public double dS;
 
     /**
-     * The target datum for this set of parameters.
+     * The target datum for this set of parameters, or {@code null} if unknown.
      * This is usually the WGS 84 datum, but other targets are allowed.
      *
      * <p>The source datum is the {@link DefaultGeodeticDatum} that contain this {@code BursaWolfParameters}
@@ -254,12 +254,11 @@ public class BursaWolfParameters extends
      * <p>Alternatively, numerical fields can also be initialized by a call to
      * {@link #setPositionVectorTransformation(Matrix, double)}.</p>
      *
-     * @param targetDatum The target datum (usually WGS 84) for this set of parameters.
+     * @param targetDatum The target datum (usually WGS 84) for this set of parameters, or {@code null} if unknown.
      * @param domainOfValidity Area or region in which a coordinate transformation based on those Bursa-Wolf parameters
      *        is valid, or {@code null} is unspecified.
      */
     public BursaWolfParameters(final GeodeticDatum targetDatum, final Extent domainOfValidity) {
-        ensureNonNull("targetDatum", targetDatum);
         this.targetDatum = targetDatum;
         this.domainOfValidity = domainOfValidity;
     }
@@ -278,13 +277,13 @@ public class BursaWolfParameters extends
     }
 
     /**
-     * Returns the target datum for this set of parameters.
+     * Returns the target datum for this set of parameters, or {@code null} if unknown.
      * This is usually the WGS 84 datum, but other targets are allowed.
      *
      * <p>The source datum is the {@link DefaultGeodeticDatum} that contain this {@code BursaWolfParameters}
      * instance.</p>
      *
-     * @return The target datum for this set of parameters.
+     * @return The target datum for this set of parameters, or {@code null} if unknown.
      */
     public GeodeticDatum getTargetDatum() {
         return targetDatum;
@@ -298,8 +297,9 @@ public class BursaWolfParameters extends
      * @return {@code true} if the given datum is equal to WGS84 for computational purpose.
      */
     final boolean isToWGS84() {
-        return IdentifiedObjects.isHeuristicMatchForName(targetDatum, "WGS 84") ||
-               IdentifiedObjects.isHeuristicMatchForName(targetDatum, "WGS84");
+        return (targetDatum != null) &&
+               (IdentifiedObjects.isHeuristicMatchForName(targetDatum, "WGS 84") ||
+                IdentifiedObjects.isHeuristicMatchForName(targetDatum, "WGS84"));
     }
 
     /**
@@ -322,6 +322,18 @@ public class BursaWolfParameters extends
     }
 
     /**
+     * Inverts in-place the sign of rotation terms ({@link #rX}, {@link #rY}, {@link #rZ}).
+     * This method can be invoked for converting a <cite>Coordinate Frame Rotation</cite> transformation
+     * (EPSG operation method 9607) to a <em>Position Vector</em> transformation (EPSG operation method 9606).
+     * The later convention is used by IAG and recommended by ISO 19111.
+     */
+    public void reverseRotation() {
+        rX = -rX;
+        rY = -rY;
+        rZ = -rZ;
+    }
+
+    /**
      * Inverts in-place the transformation by inverting the sign of all numerical parameters.
      * The {@linkplain #getPositionVectorTransformation(Date) position vector transformation} matrix
      * created from inverted Bursa-Wolf parameters will be <strong>approximatively</strong> equals
@@ -415,7 +427,7 @@ public class BursaWolfParameters extends
             final Matrix4 matrix = new Matrix4();
             matrix.m03 = tX;
             matrix.m13 = tY;
-            matrix.m13 = tZ;
+            matrix.m23 = tZ;
             return matrix;
         }
         /*
@@ -613,10 +625,10 @@ public class BursaWolfParameters extends
             return "TOWGS84";
         }
         String keyword = super.formatTo(formatter); // Declare the WKT as invalid.
-        final String name = IdentifiedObjects.getName(targetDatum, null);
+        final String name = IdentifiedObjects.getUnicodeIdentifier(targetDatum);
         if (name != null) {
             // We may try to build something better here in future SIS versions, if there is a need for that.
-            keyword = "To" + name;
+            keyword = "TO" + name;
         }
         return keyword;
     }

Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -42,7 +42,6 @@ import org.apache.sis.util.resources.Err
 
 import static java.lang.Math.*;
 import static java.lang.Double.*;
-import static org.apache.sis.internal.util.Numerics.hash;
 import static org.apache.sis.internal.util.Numerics.epsilonEqual;
 import static org.apache.sis.util.ArgumentChecks.ensureStrictlyPositive;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -724,28 +723,20 @@ public class DefaultEllipsoid extends Ab
     }
 
     /**
-     * Computes a hash value consistent with the given comparison mode.
+     * Invoked by {@link #hashCode()} for computing the hash code when first needed.
+     * See {@link org.apache.sis.referencing.AbstractIdentifiedObject#computeHashCode()}
+     * for more information.
      *
-     * @return The hash code value for the given comparison mode.
+     * @return The hash code value. This value may change in any future Apache SIS version.
      */
     @Override
-    public int hashCode(final ComparisonMode mode) throws IllegalArgumentException {
+    protected long computeHashCode() {
         /*
-         * The "^ (int) serialVersionUID" is an arbitrary change applied to the hash code value in order to
-         * differentiate this DefaultEllipsoid implementation from implementations of other GeoAPI interfaces.
+         * The "serialVersionUID ^ …" is an arbitrary change applied to the hash code value in order to
+         * differentiate this Ellipsoid implementation from implementations of other GeoAPI interfaces.
          */
-        int code = super.hashCode(mode) ^ (int) serialVersionUID;
-        switch (mode) {
-            case STRICT: {
-                code = hash(semiMajorAxis, hash(ivfDefinitive ? inverseFlattening : semiMinorAxis, code));
-                break;
-            }
-            default: {
-                code = hash(getSemiMajorAxis(), hash(isIvfDefinitive() ? getInverseFlattening() : getSemiMinorAxis(), code));
-                break;
-            }
-        }
-        return code;
+        return serialVersionUID ^ (super.computeHashCode() + Double.doubleToLongBits(semiMajorAxis) +
+               31 * Double.doubleToLongBits(ivfDefinitive ? inverseFlattening : semiMinorAxis));
     }
 
     /**

Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -166,17 +166,19 @@ public class DefaultEngineeringDatum ext
     }
 
     /**
-     * Computes a hash value consistent with the given comparison mode.
+     * Invoked by {@link #hashCode()} for computing the hash code when first needed.
+     * See {@link org.apache.sis.referencing.AbstractIdentifiedObject#computeHashCode()}
+     * for more information.
      *
-     * @return The hash code value for the given comparison mode.
+     * @return The hash code value. This value may change in any future Apache SIS version.
      */
     @Override
-    public int hashCode(final ComparisonMode mode) throws IllegalArgumentException {
+    protected long computeHashCode() {
         /*
-         * The "^ (int) serialVersionUID" is an arbitrary change applied to the hash code value in order to
+         * The "serialVersionUID ^ …" is an arbitrary change applied to the hash code value in order to
          * differentiate this EngineeringDatum implementation from implementations of other GeoAPI interfaces.
          */
-        return super.hashCode(mode) ^ (int) serialVersionUID;
+        return serialVersionUID ^ super.computeHashCode();
     }
 
     /**

Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -470,13 +470,20 @@ public class DefaultGeodeticDatum extend
     }
 
     /**
-     * Computes a hash value consistent with the given comparison mode.
+     * Invoked by {@link #hashCode()} for computing the hash code when first needed.
+     * See {@link org.apache.sis.referencing.AbstractIdentifiedObject#computeHashCode()}
+     * for more information.
      *
-     * @return The hash code value for the given comparison mode.
+     * @return The hash code value. This value may change in any future Apache SIS version.
      */
     @Override
-    public int hashCode(final ComparisonMode mode) throws IllegalArgumentException {
-        return (Objects.hashCode(ellipsoid) * 31 + Objects.hashCode(primeMeridian)) * 31 + super.hashCode(mode);
+    protected long computeHashCode() {
+        /*
+         * The "serialVersionUID ^ …" is an arbitrary change applied to the hash code value in order to
+         * differentiate this GeodeticDatum implementation from implementations of other GeoAPI interfaces.
+         */
+        return serialVersionUID ^ (super.computeHashCode() +
+                Objects.hashCode(ellipsoid) + 31 * Objects.hashCode(primeMeridian));
     }
 
     /**

Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -201,28 +201,19 @@ public class DefaultImageDatum extends A
     }
 
     /**
-     * Computes a hash value consistent with the given comparison mode.
+     * Invoked by {@link #hashCode()} for computing the hash code when first needed.
+     * See {@link org.apache.sis.referencing.AbstractIdentifiedObject#computeHashCode()}
+     * for more information.
      *
-     * @return The hash code value for the given comparison mode.
+     * @return The hash code value. This value may change in any future Apache SIS version.
      */
     @Override
-    public int hashCode(final ComparisonMode mode) throws IllegalArgumentException {
+    protected long computeHashCode() {
         /*
-         * The "^ (int) serialVersionUID" is an arbitrary change applied to the hash code value in order to
+         * The "serialVersionUID ^ …" is an arbitrary change applied to the hash code value in order to
          * differentiate this ImageDatum implementation from implementations of other GeoAPI interfaces.
          */
-        int code = super.hashCode(mode) ^ (int) serialVersionUID;
-        switch (mode) {
-            case STRICT: {
-                code += Objects.hashCode(pixelInCell);
-                break;
-            }
-            default: {
-                code += Objects.hashCode(getPixelInCell());
-                break;
-            }
-        }
-        return code;
+        return serialVersionUID ^ (super.computeHashCode() + Objects.hashCode(pixelInCell));
     }
 
     /**
@@ -236,7 +227,7 @@ public class DefaultImageDatum extends A
     protected String formatTo(final Formatter formatter) {
         super.formatTo(formatter);
         formatter.append(pixelInCell);
-        formatter.setInvalidWKT("ImageDatum");
+        formatter.setInvalidWKT(this);
         return "GENDATUM"; // Generic datum (WKT 2)
     }
 }

Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -287,28 +287,20 @@ public class DefaultPrimeMeridian extend
     }
 
     /**
-     * Computes a hash value consistent with the given comparison mode.
+     * Invoked by {@link #hashCode()} for computing the hash code when first needed.
+     * See {@link org.apache.sis.referencing.AbstractIdentifiedObject#computeHashCode()}
+     * for more information.
      *
-     * @return The hash code value for the given comparison mode.
+     * @return The hash code value. This value may change in any future Apache SIS version.
      */
     @Override
-    public int hashCode(final ComparisonMode mode) throws IllegalArgumentException {
+    protected long computeHashCode() {
         /*
-         * The "^ (int) serialVersionUID" is an arbitrary change applied to the hash code value in order to
+         * The "serialVersionUID ^ …" is an arbitrary change applied to the hash code value in order to
          * differentiate this PrimeMeridian implementation from implementations of other GeoAPI interfaces.
          */
-        int code = super.hashCode(mode) ^ (int) serialVersionUID;
-        switch (mode) {
-            case STRICT: {
-                code += Numerics.hash(greenwichLongitude, Objects.hashCode(angularUnit));
-                break;
-            }
-            default: {
-                code += Numerics.hash(getGreenwichLongitude(), Objects.hashCode(getAngularUnit()));
-                break;
-            }
-        }
-        return code;
+        return serialVersionUID ^ (super.computeHashCode() +
+                Double.doubleToLongBits(greenwichLongitude) + Objects.hashCode(angularUnit));
     }
 
     /**

Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java Tue Dec 31 23:50:03 2013
@@ -27,7 +27,6 @@ import org.opengis.referencing.datum.Tem
 import org.apache.sis.internal.metadata.MetadataUtilities;
 import org.apache.sis.util.ComparisonMode;
 
-import static org.apache.sis.internal.util.Numerics.hash;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 
 // Related to JDK7
@@ -227,27 +226,19 @@ public class DefaultTemporalDatum extend
     }
 
     /**
-     * Computes a hash value consistent with the given comparison mode.
+    /**
+     * Invoked by {@link #hashCode()} for computing the hash code when first needed.
+     * See {@link org.apache.sis.referencing.AbstractIdentifiedObject#computeHashCode()}
+     * for more information.
      *
-     * @return The hash code value for the given comparison mode.
+     * @return The hash code value. This value may change in any future Apache SIS version.
      */
     @Override
-    public int hashCode(final ComparisonMode mode) throws IllegalArgumentException {
+    protected long computeHashCode() {
         /*
-         * The "^ (int) serialVersionUID" is an arbitrary change applied to the hash code value in order to
+         * The "serialVersionUID ^ …" is an arbitrary change applied to the hash code value in order to
          * differentiate this TemporalDatum implementation from implementations of other GeoAPI interfaces.
          */
-        int code = super.hashCode(mode) ^ (int) serialVersionUID;
-        switch (mode) {
-            case STRICT: {
-                code = hash(origin, code);
-                break;
-            }
-            default: {
-                code += Objects.hashCode(getOrigin());
-                break;
-            }
-        }
-        return code;
+        return serialVersionUID ^ (super.computeHashCode() + origin);
     }
 }

Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -270,7 +270,7 @@ public class DefaultVerticalDatum extend
         }
         switch (mode) {
             case STRICT: {
-                return Objects.equals(type(), ((DefaultVerticalDatum) object).type());
+                return type().equals(((DefaultVerticalDatum) object).type());
             }
             default: {
                 return Objects.equals(getVerticalDatumType(), ((VerticalDatum) object).getVerticalDatumType());
@@ -279,19 +279,19 @@ public class DefaultVerticalDatum extend
     }
 
     /**
-     * Computes a hash value consistent with the given comparison mode.
+     * Invoked by {@link #hashCode()} for computing the hash code when first needed.
+     * See {@link org.apache.sis.referencing.AbstractIdentifiedObject#computeHashCode()}
+     * for more information.
      *
-     * @return The hash code value for the given comparison mode.
+     * @return The hash code value. This value may change in any future Apache SIS version.
      */
     @Override
-    public int hashCode(final ComparisonMode mode) throws IllegalArgumentException {
+    protected long computeHashCode() {
         /*
-         * The "^ (int) serialVersionUID" is an arbitrary change applied to the hash code value in order to
+         * The "serialVersionUID ^ …" is an arbitrary change applied to the hash code value in order to
          * differentiate this VerticalDatum implementation from implementations of other GeoAPI interfaces.
          */
-        int code = super.hashCode(mode) ^ (int) serialVersionUID;
-        code += Objects.hashCode(mode == ComparisonMode.STRICT ? type() : getVerticalDatumType());
-        return code;
+        return serialVersionUID ^ (super.computeHashCode() + type().hashCode());
     }
 
     /**

Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/TimeDependentBWP.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -217,6 +217,20 @@ public class TimeDependentBWP extends Bu
     }
 
     /**
+     * Inverts in-place the sign of rotation terms and their derivative.
+     * This method can be invoked for converting a <cite>Coordinate Frame Rotation</cite> transformation
+     * (EPSG operation method 9607) to a <em>Position Vector</em> transformation (EPSG operation method 9606).
+     * The later convention is used by IAG and recommended by ISO 19111.
+     */
+    @Override
+    public void reverseRotation() {
+        super.reverseRotation();
+        drX = -drX;
+        drY = -drY;
+        drZ = -drZ;
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override

Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -272,7 +272,6 @@ public final class Matrix1 extends Matri
      */
     @Override
     public int hashCode() {
-        final long code = Double.doubleToLongBits(m00) ^ serialVersionUID;
-        return ((int) code) ^ ((int) (code >>> 32));
+        return Numerics.hashCode(Double.doubleToLongBits(m00) ^ serialVersionUID);
     }
 }

Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -299,11 +299,10 @@ public final class Matrix2 extends Matri
      */
     @Override
     public int hashCode() {
-        final long code = serialVersionUID ^
+        return Numerics.hashCode(serialVersionUID ^
                 (((Double.doubleToLongBits(m00)  +
               31 * Double.doubleToLongBits(m01)) +
               31 * Double.doubleToLongBits(m10)) +
-              31 * Double.doubleToLongBits(m11));
-        return ((int) code) ^ ((int) (code >>> 32));
+              31 * Double.doubleToLongBits(m11)));
     }
 }

Modified: sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectVerifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectVerifier.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectVerifier.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectVerifier.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -25,6 +25,7 @@ import org.opengis.referencing.Reference
 import org.opengis.referencing.datum.Ellipsoid;
 import org.opengis.referencing.datum.PrimeMeridian;
 import org.opengis.referencing.datum.GeodeticDatum;
+import org.opengis.referencing.datum.VerticalDatum;
 
 import static org.apache.sis.test.Assert.*;
 
@@ -181,7 +182,7 @@ public final strictfp class GeodeticObje
      * <tr><td>{@linkplain ReferenceIdentifier#getCode() Code} of the {@linkplain GeodeticDatum#getName() name}</td>
      *     <td>{@code "World Geodetic System 1984"}</td></tr>
      * <tr><td>{@linkplain GeodeticDatum#getDomainOfValidity() Domain of validity}</td>
-     *     <td>{@linkplain #assertIsWorld(GeographicBoundingBox) Is world}</td></tr>
+     *     <td>{@linkplain #assertIsWorld(GeographicBoundingBox) Is world} or absent</td></tr>
      * <tr><td>{@linkplain GeodeticDatum#getPrimeMeridian() Prime meridian}</td>
      *     <td>{@linkplain #assertIsGreenwich(PrimeMeridian) Is Greenwich}</td></tr>
      * <tr><td>{@linkplain GeodeticDatum#getEllipsoid() Ellipsoid}</td>
@@ -196,4 +197,23 @@ public final strictfp class GeodeticObje
         assertIsGreenwich(datum.getPrimeMeridian());
         assertIsWGS84    (datum.getEllipsoid());
     }
+
+    /**
+     * Asserts that the given datum is the Mean Sea Level one.
+     * This method verifies the following properties:
+     *
+     * <table class="sis">
+     * <tr><th>Property</th> <th>Expected value</th></tr>
+     * <tr><td>{@linkplain ReferenceIdentifier#getCode() Code} of the {@linkplain GeodeticDatum#getName() name}</td>
+     *     <td>{@code "Mean Sea Level"}</td></tr>
+     * <tr><td>{@linkplain GeodeticDatum#getDomainOfValidity() Domain of validity}</td>
+     *     <td>{@linkplain #assertIsWorld(GeographicBoundingBox) Is world} or absent</td></tr>
+     * </table>
+     *
+     * @param datum The datum to verify.
+     */
+    public static void assertIsMeanSeaLevel(final VerticalDatum datum) {
+        assertEquals("name", "Mean Sea Level", datum.getName().getCode());
+        assertIsWorld(datum.getDomainOfValidity());
+    }
 }

Modified: sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/NamedIdentifierTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/NamedIdentifierTest.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/NamedIdentifierTest.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/NamedIdentifierTest.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -25,7 +25,7 @@ import org.apache.sis.test.DependsOnMeth
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
+import static org.apache.sis.test.Assert.*;
 import static org.apache.sis.metadata.iso.citation.HardCodedCitations.EPSG;
 
 
@@ -64,16 +64,23 @@ public final strictfp class NamedIdentif
     }
 
     /**
-     * Tests the {@link NamedIdentifier#NamedIdentifier(Citation, InternationalString)} constructor.
+     * Creates an internationalized name with a code set to "name" localized in English, French and Japanese.
      */
-    @Test
-    @DependsOnMethod("testCreateFromCode")
-    public void testCreateFromInternationalString() {
+    private NamedIdentifier createI18N() {
         final DefaultInternationalString i18n = new DefaultInternationalString();
         i18n.add(Locale.ENGLISH,  "name");
         i18n.add(Locale.FRENCH,   "nom");
         i18n.add(Locale.JAPANESE, "名前");
-        final NamedIdentifier identifier = new NamedIdentifier(EPSG, i18n);
+        return new NamedIdentifier(EPSG, i18n);
+    }
+
+    /**
+     * Tests the {@link NamedIdentifier#NamedIdentifier(Citation, InternationalString)} constructor.
+     */
+    @Test
+    @DependsOnMethod("testCreateFromCode")
+    public void testCreateFromInternationalString() {
+        final NamedIdentifier identifier = createI18N();
         Validators.validate((ReferenceIdentifier) identifier);
         Validators.validate((GenericName) identifier);
 
@@ -96,4 +103,22 @@ public final strictfp class NamedIdentif
         assertEquals("name",  "EPSG:名前",  identifier.toInternationalString().toString(Locale.JAPANESE));
         assertTrue  ("scope",              identifier.scope().isGlobal());
     }
+
+    /**
+     * Tests serialization.
+     */
+    @Test
+    @DependsOnMethod("testCreateFromInternationalString")
+    public void testSerialization() {
+        NamedIdentifier unserial = assertSerializedEquals(new NamedIdentifier(EPSG, "4326"));
+        assertEquals("EPSG:4326", unserial.toInternationalString().toString(Locale.ENGLISH));
+        /*
+         * Try again with an international string. We would not been able to get back the
+         * localized strings if NamedIdentifier.writeObject/readObject(…) didn't worked.
+         */
+        unserial = assertSerializedEquals(createI18N());
+        assertEquals("EPSG:name", unserial.toInternationalString().toString(Locale.ENGLISH));
+        assertEquals("EPSG:nom",  unserial.toInternationalString().toString(Locale.FRENCH));
+        assertEquals("EPSG:名前",  unserial.toInternationalString().toString(Locale.JAPANESE));
+    }
 }

Modified: sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/BursaWolfParametersTest.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -57,6 +57,8 @@ public final strictfp class BursaWolfPar
         bursaWolf.rZ = 0.554;
         bursaWolf.dS = 0.219;
         bursaWolf.verify();
+        assertFalse("isIdentity",    bursaWolf.isIdentity());
+        assertFalse("isTranslation", bursaWolf.isTranslation());
         return bursaWolf;
     }
 
@@ -75,6 +77,24 @@ public final strictfp class BursaWolfPar
         bursaWolf.rZ =    0.3898;
         bursaWolf.dS =   -0.3143;
         bursaWolf.verify();
+        assertFalse("isIdentity",    bursaWolf.isIdentity());
+        assertFalse("isTranslation", bursaWolf.isTranslation());
+        return bursaWolf;
+    }
+
+    /**
+     * Returns the parameters for the <cite>NTF to WGS 84 (1)</cite> transformation (EPSG:1193).
+     * Area of validity is France - onshore - mainland and Corsica.
+     * This transformation uses only translation parameters.
+     */
+    static BursaWolfParameters createNTF_to_WGS84() {
+        final BursaWolfParameters bursaWolf = new BursaWolfParameters(WGS84, Extents.WORLD);
+        bursaWolf.tX = -168;
+        bursaWolf.tY =  -60;
+        bursaWolf.tZ =  320;
+        bursaWolf.verify();
+        assertFalse("isIdentity",    bursaWolf.isIdentity());
+        assertTrue ("isTranslation", bursaWolf.isTranslation());
         return bursaWolf;
     }
 
@@ -112,6 +132,15 @@ public final strictfp class BursaWolfPar
         final MatrixSIS target  = Matrices.create(4, 1, new double[] {3657660.78, 255778.43, 5201387.75, 1});
         assertMatrixEquals("toWGS84", target, toWGS84.multiply(source), 0.01);
         assertMatrixEquals("toWGS72", source, toWGS72.multiply(target), 0.01);
+        /*
+         * Tests the optimized path for translation-only parameters.
+         * Matrices having only translation terms are much easier to predict.
+         */
+        assertMatrixEquals("Translation only", new Matrix4(
+                1, 0, 0, -168,
+                0, 1, 0,  -60,
+                0, 0, 1,  320,
+                0, 0, 0,    1), getPositionVectorTransformation(createNTF_to_WGS84()), 0);
     }
 
     /**

Modified: sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultVerticalDatumTest.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -17,13 +17,17 @@
 package org.apache.sis.referencing.datum;
 
 import java.lang.reflect.Field;
+import javax.xml.bind.JAXBException;
+import org.opengis.metadata.extent.GeographicBoundingBox;
 import org.opengis.referencing.datum.VerticalDatumType;
 import org.apache.sis.internal.referencing.VerticalDatumTypes;
 import org.apache.sis.test.DependsOn;
 import org.junit.Test;
 
-import static org.apache.sis.referencing.Assert.*;
 import static java.util.Collections.singletonMap;
+import static org.apache.sis.referencing.Assert.*;
+import static org.apache.sis.test.TestUtilities.getSingleton;
+import static org.apache.sis.referencing.GeodeticObjectVerifier.*;
 
 
 /**
@@ -75,4 +79,23 @@ public final strictfp class DefaultVerti
         datum = new DefaultVerticalDatum(singletonMap(DefaultVerticalDatum.NAME_KEY, "Ellipsoidal"), VerticalDatumTypes.ELLIPSOIDAL);
         assertWktEquals(datum, "VERT_DATUM[“Ellipsoidal”, 2002]");
     }
+
+    /**
+     * Tests unmarshalling.
+     *
+     * @throws JAXBException If an error occurred during unmarshalling.
+     */
+    @Test
+    public void testUnmarshalling() throws JAXBException {
+        final DefaultVerticalDatum datum = unmarshall(DefaultVerticalDatum.class, "Mean Sea Level.xml");
+        assertIsMeanSeaLevel(datum);
+        assertIsWorld((GeographicBoundingBox) getSingleton(datum.getDomainOfValidity().getGeographicElements()));
+        /*
+         * Values in the following tests are specific to our XML file.
+         * The actual texts in the EPSG database are more descriptive.
+         */
+        assertEquals("remarks",          "Approximates geoid.",             datum.getRemarks().toString());
+        assertEquals("scope",            "Hydrography.",                    datum.getScope().toString());
+        assertEquals("anchorDefinition", "Averaged over a 19-year period.", datum.getAnchorPoint().toString());
+    }
 }

Modified: sis/branches/JDK6/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/WGS 84.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/WGS%2084.xml?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/WGS 84.xml (original)
+++ sis/branches/JDK6/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/WGS 84.xml Tue Dec 31 23:50:03 2013
@@ -22,7 +22,6 @@
                    xmlns:gmd          = "http://www.isotc211.org/2005/gmd"
                    xmlns:gco          = "http://www.isotc211.org/2005/gco"
                    xmlns:xsi          = "http://www.w3.org/2001/XMLSchema-instance"
-                   xmlns:xlink        = "http://www.w3.org/1999/xlink"
                    gml:id             = "epsg-datum-6326">
 
   <gml:identifier codeSpace="OGP">urn:ogc:def:datum:EPSG::6326</gml:identifier>

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -208,44 +208,13 @@ public final class Numerics extends Stat
     }
 
     /**
-     * Alters the given seed with the hash code value computed from the given value.
+     * Returns a hash code value for the given long.
      *
-     * @param  value The value whose hash code to compute.
-     * @param  seed  The hash code value computed so far. If this method is invoked for the first
-     *               field, then any arbitrary value (preferably different for each class) is okay.
-     * @return An updated hash code value.
+     * @param  c The value to hash.
+     * @return Hash code value for the given long.
      */
-    public static int hash(final float value, final int seed) {
-        /*
-         * Multiplication by prime number produces better hash code distribution.
-         * Value 31 is often used because some modern compilers can optimize x*31
-         * as  (x << 5) - x    (Josh Bloch, Effective Java).
-         */
-        return 31*seed + Float.floatToIntBits(value);
-    }
-
-    /**
-     * Alters the given seed with the hash code value computed from the given value.
-     *
-     * @param  value The value whose hash code to compute.
-     * @param  seed  The hash code value computed so far. If this method is invoked for the first
-     *               field, then any arbitrary value (preferably different for each class) is okay.
-     * @return An updated hash code value.
-     */
-    public static int hash(final double value, final int seed) {
-        return hash(Double.doubleToLongBits(value), seed);
-    }
-
-    /**
-     * Alters the given seed with the hash code value computed from the given value.
-     *
-     * @param  value The value whose hash code to compute.
-     * @param  seed  The hash code value computed so far. If this method is invoked for the first
-     *               field, then any arbitrary value (preferably different for each class) is okay.
-     * @return An updated hash code value.
-     */
-    public static int hash(final long value, final int seed) {
-        return 31*seed + (((int) value) ^ ((int) (value >>> 32)));
+    public static int hashCode(final long c) {
+        return ((int) c) ^ (int) (c >>> Integer.SIZE);
     }
 
     /**

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/math/DecimalFunctions.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -18,6 +18,7 @@ package org.apache.sis.math;
 
 import org.apache.sis.util.Static;
 import org.apache.sis.util.Workaround;
+import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.internal.util.Numerics;
 
 import static org.apache.sis.internal.util.Numerics.SIGNIFICAND_SIZE;
@@ -407,8 +408,8 @@ public final class DecimalFunctions exte
      *           of a <code>double</code> value, padding with trailing zeros if necessary, but no more than
      *           necessary.}
      *
-     * @param  value The value for which to get the number of significant digits.
-     * @return The number of significant digits (may be negative), or 0 if {@code value} is NaN or infinity.
+     * @param  value The value for which to get the number of significant fraction digits.
+     * @return The number of significant fraction digits (may be negative), or 0 if {@code value} is NaN or infinity.
      *
      * @see java.text.NumberFormat#setMinimumFractionDigits(int)
      */
@@ -426,4 +427,50 @@ public final class DecimalFunctions exte
         }
         return 0;
     }
+
+    /**
+     * Returns the number of significant fraction digits, potentially minus trailing digits that may be rounding error.
+     * First, this method gets the number of fraction digits as of {@link #fractionDigitsForValue(double)}. Then there
+     * is a choice:
+     *
+     * <ul>
+     *   <li>If after rounding the given {@code value} to an amount of fraction digits given by ({@code fractionDigits}
+     *       - {@code uncertainDigits}) the 4 last fraction digits before the rounded ones are zero, then this method
+     *       returns {@code fractionDigits} - {@code uncertainDigits}.</li>
+     *   <li>Otherwise this method returns {@code fractionDigits}.</li>
+     * </ul>
+     *
+     * Examples:
+     *
+     * <ul>
+     *   <li>{@code fractionDigitsForValue(179.12499999999824)} returns 14,
+     *       the amount of digits after the decimal separator.</li>
+     *   <li>{@code fractionDigitsForValue(179.12499999999824, 3)} returns 11 because rounding the 3 last digits
+     *       (i.e. rounding after the 11<sup>th</sup> digit) results in 179.125000000000.
+     *       Since the 4 last fraction digits are zero, the condition for allowing that rounding is meet.</li>
+     *   <li>{@code fractionDigitsForValue(179.12499999999824, 2)} returns 14 because rounding the 2 last digits
+     *       (i.e. rounding after the 12<sup>th</sup> digit) results in 179.124999999998.
+     *       The condition for 4 trailing zero fraction digits is not meet.</li>
+     *   <li>{@code fractionDigitsForValue(179.12499997999999, 3)} returns 14 because rounding the 3 last digits
+     *       results in 179.12499997000. The condition for 4 trailing zero fraction digits is not meet.</li>
+     * </ul>
+     *
+     * {@note The threshold of 4 trailing fraction digits is arbitrary and may change in any future SIS version.}
+     *
+     * @param  value The value for which to get the number of significant fraction fraction digits minus rounding error.
+     * @param  uncertainDigits Number of trailing fraction digits which may be rounding error artefacts.
+     * @return Suggested number of significant digits (may be negative), or 0 if {@code value} is NaN or infinity.
+     */
+    public static int fractionDigitsForValue(double value, final int uncertainDigits) {
+        ArgumentChecks.ensurePositive("uncertainDigits", uncertainDigits);
+        int digits = fractionDigitsForValue(value);
+        final int reduced = digits - uncertainDigits;
+        if (reduced > 0) {
+            value *= pow10(reduced);
+            if ((Math.rint(value) % 10000) == 0) {
+                return reduced;
+            }
+        }
+        return digits;
+    }
 }

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -70,7 +70,7 @@ import static org.apache.sis.internal.jd
  * {@section Handling of null values}
  * Most methods in this class accept a {@code null} {@code CharSequence} argument. In such cases
  * the method return value is either a {@code null} {@code CharSequence}, an empty array, or a
- * {@code int} primitive type calculated as if the input was an empty string.
+ * {@code 0} or {@code false} primitive type calculated as if the input was an empty string.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
@@ -123,11 +123,12 @@ public final class CharSequences extends
     /**
      * Returns a character sequence of the specified length filled with white spaces.
      *
-     * <p>This method is typically used for performing right-alignment of text on the
+     * {@section Use case}
+     * This method is typically invoked for performing right-alignment of text on the
      * {@linkplain java.io.Console console} or other device using monospaced font.
-     * The {@code length} argument is then calculated by (<var>desired width</var> -
-     * <var>used width</var>). Since the used width may be greater than expected,
-     * this method accepts negative {@code length} values as if they were zero.</p>
+     * Callers compute a value for the {@code length} argument by (<var>desired width</var> - <var>used width</var>).
+     * Since the <var>used width</var> value may be greater than expected, this method handle negative {@code length}
+     * values as if the value was zero.
      *
      * @param  length The string length. Negative values are clamped to 0.
      * @return A string of length {@code length} filled with white spaces.
@@ -318,15 +319,17 @@ public final class CharSequences extends
      * @param  toSearch  The substring for which to search.
      * @param  fromIndex The index from which to start the search.
      * @param  toIndex   The index after the last character where to perform the search.
-     * @return The index within the text of the first occurrence of the specified part,
-     *         starting at the specified index, or -1 if none.
-     * @throws NullPointerException if any of the arguments is null.
+     * @return The index within the text of the first occurrence of the specified part, starting at the specified
+     *         index, or -1 if no occurrence has been found or if the {@code text} argument is null.
+     * @throws NullArgumentException If the {@code toSearch} argument is null.
+     * @throws IllegalArgumentException If the {@code toSearch} argument is empty.
      *
      * @see String#indexOf(String, int)
      * @see StringBuilder#indexOf(String, int)
      * @see StringBuffer#indexOf(String, int)
      */
     public static int indexOf(final CharSequence text, final CharSequence toSearch, int fromIndex, int toIndex) {
+        ArgumentChecks.ensureNonEmpty("toSearch", toSearch);
         if (text != null) {
             int length = text.length();
             if (toIndex > length) {
@@ -554,6 +557,7 @@ search:     for (; fromIndex <= toIndex;
      * @param  toIndex   The index after the last character where to perform the search.
      * @return The index within the text of the first occurrence of a non-space character, starting
      *         at the specified index, or a value equals or greater than {@code toIndex} if none.
+     * @throws NullPointerException if the {@code text} argument is null.
      *
      * @see #skipTrailingWhitespaces(CharSequence, int, int)
      * @see #trimWhitespaces(CharSequence)
@@ -590,6 +594,7 @@ search:     for (; fromIndex <= toIndex;
      * @param  toIndex   The index after the last character where to perform the search.
      * @return The index within the text of the last occurrence of a non-space character, starting
      *         at the specified index, or a value equals or lower than {@code fromIndex} if none.
+     * @throws NullPointerException if the {@code text} argument is null.
      *
      * @see #skipLeadingWhitespaces(CharSequence, int, int)
      * @see #trimWhitespaces(CharSequence)
@@ -1021,17 +1026,19 @@ search:     for (; fromIndex <= toIndex;
      * @param  text  The text from which to remove leading and trailing white spaces.
      * @param  lower Index of the first character to consider for inclusion in the sub-sequence.
      * @param  upper Index after the last character to consider for inclusion in the sub-sequence.
-     * @return A characters sequence with leading and trailing white spaces removed.
-     * @throws NullPointerException If {@code text} is {@code null}.
+     * @return A characters sequence with leading and trailing white spaces removed, or {@code null}
+     *         if the {@code text} argument is null.
      * @throws IndexOutOfBoundsException If {@code lower} or {@code upper} is out of bounds.
      */
     public static CharSequence trimWhitespaces(CharSequence text, int lower, int upper) {
-        final int length = text.length();
+        final int length = length(text);
         ArgumentChecks.ensureValidIndexRange(length, lower, upper);
-        lower = skipLeadingWhitespaces (text, lower, upper);
-        upper = skipTrailingWhitespaces(text, lower, upper);
-        if (lower != 0 || upper != length) { // Safety in case subSequence doesn't make the check.
-            text = text.subSequence(lower, upper);
+        if (text != null) {
+            lower = skipLeadingWhitespaces (text, lower, upper);
+            upper = skipTrailingWhitespaces(text, lower, upper);
+            if (lower != 0 || upper != length) { // Safety in case subSequence doesn't make the check.
+                text = text.subSequence(lower, upper);
+            }
         }
         return text;
     }
@@ -1230,16 +1237,14 @@ searchWordBreak:    while (true) {
      * </ol>
      *
      * {@section Exception to the above rules}
-     * If the given identifier contains only upper-case letters, digits and the {@code '_'}
-     * character, then the identifier is returned "as is" except for the {@code '_'} characters
-     * which are replaced by {@code '-'}. This work well for identifiers like {@code "UTF-8"} or
-     * {@code "ISO-LATIN-1"} for example.
+     * If the given identifier contains only upper-case letters, digits and the {@code '_'} character,
+     * then the identifier is returned "as is" except for the {@code '_'} characters which are replaced by {@code '-'}.
+     * This work well for identifiers like {@code "UTF-8"} or {@code "ISO-LATIN-1"} for instance.
      *
      * <p>Note that those heuristic rules may be modified in future SIS versions,
      * depending on the practical experience gained.</p>
      *
-     * @param  identifier An identifier with no space, words begin with an upper-case character,
-     *         or {@code null}.
+     * @param  identifier An identifier with no space, words begin with an upper-case character, or {@code null}.
      * @return The identifier with spaces inserted after what looks like words, or {@code null}
      *         if the given {@code identifier} argument was null.
      */
@@ -1407,25 +1412,26 @@ searchWordBreak:    while (true) {
      * one character from the same word may appear in the acronym, but they must always
      * be the first consecutive characters. The comparison is case-insensitive.
      *
-     * <p><b>Example:</b> given the string {@code "Open Geospatial Consortium"}, the following
-     * strings are recognized as acronyms: {@code "OGC"}, {@code "ogc"}, {@code "O.G.C."},
-     * {@code "OpGeoCon"}.</p>
+     * {@example Given the <code>"Open Geospatial Consortium"</code> words, the following strings are
+     *           recognized as acronyms: <code>"OGC"</code>, <code>"ogc"</code>, <code>"O.G.C."</code>,
+     *           <code>"OpGeoCon"</code>.}
      *
-     * @param  acronym A possible acronym of the sequence of words.
-     * @param  words The sequence of words.
+     * If any of the given arguments is {@code null}, this method returns {@code false}.
+     *
+     * @param  acronym A possible acronym of the sequence of words, or {@code null}.
+     * @param  words The sequence of words, or {@code null}.
      * @return {@code true} if the first string is an acronym of the second one.
-     * @throws NullPointerException if any of the arguments is null.
      */
     public static boolean isAcronymForWords(final CharSequence acronym, final CharSequence words) {
-        final int lgc = words.length();
-        final int lga = acronym.length();
-        int ic=0, ia=0;
-        int ca, cc;
+        final int lga = length(acronym);
+        int ia=0, ca;
         do {
             if (ia >= lga) return false;
             ca = codePointAt(acronym, ia);
             ia += charCount(ca);
         } while (!isLetterOrDigit(ca));
+        final int lgc = length(words);
+        int ic=0, cc;
         do {
             if (ic >= lgc) return false;
             cc = codePointAt(words, ic);
@@ -1517,12 +1523,11 @@ cmp:    while (ia < lga) {
      * Unicode identifier start} and all remaining characters (if any) are
      * {@linkplain Character#isUnicodeIdentifierPart(int) Unicode identifier parts}.
      *
-     * @param  identifier The character sequence to test.
+     * @param  identifier The character sequence to test, or {@code null}.
      * @return {@code true} if the given character sequence is a legal Unicode identifier.
-     * @throws NullPointerException if the argument is null.
      */
     public static boolean isUnicodeIdentifier(final CharSequence identifier) {
-        final int length = identifier.length();
+        final int length = length(identifier);
         if (length == 0) {
             return false;
         }
@@ -1548,7 +1553,6 @@ cmp:    while (ia < lga) {
      *
      * @param  text The character sequence to test.
      * @return {@code true} if every character are upper-case.
-     * @throws NullPointerException if the argument is null.
      *
      * @see String#toUpperCase()
      */

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -724,7 +724,7 @@ public class DefaultTreeTable implements
                 // Do not use Objects.hashCode(...) because we want the result of array
                 // containing only null elements to be the same than null array (zero).
                 for (int i=values.length; --i>=0;) {
-                    hash = 31*hash + Objects.hash(values[i]);
+                    hash = 31*hash + Objects.hashCode(values[i]);
                 }
             }
             // Do not use Objects.hashCode(...) because we

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/math/DecimalFunctionsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/math/DecimalFunctionsTest.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/math/DecimalFunctionsTest.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/math/DecimalFunctionsTest.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -231,11 +231,16 @@ public final strictfp class DecimalFunct
     public void testFractionDigitsForValue() {
         assertEquals(-EXPONENT_FOR_ZERO, fractionDigitsForValue(0));
         assertEquals(-EXPONENT_FOR_ZERO, fractionDigitsForValue(MIN_VALUE));
-        assertEquals(                16, fractionDigitsForValue(1));
-        assertEquals(                15, fractionDigitsForValue(45));
-        assertEquals(                 0, fractionDigitsForValue(NaN));
-        assertEquals(                 0, fractionDigitsForValue(POSITIVE_INFINITY));
-        assertEquals(                 0, fractionDigitsForValue(NEGATIVE_INFINITY));
+        assertEquals(16, fractionDigitsForValue(1));
+        assertEquals(15, fractionDigitsForValue(45));
+        assertEquals(15, fractionDigitsForValue(39.666666666666667));
+        assertEquals(15, fractionDigitsForValue(-8.131906111111111));
+        assertEquals(16, fractionDigitsForValue(0.6149999999999993));
+        assertEquals(17, fractionDigitsForValue(-0.198));
+        assertEquals(14, fractionDigitsForValue(179.12499999999824));
+        assertEquals( 0, fractionDigitsForValue(NaN));
+        assertEquals( 0, fractionDigitsForValue(POSITIVE_INFINITY));
+        assertEquals( 0, fractionDigitsForValue(NEGATIVE_INFINITY));
         for (int i=EXPONENT_FOR_ZERO; i<=EXPONENT_FOR_MAX; i++) {
             final double value = pow10(i);
             final double accuracy = pow10(-fractionDigitsForValue(value));
@@ -247,4 +252,24 @@ public final strictfp class DecimalFunct
             assertEquals("Shall not be greater than ULP", 0, accuracy, StrictMath.ulp(value));
         }
     }
+
+    /**
+     * Tests {@link DecimalFunctions#fractionDigitsForValue(double, int)}.
+     */
+    @Test
+    @DependsOnMethod("testFractionDigitsForValue")
+    public void testFractionDigitsForValue2() {
+        assertEquals(-EXPONENT_FOR_ZERO, fractionDigitsForValue(0, 2));
+        assertEquals(0, fractionDigitsForValue(POSITIVE_INFINITY,  2));
+
+        assertEquals("Expected no rounding", 15, fractionDigitsForValue(39.666666666666667,  2));
+        assertEquals("Expected no rounding", 15, fractionDigitsForValue(-8.131906111111111,  2));
+        assertEquals("Expected no rounding", 16, fractionDigitsForValue( 0.6149999999999993, 1));
+        assertEquals("Expected rounding",    14, fractionDigitsForValue( 0.6149999999999993, 2));
+        assertEquals("Expected rounding",    14, fractionDigitsForValue(-0.6149999999999993, 2));
+        assertEquals("Expected rounding",    15, fractionDigitsForValue(-0.1979999999999998, 2));
+        assertEquals("Expected rounding",    11, fractionDigitsForValue( 179.12499999999824, 3));
+        assertEquals("Expected no rounding", 14, fractionDigitsForValue( 179.12499999999824, 2));
+        assertEquals("Expected no rounding", 14, fractionDigitsForValue( 179.12499997999999, 3));
+    }
 }

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java?rev=1554592&r1=1554591&r2=1554592&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java [UTF-8] Tue Dec 31 23:50:03 2013
@@ -73,6 +73,8 @@ public final strictfp class CharSequence
         assertEquals(0, count(new StringBuilder("An ordinary sentence."),   '-'));
         assertEquals(4, count(new StringBuilder("- this one has -dashs--"), '-'));
         assertEquals(2, count(new StringBuilder("An ordinary sentence."),  "en"));
+        assertEquals(0, count("",   '-'));
+        assertEquals(0, count(null, '-'));
     }
 
     /**
@@ -97,6 +99,8 @@ public final strictfp class CharSequence
             assertEquals(12, indexOf(string, "sentence.", 0, length));
             assertEquals(-1, indexOf(string, "sentence;", 0, length));
         }
+        assertEquals(-1, indexOf("",   "An", 0, 0));
+        assertEquals(-1, indexOf(null, "An", 0, 0));
     }
 
     /**
@@ -130,6 +134,8 @@ public final strictfp class CharSequence
             assertEquals(13,           indexOf(string, 'e', 0, length));
             assertEquals(19,       lastIndexOf(string, 'e', 0, length));
         }
+        assertEquals(-1, indexOf("",   'A', 0, 0));
+        assertEquals(-1, indexOf(null, 'A', 0, 0));
     }
 
     /**
@@ -155,6 +161,8 @@ public final strictfp class CharSequence
     public void testSplit() {
         assertArrayEquals(new String[] {"lundi", "mardi", "", "mercredi"}, split("lundi , mardi,,mercredi ", ','));
         assertArrayEquals(new String[] {"lundi", "mardi", "", "mercredi"}, split("lundi \n mardi\r\n\nmercredi ", '\n'));
+        assertArrayEquals(new String[] {""}, split("",   ','));
+        assertArrayEquals(new String[] {},   split(null, ','));
     }
 
     /**
@@ -164,9 +172,9 @@ public final strictfp class CharSequence
     @DependsOnMethod("testIndexOfChar")
     public void testSplitOnEOL() {
         final CharSequence[] splitted = splitOnEOL("\nOne\r\nTwo\rThree \rFour\n Five\n\r Six \n");
-        assertArrayEquals(new String[] {
-            "", "One", "Two", "Three ", "Four", " Five", "", " Six ", ""
-        }, splitted);
+        assertArrayEquals(new String[] {"", "One", "Two", "Three ", "Four", " Five", "", " Six ", ""}, splitted);
+        assertArrayEquals(new String[] {""}, splitOnEOL(""));
+        assertArrayEquals(new String[] {},   splitOnEOL(null));
     }
 
     /**
@@ -230,6 +238,7 @@ public final strictfp class CharSequence
     public void testToString() {
         assertEquals("4, 8, 12, 9", CharSequences.toString(Arrays.asList(4, 8, 12, 9), ", "));
         assertSame  ("singleton",   CharSequences.toString(Arrays.asList("singleton"), ", "));
+        assertNull  (               CharSequences.toString(null, ", "));
     }
 
     /**
@@ -240,6 +249,7 @@ public final strictfp class CharSequence
         final String metre = "metre";
         assertSame  (metre, toASCII(metre));
         assertEquals(metre, toASCII("mètre").toString());
+        assertNull  (       toASCII(null));
     }
 
     /**
@@ -251,6 +261,8 @@ public final strictfp class CharSequence
         assertEquals("A text.", trimWhitespaces((CharSequence) "  A text. "));
         assertEquals("",        trimWhitespaces(               "          "));
         assertEquals("",        trimWhitespaces((CharSequence) "          "));
+        assertNull  (           trimWhitespaces((CharSequence) null));
+        assertNull  (           trimWhitespaces((String)       null));
     }
 
     /**
@@ -263,6 +275,7 @@ public final strictfp class CharSequence
         assertEquals("4",    trimFractionalPart("4.0"));
         assertEquals("4",    trimFractionalPart("4.00"));
         assertEquals("4.10", trimFractionalPart("4.10"));
+        assertNull  (        trimFractionalPart(null));
     }
 
     /**
@@ -272,6 +285,7 @@ public final strictfp class CharSequence
     public void testShortSentence() {
         assertEquals("This sentence given (…) in a short name.", String.valueOf(
                 shortSentence("This sentence given as an example is way too long to be included in a short name.", 40)));
+        assertNull(shortSentence(null, 40));
     }
 
     /**
@@ -279,8 +293,8 @@ public final strictfp class CharSequence
      */
     @Test
     public void testUpperCaseToSentence() {
-        final CharSequence convert = upperCaseToSentence("HALF_DOWN");
-        assertEquals("Half down", convert.toString());
+        assertEquals("Half down", upperCaseToSentence("HALF_DOWN").toString());
+        assertNull(upperCaseToSentence(null));
     }
 
     /**
@@ -290,6 +304,7 @@ public final strictfp class CharSequence
     public void testCamelCaseToWords() {
         final CharSequence convert = camelCaseToWords("PixelInterleavedSampleModel", true);
         assertEquals("Pixel interleaved sample model", convert.toString());
+        assertNull(camelCaseToWords(null, true));
     }
 
     /**
@@ -303,6 +318,7 @@ public final strictfp class CharSequence
         assertEquals("NE",  camelCaseToAcronym("North-East").toString());
         assertEquals("NE",  camelCaseToAcronym("NORTH_EAST").toString());
         assertEquals("NE",  camelCaseToAcronym("northEast").toString());
+        assertNull(camelCaseToAcronym(null));
     }
 
     /**
@@ -351,6 +367,7 @@ public final strictfp class CharSequence
         assertTrue(isAcronymForWords("versionhistory",            "[Version History]"));
         assertTrue(isAcronymForWords("change",                    "[Change]"));
         assertTrue(isAcronymForWords("deprecation",               "[Deprecation]"));
+        assertFalse(isAcronymForWords(null,                       "[Deprecation]"));
         /*
          * It is important the the following is not recognized as an acronym,
          * otherwise it leads to a confusion in DirectEpsgFactory.
@@ -365,6 +382,7 @@ public final strictfp class CharSequence
     public void testIsUnicodeIdentifier() {
         assertTrue ("A123", isUnicodeIdentifier("A123"));
         assertFalse("123A", isUnicodeIdentifier("123A"));
+        assertFalse(        isUnicodeIdentifier(null));
     }
 
     /**
@@ -385,6 +403,8 @@ public final strictfp class CharSequence
         assertTrue (equalsIgnoreCase("Test", "TEST"));
         assertTrue (equalsIgnoreCase("Test", new StringBuilder("TEST")));
         assertFalse(equalsIgnoreCase("Test1", "Test2"));
+        assertFalse(equalsIgnoreCase(null,    "Test2"));
+        assertFalse(equalsIgnoreCase("Test1", null));
     }
 
     /**
@@ -398,6 +418,7 @@ public final strictfp class CharSequence
         assertFalse(equalsFiltered("UTF-8", " utf 16", Characters.Filter.LETTERS_AND_DIGITS, true));
         assertTrue (equalsFiltered("WGS84", "WGS_84",  Characters.Filter.LETTERS_AND_DIGITS, true));
         assertFalse(equalsFiltered("WGS84", "WGS_84",  Characters.Filter.UNICODE_IDENTIFIER, true));
+        assertFalse(equalsFiltered(null,    "WGS_84",  Characters.Filter.UNICODE_IDENTIFIER, true));
     }
 
     /**
@@ -407,6 +428,8 @@ public final strictfp class CharSequence
     public void testEquals() {
         assertTrue (CharSequences.equals("Test", new StringBuilder("Test")));
         assertFalse(CharSequences.equals("Test1", "Test2"));
+        assertFalse(CharSequences.equals(null,    "Test2"));
+        assertFalse(CharSequences.equals("Test1", null));
     }
 
     /**
@@ -472,6 +495,7 @@ public final strictfp class CharSequence
         assertSame(text, replace(text, "pineapple", "orange"));
         assertEquals("One orange, two orange oranges", replace(text, "apple", "orange").toString());
         assertEquals("One apple, two apple apples",    replace(text, "orange", "apple").toString());
+        assertNull(replace(null, "orange", "apple"));
     }
 
     /**



Mime
View raw message