Author: desruisseaux
Date: Sat Dec 15 09:48:48 2012
New Revision: 1422211
URL: http://svn.apache.org/viewvc?rev=1422211&view=rev
Log:
Removed Utilities.equals(float,float) and equals(double,double) since their is
a signficant risk to use it with the wrong data type (char, byte, short, int,
long).
Added equalsIgnoreMetadata and equalsApproximatively convenience methods since
they will be often used.
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/math/Statistics.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Utilities.java
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/math/Statistics.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/math/Statistics.java?rev=1422211&r1=1422210&r2=1422211&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/math/Statistics.java
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/math/Statistics.java
Sat Dec 15 09:48:48 2012
@@ -17,7 +17,6 @@
package org.apache.sis.math;
import java.io.Serializable;
-import org.apache.sis.util.Utilities;
import org.apache.sis.util.ArgumentChecks;
import static java.lang.Math.*;
@@ -505,10 +504,10 @@ public class Statistics implements Clone
if (object != null && getClass() == object.getClass()) {
final Statistics cast = (Statistics) object;
return count == cast.count && countNaN == cast.countNaN
- && Utilities.equals(minimum, cast.minimum)
- && Utilities.equals(maximum, cast.maximum)
- && Utilities.equals(sum, cast.sum)
- && Utilities.equals(squareSum, cast.squareSum);
+ && doubleToLongBits(minimum) ==
doubleToLongBits(cast.minimum)
+ && doubleToLongBits(maximum) ==
doubleToLongBits(cast.maximum)
+ && doubleToLongBits(sum) ==
doubleToLongBits(cast.sum)
+ && doubleToLongBits(squareSum) ==
doubleToLongBits(cast.squareSum);
}
return false;
}
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Angle.java?rev=1422211&r1=1422210&r2=1422211&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
Sat Dec 15 09:48:48 2012
@@ -24,9 +24,10 @@ import java.text.Format;
import java.text.ParseException;
import java.io.Serializable;
import net.jcip.annotations.Immutable;
-import org.apache.sis.util.Utilities;
import org.apache.sis.math.MathFunctions;
+import static java.lang.Double.doubleToLongBits;
+
/**
* An angle in decimal degrees. An angle is the amount of rotation needed to
bring one line or
@@ -156,7 +157,7 @@ public class Angle implements Comparable
return true;
}
if (object != null && getClass() == object.getClass()) {
- return Utilities.equals(θ, ((Angle) object).θ);
+ return doubleToLongBits(θ) == doubleToLongBits(((Angle)
object).θ);
}
return false;
}
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Utilities.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Utilities.java?rev=1422211&r1=1422210&r2=1422211&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Utilities.java
(original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Utilities.java
Sat Dec 15 09:48:48 2012
@@ -43,33 +43,74 @@ public final class Utilities extends Sta
}
/**
- * Returns {@code true} if the given floats are equals. Positive and
negative zero are
- * considered different, while a {@link Float#NaN NaN} value is considered
equal to all
- * other NaN values.
- *
- * @param o1 The first value to compare.
- * @param o2 The second value to compare.
- * @return {@code true} if both values are equal.
+ * Compares the specified objects for equality, ignoring metadata.
+ * If this method returns {@code true}, then:
*
- * @see Float#equals(Object)
+ * <ul>
+ * <li>If the two given objects are
+ * {@linkplain
org.apache.sis.referencing.operation.transform.AbstractMathTransform math
transforms},
+ * then transforming a set of coordinate values using one transform
will produce the same
+ * results than transforming the same coordinates with the other
transform.</li>
+ *
+ * <li>If the two given objects are
+ * {@linkplain org.apache.sis.referencing.crs.AbstractCRS Coordinate
Reference Systems} (CRS), then a call to
+ * <code>{@linkplain
org.apache.sis.referencing.CRS#findMathTransform findMathTransform}(crs1,
crs2)</code>
+ * will return an identity transform.</li>
+ * </ul>
+ *
+ * If a more lenient comparison allowing slight differences in numerical
values is wanted,
+ * then {@link #equalsApproximatively(Object, Object)} can be used instead.
+ *
+ * {@section Implementation note}
+ * This is a convenience method for the following method call:
+ *
+ * {@preformat java
+ * return deepEquals(object1, object2, ComparisonMode.IGNORE_METADATA);
+ * }
+ *
+ * @param object1 The first object to compare (may be null).
+ * @param object2 The second object to compare (may be null).
+ * @return {@code true} if both objects are equal, ignoring metadata.
+ *
+ * @see #deepEquals(Object, Object, ComparisonMode)
+ * @see ComparisonMode#IGNORE_METADATA
*/
- public static boolean equals(final float o1, final float o2) {
- return Float.floatToIntBits(o1) == Float.floatToIntBits(o2);
+ public static boolean equalsIgnoreMetadata(final Object object1, final
Object object2) {
+ return deepEquals(object1, object2, ComparisonMode.IGNORE_METADATA);
}
/**
- * Returns {@code true} if the given doubles are equals. Positive and
negative zero are
- * considered different, while a {@link Double#NaN NaN} value is
considered equal to all
- * other NaN values.
- *
- * @param o1 The first value to compare.
- * @param o2 The second value to compare.
- * @return {@code true} if both values are equal.
+ * Compares the specified objects for equality, ignoring metadata and
slight differences
+ * in numerical values. If this method returns {@code true}, then:
+ *
+ * <ul>
+ * <li>If the two given objects are
+ * {@linkplain
org.apache.sis.referencing.operation.transform.AbstractMathTransform math
transforms},
+ * then transforming a set of coordinate values using one transform
will produce <em>approximatively</em>
+ * the same results than transforming the same coordinates with the
other transform.</li>
+ *
+ * <li>If the two given objects are
+ * {@linkplain org.apache.sis.referencing.crs.AbstractCRS Coordinate
Reference Systems} (CRS), then a call to
+ * <code>{@linkplain
org.apache.sis.referencing.CRS#findMathTransform findMathTransform}(crs1,
crs2)</code>
+ * will return a transform close to the identity transform.</li>
+ * </ul>
+ *
+ * {@section Implementation note}
+ * This is a convenience method for the following method call:
+ *
+ * {@preformat java
+ * return deepEquals(object1, object2, ComparisonMode.APPROXIMATIVE);
+ * }
+ *
+ * @param object1 The first object to compare (may be null).
+ * @param object2 The second object to compare (may be null).
+ * @return {@code true} if both objects are approximatively equal.
*
- * @see Double#equals(Object)
+ * @see #deepEquals(Object, Object, ComparisonMode)
+ * @see ComparisonMode#APPROXIMATIVE
*/
- public static boolean equals(final double o1, final double o2) {
- return Double.doubleToLongBits(o1) == Double.doubleToLongBits(o2);
+ public static boolean equalsApproximatively(final Object object1, final
Object object2) {
+ return deepEquals(object1, object2, ComparisonMode.APPROXIMATIVE);
}
/**
@@ -86,7 +127,8 @@ public final class Utilities extends Sta
* @param mode The strictness level of the comparison.
* @return {@code true} if both objects are equal for the given level of
strictness.
*
- * @see org.apache.sis.referencing.CRS#equalsIgnoreMetadata(Object, Object)
+ * @see #equalsIgnoreMetadata(Object, Object)
+ * @see #equalsApproximatively(Object, Object)
*/
public static boolean deepEquals(final Object object1, final Object
object2, final ComparisonMode mode) {
if (object1 == object2) {