sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1554322 - /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
Date Mon, 30 Dec 2013 21:39:27 GMT
Author: desruisseaux
Date: Mon Dec 30 21:39:27 2013
New Revision: 1554322

URL: http://svn.apache.org/r1554322
Log:
Bug fix: equals(Object) shall not use the "cached hash code check" optimization for any comparison
mode other than strict.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java

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=1554322&r1=1554321&r2=1554322&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] Mon Dec 30 21:39:27 2013
@@ -651,40 +651,35 @@ public class AbstractIdentifiedObject ex
         if (object == null) {
             return false;
         }
-        if (getClass() == object.getClass()) {
-            /*
-             * If the classes are the same, then the hash codes should be computed in the
same
-             * way. Since those codes are cached, this is an efficient way to quickly check
if
-             * the two objects are different. Note that using the hash codes for comparisons
-             * that ignore metadata is okay only if the implementation note described in
the
-             * 'computeHashCode()' javadoc hold (metadata not used in hash code computation).
-             */
-            if (mode.ordinal() < ComparisonMode.APPROXIMATIVE.ordinal()) {
-                final int tc = hashCode;
-                if (tc != 0) {
-                    final int oc = ((AbstractIdentifiedObject) object).hashCode;
-                    if (oc != 0 && tc != oc) {
-                        return false;
-                    }
-                }
-            }
-        } else {
-            if (mode == ComparisonMode.STRICT) { // Same class was required for this mode.
-                return false;
-            }
-            if (!(object instanceof IdentifiedObject)) {
-                return false;
-            }
-        }
         switch (mode) {
             case STRICT: {
+                if (getClass() != object.getClass()) {
+                    return false;
+                }
                 final AbstractIdentifiedObject that = (AbstractIdentifiedObject) object;
+                /*
+                 * If the hash codes were cached for both objects, opportunistically compare
them.
+                 * This is an efficient way to quickly check if the two objects are different
+                 * before the more extensive check below.
+                 */
+                if (mode == ComparisonMode.STRICT) {
+                    final int tc = hashCode;
+                    if (tc != 0) {
+                        final int oc = that.hashCode;
+                        if (oc != 0 && tc != oc) {
+                            return false;
+                        }
+                    }
+                }
                 return Objects.equals(name, that.name) &&
                        nonNull(alias).equals(nonNull(that.alias)) &&
                        nonNull(identifiers).equals(nonNull(that.identifiers)) &&
                        Objects.equals(remarks, that.remarks);
             }
             case BY_CONTRACT: {
+                if (!(object instanceof IdentifiedObject)) {
+                    return false;
+                }
                 final IdentifiedObject that = (IdentifiedObject) object;
                 return deepEquals(getName(),        that.getName(),        mode) &&
                        deepEquals(getAlias(),       that.getAlias(),       mode) &&
@@ -694,7 +689,7 @@ public class AbstractIdentifiedObject ex
             case IGNORE_METADATA:
             case APPROXIMATIVE:
             case DEBUG: {
-                return true;
+                return (object instanceof IdentifiedObject);
             }
             default: {
                 throw new IllegalArgumentException(Errors.format(Errors.Keys.UnknownEnumValue_1,
mode));



Mime
View raw message