directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r597946 - /directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
Date Sun, 25 Nov 2007 02:53:57 GMT
Author: elecharny
Date: Sat Nov 24 18:53:56 2007
New Revision: 597946

URL: http://svn.apache.org/viewvc?rev=597946&view=rev
Log:
Added a hashCode() method
Fixed some javadoc
Fixed the equals method to allow case insensitive comparison on IDs

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java?rev=597946&r1=597945&r2=597946&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
Sat Nov 24 18:53:56 2007
@@ -686,19 +686,46 @@
                 return oldValue;
         }
     }
+    
+    
+    /**
+     * Compute the hashcode for this attribute. It's a combinaison
+     * of the ID and all the values' hashcodes.
+     * 
+     * @see Object#hashCode()
+     */
+    public int hashCode()
+    {
+        int hash = 17;
+        
+        hash += hash*37 + StringTools.toLowerCase( getID() ).hashCode();
+        
+        if ( ( list != null ) && ( list.size() != 0 ) )
+        {
+            for ( Object value:list )
+            {
+                if ( value instanceof byte[] )
+                {
+                    hash += hash*37 + Arrays.hashCode( (byte[])value );
+                }
+                else 
+                {
+                    hash += hash*37 + value.hashCode();
+                }
+            }
+        }
+        
+        return hash;
+    }
 
 
     /**
-     * Checks for equality between this Attribute instance and another. The
-     * lockable properties are not factored into the equality semantics and
-     * neither is the Attribute implementation. The Attribute ID's are compared
-     * with regard to case and value order is only considered if the Attribute
-     * arguement is ordered itself.
+     * Checks for equality between this Attribute instance and another. The 
+     * Attribute ID's aren't compared with regard to case.
      * 
      * TODO start looking at comparing syntaxes to determine if attributes are
      *       really equal
-     * @param obj
-     *            the Attribute to test for equality
+     * @param obj the Attribute to test for equality
      * @return true if the obj is an Attribute and equals this Attribute false
      *         otherwise
      */
@@ -716,7 +743,7 @@
 
         Attribute attr = ( Attribute ) obj;
 
-        if ( !upId.equals( attr.getID() ) )
+        if ( !StringTools.toLowerCase( upId ).equals( StringTools.toLowerCase( attr.getID()
) ) )
         {
             return false;
         }



Mime
View raw message