jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r378546 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: ItemId.java NodeId.java PropertyId.java
Date Fri, 17 Feb 2006 15:36:55 GMT
Author: tripod
Date: Fri Feb 17 07:36:53 2006
New Revision: 378546

URL: http://svn.apache.org/viewcvs?rev=378546&view=rev
Log:
- clean up of some hashCode stuff

Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemId.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeId.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyId.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemId.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemId.java?rev=378546&r1=378545&r2=378546&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemId.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/ItemId.java
Fri Feb 17 07:36:53 2006
@@ -28,16 +28,6 @@
     /** Serialization UID of this class. */
     static final long serialVersionUID = -9147603369595196078L;
 
-    /** Memorized hash code. */
-    protected int hash;
-
-    /**
-     * Creates an empty item ID instance.
-     */
-    protected ItemId() {
-        hash = 0;
-    }
-
     /**
      * Returns <code>true</code> if this id denotes a <code>Node</code>.
      *

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeId.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeId.java?rev=378546&r1=378545&r2=378546&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeId.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeId.java
Fri Feb 17 07:36:53 2006
@@ -30,6 +30,9 @@
     /** UUID of the identified node */
     private final UUID uuid;
 
+    /** the precalculated hashcode */
+    private final int hashCode;
+
     /**
      * Creates a node identifier instance for the identified node.
      *
@@ -40,6 +43,7 @@
             throw new IllegalArgumentException("uuid can not be null");
         }
         this.uuid = uuid;
+        this.hashCode = uuid.hashCode();
     }
 
     /**
@@ -81,16 +85,10 @@
         return new NodeId(new UUID(s));
     }
 
-    //-------------------------------------------< java.lang.Object overrides >
+    //-----------------------------------------< java.lang.Object overrides >---
 
     /**
-     * Compares node identifiers for equality.
-     *
-     * @param obj other object
-     * @return <code>true</code> if the given object is a node identifier
-     *         instance that identifies the same node as this identifier,
-     *         <code>false</code> otherwise
-     * @see Object#equals(Object)
+     * {@inheritDoc}
      */
     public boolean equals(Object obj) {
         if (this == obj) {
@@ -103,27 +101,20 @@
     }
 
     /**
-     * Returns the node UUID.
+     * {@inheritDoc}
      *
-     * @return node UUID
-     * @see Object#toString()
+     * Returns the same as <code>this.getUUID().toString()</code>
      */
     public String toString() {
         return uuid.toString();
     }
 
     /**
-     * Returns the hash code of the node UUID. The computed hash code
-     * is memorized for better performance.
+     * {@inheritDoc}
      *
-     * @return hash code
-     * @see Object#hashCode()
+     * Returns the same as <code>this.getUUID().hashCode()</code>
      */
     public int hashCode() {
-        // NodeId is immutable, we can store the computed hash code value
-        if (hash == 0) {
-            hash = uuid.hashCode();
-        }
-        return hash;
+        return hashCode;
     }
 }

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyId.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyId.java?rev=378546&r1=378545&r2=378546&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyId.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyId.java
Fri Feb 17 07:36:53 2006
@@ -34,6 +34,9 @@
     /** Qualified name of the property. */
     private final QName propName;
 
+    /** the precalculated hash code */
+    private final int hashCode;
+
     /**
      * Creates a property identifier instance for the identified property.
      *
@@ -49,6 +52,11 @@
         }
         this.parentId = parentId;
         this.propName = propName;
+
+        int h= 17;
+        h = 37 * h + parentId.hashCode();
+        h = 37 * h + propName.hashCode();
+        this.hashCode = h;
     }
 
     /**
@@ -106,16 +114,10 @@
         return new PropertyId(NodeId.valueOf(uuid), name);
     }
 
-    //-------------------------------------------< java.lang.Object overrides >
+    //-----------------------------------------< java.lang.Object overrides >---
 
     /**
-     * Compares property identifiers for equality.
-     *
-     * @param obj other object
-     * @return <code>true</code> if the given object is a property identifier
-     *         instance that identifies the same property as this identifier,
-     *         <code>false</code> otherwise
-     * @see Object#equals(Object)
+     * {@inheritDoc}
      */
     public boolean equals(Object obj) {
         if (this == obj) {
@@ -130,32 +132,21 @@
     }
 
     /**
-     * Returns a string representation of this property identifier.
+     * {@inheritDoc}
      *
-     * @return property identifier string
-     * @see Object#toString()
+     * Returns the same as <code>this.getParentId() + "/" + this.getName()</code>
      */
     public String toString() {
         return parentId + "/" + propName;
     }
 
     /**
-     * Returns the hash code of this property identifier. The hash code
-     * is computed from the parent node UUID and the property name. The
-     * hash code is memorized for performance.
+     * {@inheritDoc}
      *
-     * @return hash code
-     * @see Object#hashCode()
+     * Returns the hash code of this property identifier. The hash code
+     * is computed from the parent node id and the property name.
      */
     public int hashCode() {
-        // PropertyId is immutable, we can store the computed hash code value
-        int h = hash;
-        if (h == 0) {
-            h = 17;
-            h = 37 * h + parentId.hashCode();
-            h = 37 * h + propName.hashCode();
-            hash = h;
-        }
-        return h;
+        return hashCode;
     }
 }



Mime
View raw message