jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r529332 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/Path.java
Date Mon, 16 Apr 2007 17:19:50 GMT
Author: reschke
Date: Mon Apr 16 10:19:49 2007
New Revision: 529332

URL: http://svn.apache.org/viewvc?view=rev&rev=529332
Log:
JCR-789: treat index 0 and 1 as equal in equals() and hashCode()

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/Path.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/Path.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/Path.java?view=diff&rev=529332&r1=529331&r2=529332
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/Path.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/name/Path.java
Mon Apr 16 10:19:49 2007
@@ -1194,9 +1194,8 @@
          * @return hash code
          */
         public int hashCode() {
-            // @todo treat index==0 as index==1?
             int h = 17;
-            h = 37 * h + index;
+            h = 37 * h + normalizeIndex(index);
             h = 37 * h + name.hashCode();
             return h;
         }
@@ -1216,12 +1215,22 @@
             if (obj instanceof PathElement) {
                 PathElement other = (PathElement) obj;
                 return name.equals(other.name)
-                        // @todo treat index==0 as index==1?
-                        && index == other.index;
+                        && normalizeIndex(index) == normalizeIndex(other.index);
             }
             return false;
         }
 
+        /**
+         * Normalizes index value {@link Path#INDEX_UNDEFINED} to
+         * {@link Path#INDEX_DEFAULT} for {@link #equals(Object)} and
+         * {@link #hashCode()}.
+         * @param index
+         * @return normalized index
+         */
+        private int normalizeIndex(int index) {
+            return index == Path.INDEX_UNDEFINED ? Path.INDEX_DEFAULT : index;
+        }
+      
         /**
          * Returns <code>true</code> if this element denotes the <i>root</i>
element,
          * otherwise returns <code>false</code>.



Mime
View raw message