Author: desruisseaux
Date: Thu Feb 16 08:47:18 2017
New Revision: 1783181

URL: http://svn.apache.org/viewvc?rev=1783181&view=rev
Log:
Fix a regression caused by the new unit framework, when 
equalsIgnoreMetadata(...) fails to detect that 2 units are equivalent even if 
not defined in exactly the same way.

Modified:
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
    
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AbstractUnit.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConcatenatedConverter.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConventionalUnit.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java

Modified: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java?rev=1783181&r1=1783180&r2=1783181&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
 [UTF-8] Thu Feb 16 08:47:18 2017
@@ -28,6 +28,7 @@ import org.opengis.parameter.ParameterVa
 import org.opengis.parameter.ParameterDescriptor;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.Numbers;
+import org.apache.sis.util.Utilities;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.measure.Range;
@@ -67,7 +68,7 @@ import static org.apache.sis.util.Argume
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Johann Sorel (Geomatys)
  * @since   0.4
- * @version 0.6
+ * @version 0.8
  * @module
  *
  * @see DefaultParameterValue
@@ -468,7 +469,7 @@ public class DefaultParameterDescriptor<
                     final ParameterDescriptor<?> that = 
(ParameterDescriptor<?>) object;
                     return getValueClass() == that.getValueClass() &&
                            Objects.deepEquals(getDefaultValue(), 
that.getDefaultValue()) &&
-                           Objects.equals(getUnit(), that.getUnit()) &&
+                           Utilities.deepEquals(getUnit(), that.getUnit(), 
mode) &&
                            (isHeuristicMatchForName(that.getName().getCode()) 
||
                             IdentifiedObjects.isHeuristicMatchForName(that, 
getName().getCode()));
                 }
@@ -481,7 +482,7 @@ public class DefaultParameterDescriptor<
                            Objects.    equals(getMinimumValue(), 
that.getMinimumValue()) &&
                            Objects.    equals(getMaximumValue(), 
that.getMaximumValue()) &&
                            Objects.deepEquals(getDefaultValue(), 
that.getDefaultValue()) &&
-                           Objects.    equals(getUnit(),         
that.getUnit());
+                           Utilities.deepEquals(getUnit(),       
that.getUnit(), mode);
                 }
                 case STRICT: {
                     final DefaultParameterDescriptor<?> that = 
(DefaultParameterDescriptor<?>) object;

Modified: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java?rev=1783181&r1=1783180&r2=1783181&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
 [UTF-8] Thu Feb 16 08:47:18 2017
@@ -118,7 +118,7 @@ import static org.apache.sis.util.Utilit
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.7
+ * @version 0.8
  * @module
  *
  * @see DefaultParameterDescriptor
@@ -787,8 +787,8 @@ public class DefaultParameterValue<T> ex
             } else if (object instanceof ParameterValue<?>) {
                 final ParameterValue<?> that = (ParameterValue<?>) object;
                 return deepEquals(getDescriptor(), that.getDescriptor(), mode) 
&&
-                       deepEquals(getValue(),      that.getValue(), mode) &&
-                       Objects.equals(getUnit(),   that.getUnit());
+                       deepEquals(getValue(),      that.getValue(),      mode) 
&&
+                       deepEquals(getUnit(),       that.getUnit(),       mode);
             }
         }
         return false;

Modified: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java?rev=1783181&r1=1783180&r2=1783181&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
 [UTF-8] Thu Feb 16 08:47:18 2017
@@ -19,6 +19,7 @@ package org.apache.sis.referencing.cs;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Locale;
+import java.util.Objects;
 import javax.measure.Unit;
 import javax.measure.quantity.Angle;
 import javax.measure.UnitConverter;
@@ -45,6 +46,7 @@ import org.apache.sis.referencing.Identi
 import org.apache.sis.measure.Longitude;
 import org.apache.sis.measure.Latitude;
 import org.apache.sis.measure.Units;
+import org.apache.sis.util.Utilities;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.jaxb.Context;
@@ -69,9 +71,6 @@ import static org.apache.sis.util.collec
  */
 import static org.apache.sis.internal.referencing.NilReferencingObject.UNNAMED;
 
-// Branch-dependent imports
-import java.util.Objects;
-
 
 /**
  * Coordinate system axis name, direction, unit and range of values.
@@ -567,12 +566,13 @@ public class DefaultCoordinateSystemAxis
      * i.e. it is caller responsibility to determine if range shall be 
considered as metadata.
      *
      * @param  that  the axis to compare with this axis.
+     * @param  mode  whether the unit comparison is approximative or exact.
      * @param  cr    {@code true} for comparing also the range minimum and 
maximum values.
      * @return {@code true} if unit, direction and optionally range extremum 
are equal.
      */
-    private boolean equalsIgnoreMetadata(final CoordinateSystemAxis that, 
final boolean cr) {
-        return Objects.equals(getUnit(),      that.getUnit()) &&
-               Objects.equals(getDirection(), that.getDirection()) &&
+    private boolean equalsIgnoreMetadata(final CoordinateSystemAxis that, 
final ComparisonMode mode, final boolean cr) {
+        return Objects.equals(getDirection(), that.getDirection()) &&
+               Utilities.deepEquals(getUnit(), that.getUnit(), mode) &&
                (!cr || (doubleToLongBits(getMinimumValue()) == 
doubleToLongBits(that.getMinimumValue()) &&
                         doubleToLongBits(getMaximumValue()) == 
doubleToLongBits(that.getMaximumValue())));
     }
@@ -618,7 +618,7 @@ public class DefaultCoordinateSystemAxis
             }
             case BY_CONTRACT: {
                 final CoordinateSystemAxis that = (CoordinateSystemAxis) 
object;
-                return equalsIgnoreMetadata(that, true) &&
+                return equalsIgnoreMetadata(that, mode, true) &&
                        Objects.equals(getAbbreviation(), 
that.getAbbreviation()) &&
                        Objects.equals(getRangeMeaning(), 
that.getRangeMeaning());
             }
@@ -629,8 +629,8 @@ public class DefaultCoordinateSystemAxis
          * coordinate operation may shift some ordinate values (typically 
±360° on longitudes).
          */
         final CoordinateSystemAxis that = (CoordinateSystemAxis) object;
-        if (!equalsIgnoreMetadata(that, 
RangeMeaning.WRAPAROUND.equals(this.getRangeMeaning()) &&
-                                        
RangeMeaning.WRAPAROUND.equals(that.getRangeMeaning())))
+        if (!equalsIgnoreMetadata(that, mode, 
RangeMeaning.WRAPAROUND.equals(this.getRangeMeaning()) &&
+                                              
RangeMeaning.WRAPAROUND.equals(that.getRangeMeaning())))
         {
             return false;
         }

Modified: 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1783181&r1=1783180&r2=1783181&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
 [UTF-8] Thu Feb 16 08:47:18 2017
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing.datum;
 
 import java.util.Map;
+import java.util.Objects;
 import javax.measure.Unit;
 import javax.measure.quantity.Length;
 import javax.measure.UnitConverter;
@@ -42,6 +43,7 @@ import org.apache.sis.referencing.Abstra
 import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.io.wkt.Convention;
 import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.Utilities;
 import org.apache.sis.measure.Units;
 
 import static java.lang.Math.*;
@@ -49,9 +51,6 @@ import static java.lang.Double.*;
 import static org.apache.sis.util.ArgumentChecks.ensureStrictlyPositive;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 
-// Branch-dependent imports
-import java.util.Objects;
-
 
 /**
  * Geometric figure that can be used to describe the approximate shape of the 
earth.
@@ -717,7 +716,7 @@ public class DefaultEllipsoid extends Ab
                  */
                 final Ellipsoid that = (Ellipsoid) object;
                 final Unit<Length> unit = getAxisUnit();  // In case the user 
override this method.
-                if (!Objects.equals(unit, that.getAxisUnit())) {
+                if (!Utilities.deepEquals(unit, that.getAxisUnit(), mode)) {
                     return false;
                 }
                 final UnitConverter c = mode.isApproximative() ? 
unit.getConverterTo(Units.METRE) : null;

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AbstractUnit.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AbstractUnit.java?rev=1783181&r1=1783180&r2=1783181&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AbstractUnit.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/AbstractUnit.java
 [UTF-8] Thu Feb 16 08:47:18 2017
@@ -27,6 +27,8 @@ import javax.measure.Quantity;
 import org.apache.sis.math.Fraction;
 import org.apache.sis.util.Characters;
 import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.LenientComparable;
 import org.apache.sis.util.resources.Errors;
 
 
@@ -57,7 +59,7 @@ import org.apache.sis.util.resources.Err
  * @version 0.8
  * @module
  */
-abstract class AbstractUnit<Q extends Quantity<Q>> implements Unit<Q>, 
Serializable {
+abstract class AbstractUnit<Q extends Quantity<Q>> implements Unit<Q>, 
LenientComparable, Serializable {
     /**
      * For cross-version compatibility.
      */
@@ -270,16 +272,28 @@ abstract class AbstractUnit<Q extends Qu
     /**
      * Compares this unit with the given object for equality.
      *
-     * @param  other  the other object to compares with this unit, or {@code 
null}.
-     * @return {@code true} if the given object is equals to this unit.
+     * @param  other  the other object to compare with this unit, or {@code 
null}.
+     * @return {@code true} if the given object is equal to this unit.
      */
     @Override
-    public boolean equals(final Object other) {
-        if (other != null && other.getClass() == getClass()) {
-            final AbstractUnit<?> that = (AbstractUnit<?>) other;
-            return epsg == that.epsg && scope == that.scope && 
Objects.equals(symbol, that.symbol);
+    public final boolean equals(final Object other) {
+        return equals(other, ComparisonMode.STRICT);
+    }
+
+    /**
+     * Compares this unit with the given object for equality,
+     * optionally ignoring metadata and rounding errors.
+     */
+    @Override
+    public boolean equals(final Object other, final ComparisonMode mode) {
+        if (other == null || other.getClass() != getClass()) {
+            return false;
+        }
+        if (mode.isIgnoringMetadata()) {
+            return true;
         }
-        return false;
+        final AbstractUnit<?> that = (AbstractUnit<?>) other;
+        return epsg == that.epsg && scope == that.scope && 
Objects.equals(symbol, that.symbol);
     }
 
     /**

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConcatenatedConverter.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConcatenatedConverter.java?rev=1783181&r1=1783180&r2=1783181&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConcatenatedConverter.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConcatenatedConverter.java
 [UTF-8] Thu Feb 16 08:47:18 2017
@@ -20,6 +20,9 @@ import java.util.List;
 import java.util.ArrayList;
 import javax.measure.UnitConverter;
 import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.LenientComparable;
+import org.apache.sis.util.Utilities;
 
 
 /**
@@ -30,7 +33,7 @@ import org.apache.sis.util.ArgumentCheck
  * @version 0.8
  * @module
  */
-final class ConcatenatedConverter extends AbstractConverter {
+final class ConcatenatedConverter extends AbstractConverter implements 
LenientComparable {
     /**
      * For cross-version compatibility.
      */
@@ -161,4 +164,17 @@ final class ConcatenatedConverter extend
         }
         return false;
     }
+
+    /**
+     * Compares this converter with the given object for equality, optionally 
ignoring rounding errors.
+     */
+    @Override
+    public boolean equals(final Object other, final ComparisonMode mode) {
+        if (other instanceof ConcatenatedConverter) {
+            final ConcatenatedConverter o = (ConcatenatedConverter) other;
+            return Utilities.deepEquals(c1, o.c1, mode) &&
+                   Utilities.deepEquals(c2, o.c2, mode);
+        }
+        return false;
+    }
 }

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConventionalUnit.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConventionalUnit.java?rev=1783181&r1=1783180&r2=1783181&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConventionalUnit.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConventionalUnit.java
 [UTF-8] Thu Feb 16 08:47:18 2017
@@ -26,6 +26,8 @@ import javax.measure.IncommensurableExce
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Characters;
+import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.Utilities;
 import org.apache.sis.math.Fraction;
 import org.apache.sis.math.MathFunctions;
 import org.apache.sis.internal.util.Numerics;
@@ -439,19 +441,21 @@ final class ConventionalUnit<Q extends Q
     }
 
     /**
-     * Compares this unit with the given object for equality.
+     * Compares this unit with the given object for equality,
+     * optionally ignoring metadata and rounding errors.
      *
-     * @param  other  the other object to compares with this unit, or {@code 
null}.
-     * @return {@code true} if the given object is equals to this unit.
+     * @param  other  the other object to compare with this unit, or {@code 
null}.
+     * @return {@code true} if the given object is equal to this unit.
      */
     @Override
-    public boolean equals(final Object other) {
+    public boolean equals(final Object other, final ComparisonMode mode) {
         if (other == this) {
             return true;
         }
-        if (super.equals(other)) {
+        if (super.equals(other, mode)) {
             final ConventionalUnit<?> that = (ConventionalUnit<?>) other;
-            return target.equals(that.target) && 
toTarget.equals(that.toTarget);
+            return Utilities.deepEquals(target,   that.target,   mode) &&
+                   Utilities.deepEquals(toTarget, that.toTarget, mode);
         }
         return false;
     }

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java?rev=1783181&r1=1783180&r2=1783181&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/LinearConverter.java
 [UTF-8] Thu Feb 16 08:47:18 2017
@@ -25,6 +25,8 @@ import javax.measure.UnitConverter;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.StringBuilders;
+import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.LenientComparable;
 import org.apache.sis.math.DecimalFunctions;
 import org.apache.sis.math.MathFunctions;
 import org.apache.sis.math.Fraction;
@@ -49,7 +51,7 @@ import org.apache.sis.internal.util.Nume
  * @version 0.8
  * @module
  */
-final class LinearConverter extends AbstractConverter {
+final class LinearConverter extends AbstractConverter implements 
LenientComparable {
     /**
      * For cross-version compatibility.
      */
@@ -450,6 +452,18 @@ final class LinearConverter extends Abst
     }
 
     /**
+     * Compares this converter with the given object for equality, optionally 
ignoring rounding errors.
+     */
+    @Override
+    public boolean equals(final Object other, final ComparisonMode mode) {
+        if (mode.isApproximative()) {
+            return (other instanceof LinearConverter) && 
equivalent((LinearConverter) other);
+        } else {
+            return equals(other);
+        }
+    }
+
+    /**
      * Returns {@code true} if the given converter perform the same conversion 
than this converter,
      * except for rounding errors.
      */

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java?rev=1783181&r1=1783180&r2=1783181&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java
 [UTF-8] Thu Feb 16 08:47:18 2017
@@ -28,6 +28,7 @@ import javax.measure.UnconvertibleExcept
 import javax.measure.IncommensurableException;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ObjectConverters;
+import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.converter.SurjectiveConverter;
 import org.apache.sis.math.Fraction;
@@ -481,17 +482,18 @@ final class SystemUnit<Q extends Quantit
     }
 
     /**
-     * Compares this unit with the given object for equality.
+     * Compares this unit with the given object for equality,
+     * optionally ignoring metadata and rounding errors.
      *
-     * @param  other  the other object to compares with this unit, or {@code 
null}.
-     * @return {@code true} if the given object is equals to this unit.
+     * @param  other  the other object to compare with this unit, or {@code 
null}.
+     * @return {@code true} if the given object is equal to this unit.
      */
     @Override
-    public boolean equals(final Object other) {
+    public boolean equals(final Object other, final ComparisonMode mode) {
         if (other == this) {
             return true;
         }
-        if (super.equals(other)) {
+        if (super.equals(other, mode)) {
             final SystemUnit<?> that = (SystemUnit<?>) other;
             return Objects.equals(quantity, that.quantity) && 
dimension.equals(that.dimension);
         }


Reply via email to