directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r491848 - /directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/
Date Tue, 02 Jan 2007 16:51:59 GMT
Author: elecharny
Date: Tue Jan  2 08:51:57 2007
New Revision: 491848

URL: http://svn.apache.org/viewvc?view=rev&rev=491848
Log:
Implemented missing hashCode() methods

Modified:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbandonRequestImpl.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractRequest.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AddRequestImpl.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindRequestImpl.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindResponseImpl.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedRequestImpl.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedResponseImpl.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/LockableAttributesImpl.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/Message.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchRequestImpl.java

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbandonRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbandonRequestImpl.java?view=diff&rev=491848&r1=491847&r2=491848
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbandonRequestImpl.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbandonRequestImpl.java
Tue Jan  2 08:51:57 2007
@@ -85,12 +85,18 @@
             return true;
         }
 
+        if ( ( obj == null ) || !( obj instanceof AbandonRequest ) )
+        {
+            return false;
+        }
+        
         if ( !super.equals( obj ) )
         {
             return false;
         }
 
         AbandonRequest req = ( AbandonRequest ) obj;
+        
         if ( req.getAbandoned() != abandonId )
         {
             return false;
@@ -99,6 +105,17 @@
         return true;
     }
 
+    /**
+     * @see Object#hashCode()
+     */
+    public int hashCode()
+    {
+        int hash = 7;
+        hash = hash*31 + abandonId;
+        hash = hash*31 + super.hashCode();
+        
+        return hash;
+    }
 
     /**
      * RFC 2251 [Section 4.11]: Abandon, Bind, Unbind, and StartTLS operations

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java?view=diff&rev=491848&r1=491847&r2=491848
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractMessage.java
Tue Jan  2 08:51:57 2007
@@ -34,7 +34,7 @@
     static final long serialVersionUID = 7601738291101182094L;
 
     /** Map of message controls using OID Strings for keys and Control values */
-    private final Map controls;
+    private final Map<String, Control> controls;
 
     /** The session unique message sequence identifier */
     private final int id;
@@ -43,7 +43,7 @@
     private final MessageTypeEnum type;
 
     /** Transient Message Parameter Hash */
-    private final Map parameters;
+    private final Map<Object, Object> parameters;
 
 
     /**
@@ -58,8 +58,8 @@
     {
         this.id = id;
         this.type = type;
-        controls = new HashMap();
-        parameters = new HashMap();
+        controls = new HashMap<String, Control>();
+        parameters = new HashMap<Object, Object>();
     }
 
 
@@ -83,7 +83,7 @@
      * @return Map of OID strings to Control object instances.
      * @see Control
      */
-    public Map getControls()
+    public Map<String, Control> getControls()
     {
         return Collections.unmodifiableMap( controls );
     }
@@ -185,7 +185,7 @@
             return true;
         }
 
-        if ( !( obj instanceof Message ) )
+        if ( ( obj == null ) || !( obj instanceof Message ) )
         {
             return false;
         }
@@ -219,4 +219,19 @@
 
         return true;
     }
+    
+    /**
+     * @see Object#hashCode()
+     */
+    public int hashCode()
+    {
+        int hash = 7;
+        hash = hash*31 + id;
+        hash = hash*31 + ( type == null ? 0 : type.hashCode() );
+        hash = hash*31 + ( parameters == null ? 0 : parameters.hashCode() );
+        hash = hash*31 + ( controls == null ? 0 : controls.hashCode() );
+        
+        return hash;
+    }
+
 }

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractRequest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractRequest.java?view=diff&rev=491848&r1=491847&r2=491848
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractRequest.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AbstractRequest.java
Tue Jan  2 08:51:57 2007
@@ -62,4 +62,16 @@
     {
         return hasResponse;
     }
+    
+    /**
+     * @see Object#hashCode()
+     */
+    public int hashCode()
+    {
+        int hash = 7;
+        hash = hash*31 + (hasResponse ? 0 : 1 );
+        hash = hash*31 + super.hashCode();
+        
+        return hash;
+    }
 }

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AddRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AddRequestImpl.java?view=diff&rev=491848&r1=491847&r2=491848
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AddRequestImpl.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AddRequestImpl.java
Tue Jan  2 08:51:57 2007
@@ -162,45 +162,52 @@
         {
             return true;
         }
-
-        if ( !super.equals( obj ) )
+        
+        if ( ( obj == null ) || !( obj instanceof AddRequest ) )
         {
             return false;
         }
 
-        AddRequest req = ( AddRequest ) obj;
-
-        if ( entry != null && req.getEntry() == null )
+        if ( !super.equals( obj ) )
         {
             return false;
         }
 
-        if ( entry == null && req.getEntry() != null )
-        {
-            return false;
-        }
+        AddRequest req = ( AddRequest ) obj;
 
-        if ( entry != null && req.getEntry() != null )
+        if ( entry == null )
         {
-            if ( !entry.equals( req.getEntry() ) )
+            if ( req.getEntry() != null )
             {
                 return false;
             }
         }
-
-        if ( attributes != null && req.getAttributes() == null )
+        else
         {
-            return false;
+            if ( req.getEntry() == null )
+            {
+                return false;
+            }
+            else if ( !entry.equals( req.getEntry() ) )
+            {
+                return false;
+            }
         }
-
-        if ( attributes == null && req.getAttributes() != null )
+        
+        if ( attributes == null )
         {
-            return false;
+            if ( req.getAttributes() != null )
+            {
+                return false;
+            }
         }
-
-        if ( attributes != null && req.getAttributes() != null )
+        else
         {
-            if ( !attributes.equals( req.getAttributes() ) )
+            if ( req.getAttributes() == null )
+            {
+                return false;
+            }
+            else if ( !attributes.equals( req.getAttributes() ) )
             {
                 return false;
             }
@@ -209,7 +216,23 @@
         return true;
     }
 
+    /**
+     * @see Object#hashCode()
+     */
+    public int hashCode()
+    {
+        int hash = 7;
+        hash = hash*31 + ( attributes == null ? 0 : attributes.hashCode() );
+        hash = hash*31 + ( entry == null ? 0 : entry.hashCode() );
+        hash = hash*31 + ( response == null ? 0 : response.hashCode() );
+        hash = hash*31 + super.hashCode();
+        
+        return hash;
+    }
 
+    /**
+     * @see Object#toString()
+     */
     public String toString()
     {
         StringBuffer sb = new StringBuffer();

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindRequestImpl.java?view=diff&rev=491848&r1=491847&r2=491848
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindRequestImpl.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindRequestImpl.java
Tue Jan  2 08:51:57 2007
@@ -20,8 +20,9 @@
 package org.apache.directory.shared.ldap.message;
 
 
+import java.util.Arrays;
+
 import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.util.ArrayUtils;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 
@@ -44,6 +45,9 @@
 
     /** The passwords, keys or tickets used to verify user identity */
     private byte[] credentials;
+    
+    /** A storage for credential hashCode */
+    private int hCredentials;
 
     /** The mechanism used to decode user identity */
     private String mechanism;
@@ -70,6 +74,7 @@
     public BindRequestImpl(final int id)
     {
         super( id, TYPE, true );
+        hCredentials = 0;
     }
 
 
@@ -136,6 +141,20 @@
     public void setCredentials( byte[] credentials )
     {
         this.credentials = credentials;
+        
+        if ( credentials != null )
+        {
+            hCredentials = 0;
+            
+            for ( byte b:credentials )
+            {
+                hCredentials = hCredentials*31 + b;
+            }
+        }
+        else
+        {
+            hCredentials = 0;
+        }
     }
 
 
@@ -278,7 +297,9 @@
         return response;
     }
 
-
+    /**
+     * @see Object#equals(Object)
+     */
     public boolean equals( Object obj )
     {
         if ( obj == this )
@@ -286,6 +307,11 @@
             return true;
         }
 
+        if ( ( obj == null ) || !( obj instanceof BindRequest ) )
+        {
+            return false;
+        }
+        
         if ( !super.equals( obj ) )
         {
             return false;
@@ -326,14 +352,30 @@
                 
         }
         
-        if ( !ArrayUtils.isEquals( req.getCredentials(), getCredentials() ) )
+        if ( !Arrays.equals( req.getCredentials(), getCredentials() ) )
         {
             return false;
         }
 
         return true;
     }
-
+    
+    /**
+     * @see Object#hashCode()
+     */
+    public int hashCode()
+    {
+        int hash = 7;
+        hash = hash*31 + ( credentials == null ? 0 : hCredentials );
+        hash = hash*31 + ( isSimple ? 0 : 1 );
+        hash = hash*31 + ( isVersion3 ? 0 : 1 );
+        hash = hash*31 + ( mechanism == null ? 0 : mechanism.hashCode() );
+        hash = hash*31 + ( name == null ? 0 : name.hashCode() );
+        hash = hash*31 + ( response == null ? 0 : response.hashCode() );
+        hash = hash*31 + super.hashCode();
+        
+        return hash;
+    }
 
     /**
      * Get a String representation of a BindRequest

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindResponseImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindResponseImpl.java?view=diff&rev=491848&r1=491847&r2=491848
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindResponseImpl.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindResponseImpl.java
Tue Jan  2 08:51:57 2007
@@ -20,6 +20,8 @@
 package org.apache.directory.shared.ldap.message;
 
 
+import java.util.Arrays;
+
 import org.apache.directory.shared.ldap.util.ArrayUtils;
 import org.apache.directory.shared.ldap.util.StringTools;
 
@@ -104,32 +106,32 @@
             return true;
         }
 
-        if ( !super.equals( obj ) )
-        {
-            return false;
-        }
-
-        BindResponse response = ( BindResponse ) obj;
-        byte[] creds = response.getServerSaslCreds();
-        if ( serverSaslCreds == null && creds != null )
+        if ( ( obj == null ) || !( obj instanceof BindResponse ) )
         {
             return false;
         }
 
-        if ( creds == null && serverSaslCreds != null )
+        if ( !super.equals( obj ) )
         {
             return false;
         }
 
-        if ( creds != null && serverSaslCreds != null )
+        BindResponse response = ( BindResponse ) obj;
+        byte[] creds = response.getServerSaslCreds();
+        
+        if ( serverSaslCreds == null )
         {
-            if ( !ArrayUtils.isEquals( serverSaslCreds, creds ) )
+            if ( creds != null )
             {
                 return false;
             }
         }
-
-        return true;
+        else if ( creds == null )
+        {
+            return false;
+        }
+        
+        return Arrays.equals( serverSaslCreds, creds );
     }
 
 

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedRequestImpl.java?view=diff&rev=491848&r1=491847&r2=491848
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedRequestImpl.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedRequestImpl.java
Tue Jan  2 08:51:57 2007
@@ -20,10 +20,11 @@
 package org.apache.directory.shared.ldap.message;
 
 
+import java.util.Arrays;
+
 import javax.naming.NamingException;
 import javax.naming.ldap.ExtendedResponse;
 
-import org.apache.directory.shared.ldap.util.ArrayUtils;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 
@@ -198,7 +199,7 @@
 
         if ( payload != null && req.getPayload() != null )
         {
-            if ( !ArrayUtils.isEquals( payload, req.getPayload() ) )
+            if ( !Arrays.equals( payload, req.getPayload() ) )
             {
                 return false;
             }

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedResponseImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedResponseImpl.java?view=diff&rev=491848&r1=491847&r2=491848
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedResponseImpl.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedResponseImpl.java
Tue Jan  2 08:51:57 2007
@@ -20,8 +20,7 @@
 package org.apache.directory.shared.ldap.message;
 
 
-import org.apache.directory.shared.ldap.util.ArrayUtils;
-
+import java.util.Arrays;
 
 /**
  * Lockable ExtendedResponse implementation
@@ -172,7 +171,7 @@
 
         if ( value != null && resp.getResponse() != null )
         {
-            if ( !ArrayUtils.isEquals( value, resp.getResponse() ) )
+            if ( !Arrays.equals( value, resp.getResponse() ) )
             {
                 return false;
             }

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/LockableAttributesImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/LockableAttributesImpl.java?view=diff&rev=491848&r1=491847&r2=491848
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/LockableAttributesImpl.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/LockableAttributesImpl.java
Tue Jan  2 08:51:57 2007
@@ -55,13 +55,13 @@
 		String upId;
 		Attribute attribute;
 		
-		Holder( String upId, Attribute attribute )
+		private Holder( String upId, Attribute attribute )
 		{
 			this.upId = upId;
 			this.attribute = attribute;
 		}
 		
-		public Object clone() throws CloneNotSupportedException
+        public Object clone() throws CloneNotSupportedException
 		{
 			Holder clone = (Holder)super.clone();
 			
@@ -81,6 +81,15 @@
 			
 			return sb.toString();
 		}
+        
+        public int hashCode()
+        {
+            int hash = 7;
+            hash = hash*31 + ( upId == null ? 0 : upId.hashCode() );
+            hash = hash*31 + (attribute == null ? 0 : attribute.hashCode() );
+            
+            return hash;
+        }
 	}
 	
     /**
@@ -512,7 +521,7 @@
             return true;
         }
 
-        if ( !( obj instanceof Attributes ) )
+        if ( ( obj == null ) || !( obj instanceof Attributes ) )
         {
             return false;
         }
@@ -548,5 +557,14 @@
         }
 
         return true;
+    }
+    
+    /**
+     * @see Object#hashCode()
+     */
+    public int hashCode()
+    {
+        int hash = 7;
+        return hash*31 + keyMap.hashCode();
     }
 }

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/Message.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/Message.java?view=diff&rev=491848&r1=491847&r2=491848
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/Message.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/Message.java
Tue Jan  2 08:51:57 2007
@@ -47,7 +47,7 @@
      * @return Map of OID strings to Control object instances.
      * @see Control
      */
-    Map getControls();
+    Map<String, Control> getControls();
 
 
     /**

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchRequestImpl.java?view=diff&rev=491848&r1=491847&r2=491848
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchRequestImpl.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchRequestImpl.java
Tue Jan  2 08:51:57 2007
@@ -24,6 +24,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.filter.BranchNormalizedVisitor;
@@ -63,7 +64,7 @@
     private DerefAliasesEnum derefAliases;
 
     /** Attributes to return */
-    private Collection attributes = new ArrayList();
+    private List<String> attributes = new ArrayList<String>();
 
     /** The final result containing SearchResponseDone response */
     private SearchResponseDone response;
@@ -196,7 +197,7 @@
      */
     public MessageTypeEnum[] getResponseTypes()
     {
-        return ( MessageTypeEnum[] ) RESPONSE_TYPES.clone();
+        return RESPONSE_TYPES.clone();
     }
 
 



Mime
View raw message