You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/12/31 01:33:19 UTC
svn commit: r1554339 - in /sis/branches/JDK7/core:
sis-referencing/src/main/java/org/apache/sis/geometry/
sis-referencing/src/main/java/org/apache/sis/referencing/
sis-referencing/src/main/java/org/apache/sis/referencing/cs/
sis-referencing/src/main/ja...
Author: desruisseaux
Date: Tue Dec 31 00:33:18 2013
New Revision: 1554339
URL: http://svn.apache.org/r1554339
Log:
Replaced AbstractIdentifiedObject.hashCode(...) by a simpler computeHashCode(),
because the previous approach did not worked well for caching hash code values.
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DirectionAlongMeridian.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java [UTF-8] Tue Dec 31 00:33:18 2013
@@ -33,6 +33,7 @@ import org.apache.sis.util.ArraysExt;
import org.apache.sis.util.Utilities;
import org.apache.sis.util.CharSequences;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.internal.util.Numerics;
import static java.lang.Double.doubleToLongBits;
import static org.apache.sis.util.StringBuilders.trimFractionalPart;
@@ -362,8 +363,7 @@ parse: while (i < length) {
final int dimension = getDimension();
int code = 1;
for (int i=0; i<dimension; i++) {
- final long bits = doubleToLongBits(getOrdinate(i));
- code = 31 * code + (((int) bits) ^ (int) (bits >>> 32));
+ code = code*31 + Numerics.hashCode(doubleToLongBits(getOrdinate(i)));
}
return code + Objects.hashCode(getCoordinateReferenceSystem());
}
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java [UTF-8] Tue Dec 31 00:33:18 2013
@@ -33,6 +33,7 @@ import org.opengis.referencing.crs.Coord
import org.opengis.referencing.cs.CoordinateSystemAxis;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.RangeMeaning;
+import org.apache.sis.internal.util.Numerics;
import org.apache.sis.util.Emptiable;
import org.apache.sis.util.Utilities;
import org.apache.sis.util.ComparisonMode;
@@ -1019,19 +1020,14 @@ public abstract class AbstractEnvelope i
@Override
public int hashCode() {
final int dimension = getDimension();
- int code = 1;
+ long code = 1;
boolean p = true;
do {
for (int i=0; i<dimension; i++) {
- final long bits = doubleToLongBits(p ? getLower(i) : getUpper(i));
- code = 31 * code + (((int) bits) ^ (int) (bits >>> 32));
+ code = code*31 + doubleToLongBits(p ? getLower(i) : getUpper(i));
}
} while ((p = !p) == false);
- final CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
- if (crs != null) {
- code += crs.hashCode();
- }
- return code;
+ return Numerics.hashCode(code) + Objects.hashCode(getCoordinateReferenceSystem());
}
/**
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java [UTF-8] Tue Dec 31 00:33:18 2013
@@ -25,10 +25,14 @@ import java.io.Serializable;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.geometry.DirectPosition;
import org.opengis.geometry.MismatchedDimensionException;
+import org.apache.sis.internal.util.Numerics;
import org.apache.sis.util.resources.Errors;
import static org.apache.sis.util.ArgumentChecks.ensureDimensionMatches;
+// Related to JDK7
+import java.util.Objects;
+
/**
* Holds the coordinates for a one-dimensional position within some coordinate reference system.
@@ -224,6 +228,8 @@ public class DirectPosition1D extends Ab
/**
* Returns a copy of this position.
+ *
+ * @return A copy of this position.
*/
@Override
public DirectPosition1D clone() {
@@ -240,11 +246,7 @@ public class DirectPosition1D extends Ab
*/
@Override
public int hashCode() {
- final long value = Double.doubleToLongBits(ordinate);
- int code = 31 + (((int) value) ^ (int) (value >>> 32));
- if (crs != null) {
- code += crs.hashCode();
- }
+ final int code = 31 + Numerics.hashCode(Double.doubleToLongBits(ordinate)) + Objects.hashCode(crs);
assert code == super.hashCode();
return code;
}
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java [UTF-8] Tue Dec 31 00:33:18 2013
@@ -21,6 +21,7 @@ import org.opengis.geometry.DirectPositi
import org.opengis.geometry.MismatchedDimensionException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.AxisDirection;
+import org.apache.sis.internal.util.Numerics;
import org.apache.sis.util.resources.Errors;
import static java.lang.Double.doubleToLongBits;
@@ -302,14 +303,9 @@ public class DirectPosition2D extends Po
*/
@Override
public int hashCode() {
- int code;
- long bits;
- bits = doubleToLongBits(x); code = 31 + (((int) bits) ^ (int) (bits >>> 32));
- bits = doubleToLongBits(y); code = 31*code + (((int) bits) ^ (int) (bits >>> 32));
- if (crs != null) {
- code += crs.hashCode();
- }
- return code;
+ int code = 31 + Numerics.hashCode(doubleToLongBits(x));
+ code = code*31 + Numerics.hashCode(doubleToLongBits(y));
+ return code + Objects.hashCode(crs);
}
/**
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] Tue Dec 31 00:33:18 2013
@@ -40,6 +40,7 @@ import org.opengis.referencing.Identifie
import org.opengis.referencing.ReferenceIdentifier;
import org.apache.sis.internal.referencing.ReferencingUtilities;
import org.apache.sis.internal.jaxb.referencing.Code;
+import org.apache.sis.internal.util.Numerics;
import org.apache.sis.io.wkt.FormattableObject;
import org.apache.sis.xml.Namespaces;
import org.apache.sis.util.Deprecable;
@@ -643,7 +644,7 @@ public class AbstractIdentifiedObject ex
* relevant to coordinate transformations.
* @return {@code true} if both objects are equal.
*
- * @see #hashCode(ComparisonMode)
+ * @see #computeHashCode()
* @see org.apache.sis.util.Utilities#deepEquals(Object, Object, ComparisonMode)
*/
@Override
@@ -698,51 +699,6 @@ public class AbstractIdentifiedObject ex
}
/**
- * Computes a hash value consistent with the given comparison mode.
- * This method accepts only the following enumeration values:
- *
- * <ul>
- * <li>{@link ComparisonMode#STRICT STRICT}: this method may use any property,
- * including implementation-specific ones if any, at implementation choice.</li>
- * <li>{@link ComparisonMode#BY_CONTRACT BY_CONTRACT}: this method can use any property defined
- * in the implemented interface (typically a GeoAPI interface).</li>
- * <li>{@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA}: this method ignores the metadata that do not
- * affect coordinate operations. By default, the ignored properties are the {@linkplain #getName() name},
- * {@linkplain #getIdentifiers() identifiers} and {@linkplain #getRemarks() remarks}.
- * However subclasses may ignore a different list of properties.</li>
- * </ul>
- *
- * In the later case, two identified objects will return the same hash value if they are equal in the sense of
- * <code>{@linkplain #equals(Object, ComparisonMode) equals}(object, IGNORE_METADATA)</code>.
- * This feature allows users to implement metadata-insensitive {@link java.util.HashMap}.
- *
- * @param mode Specifies the properties that can be used for hash code computation.
- * @return The hash code value. This value may change between different execution of the Apache SIS library.
- * @throws IllegalArgumentException If the given {@code mode} is not one of {@code STRICT}, {@code BY_CONTRACT}
- * or {@code IGNORE_METADATA} enumeration values.
- */
- public int hashCode(final ComparisonMode mode) throws IllegalArgumentException {
- int code = (int) serialVersionUID;
- switch (mode) {
- case STRICT: {
- code ^= Objects.hash(name, nonNull(alias), nonNull(identifiers), remarks);
- break;
- }
- case BY_CONTRACT: {
- code ^= Objects.hash(getName(), getAlias(), getIdentifiers(), getRemarks());
- break;
- }
- case IGNORE_METADATA: {
- break;
- }
- default: {
- throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2, "mode", mode));
- }
- }
- return code;
- }
-
- /**
* Compares the specified object with this object for equality.
* This method is implemented as below (omitting assertions):
*
@@ -764,30 +720,53 @@ public class AbstractIdentifiedObject ex
}
/**
- * Returns a hash value for this identified object.
- * This method derives a value from <code>{@linkplain #hashCode(ComparisonMode) hashCode}(STRICT)</code>.
- * Notes:
+ * Returns a hash value for this identified object. Two {@code AbstractIdentifiedObject} instances
+ * for which {@link #equals(Object)} returns {@code true} shall have the same hash code value, if
+ * the hash codes are computed on the same JVM instance for both objects. The hash code value is
+ * <em>not</em> guaranteed to be stable between different versions of the Apache SIS library, or
+ * between libraries running on different JVM.
+ *
+ * {@section Implementation note}
+ * This method invokes {@link #computeHashCode()} when first needed, then caches the result.
+ * Subclasses shall override {@link #computeHashCode()} instead than this method.
*
- * <ul>
- * <li>The derived value may be different than {@code hashCode(STRICT)}.</li>
- * <li>This method may cache the hash code value.</li>
- * </ul>
- *
- * Subclasses shall override {@link #hashCode(ComparisonMode)} instead than this method.
- *
- * @return The hash code value. This value may change between different execution of the Apache SIS library.
+ * @return The hash code value. This value may change in any future Apache SIS version.
*/
@Override
public final int hashCode() { // No need to synchronize; ok if invoked twice.
int hash = hashCode;
if (hash == 0) {
- hash = hashCode(ComparisonMode.STRICT);
+ hash = Numerics.hashCode(computeHashCode());
if (hash == 0) {
hash = -1;
}
hashCode = hash;
}
- assert hash == -1 || hash == hashCode(ComparisonMode.STRICT) : this;
+ assert hash == -1 || hash == Numerics.hashCode(computeHashCode()) : hash;
return hash;
}
+
+ /**
+ * Invoked by {@link #hashCode()} for computing the hash code when first needed.
+ * This method is invoked at most once in normal execution, or an arbitrary amount of times if Java
+ * assertions are enabled. The hash code value shall never change during the whole lifetime of this
+ * object.
+ *
+ * {@section Overriding}
+ * Subclasses can override this method for using more properties in hash code calculation.
+ * All {@code computeHashCode()} methods shall invoke {@code super.computeHashCode()},
+ * <strong>not</strong> {@code hashCode()}. Example:
+ *
+ * {@preformat java
+ * @Override
+ * protected long computeHashCode() {
+ * return super.computeHashCode() + 31 * Objects.hash(myProperties);
+ * }
+ * }
+ *
+ * @return The hash code value. This value may change in any future Apache SIS version.
+ */
+ protected long computeHashCode() {
+ return Objects.hash(name, nonNull(alias), nonNull(identifiers), remarks) ^ serialVersionUID;
+ }
}
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java [UTF-8] Tue Dec 31 00:33:18 2013
@@ -223,31 +223,18 @@ public class AbstractReferenceSystem ext
}
/**
- * Computes a hash value consistent with the given comparison mode.
- * If the given argument is {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA}, then the
- * {@linkplain #getDomainOfValidity() domain of validity} and the {@linkplain #getScope() scope}
- * properties are ignored, in addition to other ignored properties documented in the
- * {@linkplain AbstractIdentifiedObject#hashCode(ComparisonMode) super-class}.
+ * 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 ReferenceSystem implementation from implementations of other GeoAPI interfaces.
*/
- int code = super.hashCode(mode) ^ (int) serialVersionUID;
- switch (mode) {
- case STRICT: {
- code ^= Objects.hash(domainOfValidity, scope);
- break;
- }
- case BY_CONTRACT: {
- code ^= Objects.hash(getDomainOfValidity(), getScope());
- break;
- }
- }
- return code;
+ return serialVersionUID ^ (super.computeHashCode() + Objects.hash(domainOfValidity, scope));
}
}
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java [UTF-8] Tue Dec 31 00:33:18 2013
@@ -283,13 +283,19 @@ public class AbstractCS extends Abstract
}
/**
- * 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 Arrays.hashCode(axes) + 31*super.hashCode(mode);
+ protected long computeHashCode() {
+ /*
+ * The "serialVersionUID ^ …" is an arbitrary change applied to the hash code value in order to
+ * differentiate this CoordinateSystem implementation from implementations of other GeoAPI interfaces.
+ */
+ return serialVersionUID ^ (super.computeHashCode() + Arrays.hashCode(axes));
}
/**
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java [UTF-8] Tue Dec 31 00:33:18 2013
@@ -39,7 +39,6 @@ import org.apache.sis.measure.Latitude;
import org.apache.sis.measure.Units;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.resources.Errors;
-import org.apache.sis.internal.util.Numerics;
import org.apache.sis.io.wkt.Formatter;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -553,20 +552,20 @@ public class DefaultCoordinateSystemAxis
}
/**
- * 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 {
- int code = super.hashCode(mode);
- if (unit != null) code = 31*code + unit .hashCode();
- if (direction != null) code = 31*code + direction.hashCode();
- if (mode == ComparisonMode.STRICT) {
- code = Numerics.hash(minimum, code);
- code = Numerics.hash(maximum, code);
- }
- return code;
+ protected long computeHashCode() {
+ /*
+ * The "serialVersionUID ^ …" is an arbitrary change applied to the hash code value in order to
+ * differentiate this CoordinateSystemAxis implementation from implementations of other GeoAPI interfaces.
+ */
+ return serialVersionUID ^ (super.computeHashCode() + Objects.hashCode(unit) + Objects.hashCode(direction)
+ + Double.doubleToLongBits(minimum) + 31*Double.doubleToLongBits(maximum));
}
/**
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DirectionAlongMeridian.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DirectionAlongMeridian.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DirectionAlongMeridian.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DirectionAlongMeridian.java [UTF-8] Tue Dec 31 00:33:18 2013
@@ -235,7 +235,7 @@ final class DirectionAlongMeridian imple
if (object instanceof DirectionAlongMeridian) {
final DirectionAlongMeridian that = (DirectionAlongMeridian) object;
return baseDirection.equals(that.baseDirection) &&
- Double.doubleToLongBits(meridian) == Double.doubleToLongBits(that.meridian);
+ Numerics.equals(meridian, that.meridian);
}
return false;
}
@@ -245,7 +245,7 @@ final class DirectionAlongMeridian imple
*/
@Override
public int hashCode() {
- return Numerics.hash(meridian, baseDirection.hashCode()) ^ (int) serialVersionUID;
+ return Numerics.hashCode(serialVersionUID ^ (Double.doubleToLongBits(meridian) + baseDirection.hashCode()));
}
/**
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/AbstractDatum.java [UTF-8] Tue Dec 31 00:33:18 2013
@@ -401,37 +401,20 @@ public class AbstractDatum extends Abstr
}
/**
- * Computes a hash value consistent with the given comparison mode.
- * If the given argument is {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA}, then the
- * {@linkplain #getAnchorPoint() anchor point}, {@linkplain #getRealizationEpoch() realization epoch},
- * {@linkplain #getDomainOfValidity() domain of validity} and the {@linkplain #getScope() scope}
- * properties are ignored.
+ * 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 Datum implementation from implementations of other GeoAPI interfaces.
*/
- int code = super.hashCode(mode) ^ (int) serialVersionUID;
- switch (mode) {
- case STRICT: {
- code += Objects.hash(anchorPoint, realizationEpoch, domainOfValidity, scope);
- break;
- }
- case BY_CONTRACT: {
- code += Objects.hash(getAnchorPoint(), getRealizationEpoch(), getDomainOfValidity(), getScope());
- break;
- }
- /*
- * The name is significant for all modes, but we nevertheless ignore it because
- * of the way the name is compared in the equals(Object, ComparisonMode) method
- * which make hash code computation impractical in the IGNORE_METADATA case.
- */
- }
- return code;
+ return serialVersionUID ^ (super.computeHashCode() +
+ Objects.hash(anchorPoint, realizationEpoch, domainOfValidity, scope));
}
/**
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java [UTF-8] Tue Dec 31 00:33:18 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/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEngineeringDatum.java [UTF-8] Tue Dec 31 00:33:18 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/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java [UTF-8] Tue Dec 31 00:33:18 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/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultImageDatum.java [UTF-8] Tue Dec 31 00:33:18 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));
}
/**
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultPrimeMeridian.java [UTF-8] Tue Dec 31 00:33:18 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/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultTemporalDatum.java Tue Dec 31 00:33:18 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/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java [UTF-8] Tue Dec 31 00:33:18 2013
@@ -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() + Objects.hashCode(type()));
}
/**
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java [UTF-8] Tue Dec 31 00:33:18 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/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java [UTF-8] Tue Dec 31 00:33:18 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/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Numerics.java [UTF-8] Tue Dec 31 00:33:18 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/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java?rev=1554339&r1=1554338&r2=1554339&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java [UTF-8] Tue Dec 31 00:33:18 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