directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r946251 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/message/ test/java/org/apache/directory/shared/ldap/message/
Date Wed, 19 May 2010 16:06:58 GMT
Author: felixk
Date: Wed May 19 16:06:57 2010
New Revision: 946251

URL: http://svn.apache.org/viewvc?rev=946251&view=rev
Log:
Override hashCode when overriding equals

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/DeleteRequestImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedRequestImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedResponseImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/IntermediateResponseImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapResultImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ReferralImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchRequestImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImpl.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/LdapResultImplTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ReferralImplTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImplTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImplTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImplTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/CompareRequestImpl.java
Wed May 19 16:06:57 2010
@@ -197,6 +197,36 @@ public class CompareRequestImpl extends 
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( name != null )
+        {
+            hash = hash * 17 + name.hashCode();
+        }
+        if ( attrId != null )
+        {
+            hash = hash * 17 + attrId.hashCode();
+        }
+        if ( attrVal != null )
+        {
+            hash = hash * 17 + attrVal.hashCode();
+        }
+        Value<?> reqVal = getAssertionValue();
+        if ( reqVal != null )
+        {
+            hash = hash * 17 + reqVal.hashCode();
+        }
+        hash = hash * 17 + super.hashCode();
+
+        return hash;
+    }
+
+
+    /**
      * Checks to see if an object is equivalent to this CompareRequest.
      * 
      * @param obj the obj to compare with this CompareRequest

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/DeleteRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/DeleteRequestImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/DeleteRequestImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/DeleteRequestImpl.java
Wed May 19 16:06:57 2010
@@ -122,6 +122,23 @@ public class DeleteRequestImpl extends A
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( name != null )
+        {
+            hash = hash * 17 + name.hashCode();
+        }
+        hash = hash * 17 + super.hashCode();
+
+        return hash;
+    }
+
+
+    /**
      * Checks to see if an object is equivalent to this DeleteRequest. First
      * there's a quick test to see if the obj is the same object as this one -
      * if so true is returned. Next if the super method fails false is returned.

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedRequestImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedRequestImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedRequestImpl.java
Wed May 19 16:06:57 2010
@@ -169,6 +169,27 @@ public class ExtendedRequestImpl extends
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( oid != null )
+        {
+            hash = hash * 17 + oid.hashCode();
+        }
+        if ( payload != null )
+        {
+            hash = hash * 17 + Arrays.hashCode( payload );
+        }
+        hash = hash * 17 + super.hashCode();
+
+        return hash;
+    }
+
+
+    /**
      * Checks to see if an object equals this ExtendedRequest.
      * 
      * @param obj

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedResponseImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedResponseImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedResponseImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ExtendedResponseImpl.java
Wed May 19 16:06:57 2010
@@ -140,6 +140,27 @@ public class ExtendedResponseImpl extend
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( oid != null )
+        {
+            hash = hash * 17 + oid.hashCode();
+        }
+        if ( value != null )
+        {
+            hash = hash * 17 + Arrays.hashCode( value );
+        }
+        hash = hash * 17 + super.hashCode();
+
+        return hash;
+    }
+
+
+    /**
      * Checks to see if an object equals this ExtendedRequest.
      * 
      * @param obj

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/IntermediateResponseImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/IntermediateResponseImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/IntermediateResponseImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/IntermediateResponseImpl.java
Wed May 19 16:06:57 2010
@@ -118,6 +118,27 @@ public class IntermediateResponseImpl ex
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( oid != null )
+        {
+            hash = hash * 17 + oid.hashCode();
+        }
+        if ( value != null )
+        {
+            hash = hash * 17 + Arrays.hashCode( value );
+        }
+        hash = hash * 17 + super.hashCode();
+
+        return hash;
+    }
+
+
+    /**
      * Checks to see if an object equals this IntemediateResponse.
      * 
      * @param obj the object to be checked for equality

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapResultImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapResultImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapResultImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapResultImpl.java
Wed May 19 16:06:57 2010
@@ -177,6 +177,31 @@ public class LdapResultImpl implements I
 
 
     /**
+     * @see Object#hashCode()
+     * @return the instance's hash code 
+     */
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( referral != null )
+        {
+            hash = hash * 17 + referral.hashCode();
+        }
+        hash = hash * 17 + resultCode.hashCode();
+        if ( errorMessage != null )
+        {
+            hash = hash * 17 + errorMessage.hashCode();
+        }
+        if ( matchedDn != null )
+        {
+            hash = hash * 17 + matchedDn.hashCode();
+        }
+
+        return hash;
+    }
+
+
+    /**
      * @param obj The object to compare with
      * @return <code>true</code> if both objects are equals
      */

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImpl.java
Wed May 19 16:06:57 2010
@@ -233,6 +233,33 @@ public class ModifyDnRequestImpl extends
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( name != null )
+        {
+            hash = hash * 17 + name.hashCode();
+        }
+        hash = hash * 17 + ( deleteOldRdn ? 0 : 1 );
+
+        if ( newRdn != null )
+        {
+            hash = hash * 17 + newRdn.hashCode();
+        }
+        if ( newSuperior != null )
+        {
+            hash = hash * 17 + newSuperior.hashCode();
+        }
+        hash = hash * 17 + super.hashCode();
+
+        return hash;
+    }
+
+
+    /**
      * Checks to see of an object equals this ModifyDnRequest stub. The equality
      * presumes all ModifyDnRequest specific properties are the same.
      * 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModifyRequestImpl.java
Wed May 19 16:06:57 2010
@@ -21,6 +21,7 @@ package org.apache.directory.shared.ldap
 
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -168,6 +169,28 @@ public class ModifyRequestImpl extends A
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( name != null )
+        {
+            hash = hash * 17 + name.hashCode();
+        }
+        hash = hash * 17 + mods.size();
+        for ( int i = 0; i < mods.size(); i++ )
+        {
+            hash = hash * 17 + ( ( DefaultModification ) mods.get( i ) ).hashCode();
+        }
+        hash = hash * 17 + super.hashCode();
+
+        return hash;
+    }
+
+
+    /**
      * Checks to see if ModifyRequest stub equals another by factoring in checks
      * for the name and modification items of the request.
      * 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ReferralImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ReferralImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ReferralImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ReferralImpl.java
Wed May 19 16:06:57 2010
@@ -85,6 +85,25 @@ public class ReferralImpl implements Int
 
 
     /**
+     * @see Object#hashCode()
+     * @return the instance's hash code 
+     */
+    public int hashCode()
+    {
+        int hash = 37;
+        hash = hash * 17 + urls.size();
+
+        // Order doesn't matter, so just add the url hashCode
+        for ( String url : urls )
+        {
+            hash = hash + url.hashCode();
+        }
+
+        return hash;
+    }
+
+
+    /**
      * Compares this Referral implementation to see if it is the same as
      * another. The classes do not have to be the same implementation to return
      * true. Both this and the compared Referral must have the same entries

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchRequestImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchRequestImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchRequestImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchRequestImpl.java
Wed May 19 16:06:57 2010
@@ -354,6 +354,41 @@ public class SearchRequestImpl extends A
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( baseDn != null )
+        {
+            hash = hash * 17 + baseDn.hashCode();
+        }
+        hash = hash * 17 + aliasDerefMode.hashCode();
+        hash = hash * 17 + scope.hashCode();
+        hash = hash * 17 + Long.valueOf( sizeLimit ).hashCode();
+        hash = hash * 17 + timeLimit;
+        hash = hash * 17 + ( typesOnly ? 0 : 1 );
+        if ( attributes != null )
+        {
+            hash = hash * 17 + attributes.size();
+
+            // Order doesn't matter, thus just add hashCode
+            for ( String attr : attributes )
+            {
+                hash = hash + attr.hashCode();
+            }
+        }
+        BranchNormalizedVisitor visitor = new BranchNormalizedVisitor();
+        filter.accept( visitor );
+        hash = hash * 17 + filter.toString().hashCode();
+        hash = hash * 17 + super.hashCode();
+
+        return hash;
+    }
+
+
+    /**
      * Checks to see if two search requests are equal. The Lockable properties
      * and the get/set context specific parameters are not consulted to
      * determine equality. The filter expression tree comparison will normalize

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImpl.java
Wed May 19 16:06:57 2010
@@ -55,6 +55,20 @@ public class SearchResponseDoneImpl exte
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        hash = hash * 17 + getLdapResult().hashCode();
+        hash = hash * 17 + super.hashCode();
+
+        return hash;
+    }
+
+
+    /**
      * Checks for equality by using the underlying LdapResult objects of this
      * SearchResponseDone stub.
      * 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImpl.java
Wed May 19 16:06:57 2010
@@ -109,6 +109,23 @@ public class SearchResponseEntryImpl ext
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( entry != null )
+        {
+            hash = hash * 17 + entry.hashCode();
+        }
+        hash = hash * 17 + super.hashCode();
+
+        return hash;
+    }
+
+
+    /**
      * Checks for equality by comparing the objectName, and attributes
      * properties of this Message after delegating to the super.equals() method.
      * 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImpl.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImpl.java
Wed May 19 16:06:57 2010
@@ -84,6 +84,23 @@ public class SearchResponseReferenceImpl
 
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode()
+    {
+        int hash = 37;
+        if ( this.referral != null )
+        {
+            hash = hash * 17 + this.referral.hashCode();
+        }
+        hash = hash * 17 + super.hashCode();
+
+        return hash;
+    }
+
+
+    /**
      * Checks to see if an object is equal to this SearchResponseReference stub.
      * 
      * @param obj

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java
Wed May 19 16:06:57 2010
@@ -47,7 +47,7 @@ public class CompareRequestImplTest
     private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String,
Control>();
 
     /**
-     * Tests the same object referrence for equality.
+     * Tests the same object reference for equality.
      */
     @Test
     public void testEqualsSameObj()
@@ -79,6 +79,37 @@ public class CompareRequestImplTest
 
 
     /**
+     * Tests the same object reference for equal hashCode.
+     */
+    @Test
+    public void testHashCodeSameObj()
+    {
+        CompareRequestImpl req = new CompareRequestImpl( 5 );
+        assertTrue( req.hashCode() == req.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode using exact copies.
+     */
+    @Test
+    public void testHashCodeExactCopy() throws LdapException
+    {
+        CompareRequestImpl req0 = new CompareRequestImpl( 5 );
+        req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+        req0.setAttributeId( "objectClass" );
+        req0.setAssertionValue( "top" );
+
+        CompareRequestImpl req1 = new CompareRequestImpl( 5 );
+        req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+        req1.setAttributeId( "objectClass" );
+        req1.setAssertionValue( "top" );
+
+        assertTrue( req0.hashCode() == req1.hashCode() );
+    }
+
+
+    /**
      * Test for inequality when only the IDs are different.
      */
     @Test

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java
Wed May 19 16:06:57 2010
@@ -46,7 +46,7 @@ public class DeleteRequestImplTest
     private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String,
Control>();
 
     /**
-     * Tests the same object referrence for equality.
+     * Tests the same object reference for equality.
      */
     @Test
     public void testEqualsSameObj()
@@ -73,6 +73,33 @@ public class DeleteRequestImplTest
 
 
     /**
+     * Tests the same object reference for equal hashCode.
+     */
+    @Test
+    public void testHashCodeSameObj()
+    {
+        DeleteRequestImpl req = new DeleteRequestImpl( 5 );
+        assertTrue( req.hashCode() == req.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode using exact copies.
+     */
+    @Test
+    public void testHashCodeExactCopy() throws LdapException
+    {
+        DeleteRequestImpl req0 = new DeleteRequestImpl( 5 );
+        req0.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+        DeleteRequestImpl req1 = new DeleteRequestImpl( 5 );
+        req1.setName( new DN( "cn=admin,dc=example,dc=com" ) );
+
+        assertTrue( req0.hashCode() == req1.hashCode() );
+    }
+
+
+    /**
      * Test for inequality when only the IDs are different.
      */
     @Test

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java
Wed May 19 16:06:57 2010
@@ -47,7 +47,7 @@ public class ExtendedRequestImplTest
     private static final Map<String, Control> EMPTY_CONTROL_MAP = new HashMap<String,
Control>();
 
     /**
-     * Tests the same object referrence for equality.
+     * Tests the same object reference for equality.
      */
     @Test
     public void testEqualsSameObj()
@@ -77,6 +77,35 @@ public class ExtendedRequestImplTest
 
 
     /**
+     * Tests the same object reference for equal hashCode.
+     */
+    @Test
+    public void testHashCodeSameObj()
+    {
+        ExtendedRequestImpl req = new ExtendedRequestImpl( 5 );
+        assertTrue( req.hashCode() == req.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode using exact copies.
+     */
+    @Test
+    public void testHashCodeExactCopy()
+    {
+        ExtendedRequestImpl req0 = new ExtendedRequestImpl( 5 );
+        req0.setOid( "1.1.1.1" );
+        req0.setPayload( "Hello World!".getBytes() );
+
+        ExtendedRequestImpl req1 = new ExtendedRequestImpl( 5 );
+        req1.setOid( "1.1.1.1" );
+        req1.setPayload( "Hello World!".getBytes() );
+
+        assertTrue( req0.hashCode() == req1.hashCode() );
+    }
+
+
+    /**
      * Test for inequality when only the IDs are different.
      */
     @Test

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java
Wed May 19 16:06:57 2010
@@ -228,6 +228,29 @@ public class ExtendedResponseImplTest
 
 
     /**
+     * Tests for equal hashCode using the same object.
+     */
+    @Test
+    public void testHashCodeSameObj()
+    {
+        ExtendedResponseImpl resp = createStub();
+        assertTrue( resp.hashCode() == resp.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode using an exact copy.
+     */
+    @Test
+    public void testHashCodeExactCopy()
+    {
+        ExtendedResponseImpl resp0 = createStub();
+        ExtendedResponseImpl resp1 = createStub();
+        assertTrue( resp0.hashCode() == resp1.hashCode() );
+    }
+
+
+    /**
      * Tests inequality when messageIds are different.
      */
     @Test

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/LdapResultImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/LdapResultImplTest.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/LdapResultImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/LdapResultImplTest.java
Wed May 19 16:06:57 2010
@@ -176,6 +176,74 @@ public class LdapResultImplTest
 
 
     /**
+     * Tests to make sure the two same objects have equal HashCode.
+     */
+    @Test
+    public void testHashCodeSameObj()
+    {
+        LdapResultImpl r0 = new LdapResultImpl();
+        assertTrue( r0.hashCode() == r0.hashCode() );
+    }
+
+
+    /**
+     * Tests to make sure a default LdapResultImpl has equal hashCode another one just
+     * created.
+     */
+    @Test
+    public void testHashCodeDefaultCopy()
+    {
+        LdapResultImpl r0 = new LdapResultImpl();
+        LdapResultImpl r1 = new LdapResultImpl();
+
+        assertTrue( r0.hashCode() == r1.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode when the lockable parent is not the same.
+     */
+    @Test
+    public void testHashCodeDiffLockableParent()
+    {
+        LdapResultImpl r0 = new LdapResultImpl();
+        LdapResultImpl r1 = new LdapResultImpl();
+
+        assertTrue( r0.hashCode() == r1.hashCode() );
+    }
+
+
+    /**
+     * Tests two non default carbon copies for equal hashCode.
+     */
+    @Test
+    public void testHashCodeCarbonCopy() throws LdapException
+    {
+        LdapResultImpl r0 = new LdapResultImpl();
+        LdapResultImpl r1 = new LdapResultImpl();
+
+        r0.setErrorMessage( "blah blah blah" );
+        r1.setErrorMessage( "blah blah blah" );
+
+        r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
+        r1.setMatchedDn( new DN( "dc=example,dc=com" ) );
+
+        r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+        r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
+
+        InternalReferral refs0 = new ReferralImpl();
+        refs0.addLdapUrl( "ldap://someserver.com" );
+        refs0.addLdapUrl( "ldap://anotherserver.org" );
+
+        InternalReferral refs1 = new ReferralImpl();
+        refs1.addLdapUrl( "ldap://someserver.com" );
+        refs1.addLdapUrl( "ldap://anotherserver.org" );
+
+        assertTrue( r0.hashCode() == r1.hashCode() );
+    }
+
+
+    /**
      * Tests for inequality when the error message is different.
      */
     @Test

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java
Wed May 19 16:06:57 2010
@@ -73,7 +73,7 @@ public class ModifyDnRequestImplTest
 
 
     /**
-     * Tests the same object referrence for equality.
+     * Tests the same object reference for equality.
      */
     @Test
     public void testEqualsSameObj()
@@ -112,6 +112,45 @@ public class ModifyDnRequestImplTest
 
 
     /**
+    * Tests the same object reference for equal hashCode
+    */
+   @Test
+   public void testHashCodeSameObj()
+   {
+       ModifyDnRequestImpl req = new ModifyDnRequestImpl( 5 );
+       assertTrue( req.hashCode() == req.hashCode() );
+   }
+
+
+   /**
+    * Tests for equal hashCode using exact copies.
+    */
+   @Test
+   public void testHashCodeExactCopy0()
+   {
+       ModifyDnRequestImpl req0 = getRequest();
+       ModifyDnRequestImpl req1 = getRequest();
+
+       assertTrue( req0.hashCode() == req1.hashCode() );
+   }
+
+
+   /**
+    * Tests for equal hashCode using exact copies.
+    */
+   @Test
+   public void testHashCodeExactCopy1()
+   {
+       ModifyDnRequestImpl req0 = getRequest();
+       req0.setNewSuperior( null );
+       ModifyDnRequestImpl req1 = getRequest();
+       req1.setNewSuperior( null );
+
+       assertTrue( req0.hashCode() == req1.hashCode() );
+   }
+
+
+    /**
      * Test for inequality when only the IDs are different.
      */
     @Test

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java
Wed May 19 16:06:57 2010
@@ -95,7 +95,7 @@ public class ModifyRequestImplTest
 
 
     /**
-     * Tests the same object referrence for equality.
+     * Tests the same object reference for equality.
      */
     @Test
     public void testEqualsSameObj()
@@ -118,6 +118,29 @@ public class ModifyRequestImplTest
 
 
     /**
+     * Tests the same object reference for equal hashCode.
+     */
+    @Test
+    public void testHashCodeSameObj()
+    {
+        ModifyRequestImpl req = getRequest();
+        assertTrue( req.hashCode() == req.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode using exact copies.
+     */
+    @Test
+    public void testHashCodeExactCopy()
+    {
+        ModifyRequestImpl req0 = getRequest();
+        ModifyRequestImpl req1 = getRequest();
+        assertTrue( req0.hashCode() == req1.hashCode() );
+    }
+
+
+    /**
      * Test for inequality when only the IDs are different.
      */
     @Test

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ReferralImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ReferralImplTest.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ReferralImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/ReferralImplTest.java
Wed May 19 16:06:57 2010
@@ -92,6 +92,57 @@ public class ReferralImplTest
 
 
     /**
+     * Tests to make sure to get equal hashCode for the same exact object.
+     */
+    @Test
+    public void testHashCodeSameObject()
+    {
+        ReferralImpl refs = new ReferralImpl();
+        assertTrue( refs.hashCode() == refs.hashCode() );
+    }
+
+
+    /**
+     * Tests to make sure to get equal hashCode for two objects that are the
+     * same exact copy of one another.
+     */
+    @Test
+    public void testHashCodeExactCopy()
+    {
+        ReferralImpl refs0 = new ReferralImpl();
+        refs0.addLdapUrl( "ldap://blah0" );
+        refs0.addLdapUrl( "ldap://blah1" );
+        refs0.addLdapUrl( "ldap://blah2" );
+        ReferralImpl refs1 = new ReferralImpl();
+        refs1.addLdapUrl( "ldap://blah0" );
+        refs1.addLdapUrl( "ldap://blah1" );
+        refs1.addLdapUrl( "ldap://blah2" );
+        assertTrue( refs0.hashCode() == refs1.hashCode() );
+    }
+
+
+    /**
+     * Tests to make sure to get equal hashCode for two objects that are the
+     * same exact copy of one another but there are redundant entries.
+     */
+    @Test
+    public void testHashCodeExactCopyWithRedundancy()
+    {
+        ReferralImpl refs0 = new ReferralImpl();
+        refs0.addLdapUrl( "ldap://blah0" );
+        refs0.addLdapUrl( "ldap://blah1" );
+        refs0.addLdapUrl( "ldap://blah2" );
+        refs0.addLdapUrl( "ldap://blah2" );
+        ReferralImpl refs1 = new ReferralImpl();
+        refs1.addLdapUrl( "ldap://blah0" );
+        refs1.addLdapUrl( "ldap://blah1" );
+        refs1.addLdapUrl( "ldap://blah2" );
+        refs1.addLdapUrl( "ldap://blah2" );
+        assertTrue( refs0.hashCode() == refs1.hashCode() );
+    }
+
+
+    /**
      * Tests to make sure the equals method works for two objects that are the
      * not exact copies of one another but have the same number of URLs.
      */

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImplTest.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImplTest.java
Wed May 19 16:06:57 2010
@@ -188,6 +188,29 @@ public class SearchResponseDoneImplTest
 
 
     /**
+     * Tests for equal hashCode using the same object.
+     */
+    @Test
+    public void testHashCodeSameObj()
+    {
+        SearchResponseDoneImpl resp = createStub();
+        assertTrue( resp.hashCode() == resp.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode using an exact copy.
+     */
+    @Test
+    public void testHashCodeExactCopy()
+    {
+        SearchResponseDoneImpl resp0 = createStub();
+        SearchResponseDoneImpl resp1 = createStub();
+        assertTrue( resp0.hashCode() == resp1.hashCode() );
+    }
+
+
+    /**
      * Tests inequality when messageIds are different.
      */
     @Test

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImplTest.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseEntryImplTest.java
Wed May 19 16:06:57 2010
@@ -73,7 +73,7 @@ public class SearchResponseEntryImplTest
 
 
     /**
-     * Tests for equality when the same object referrence is used.
+     * Tests for equality when the same object reference is used.
      */
     @Test
     public void testEqualsSameObject()
@@ -103,6 +103,35 @@ public class SearchResponseEntryImplTest
 
 
     /**
+     * Tests for equal hashCode when the same object reference is used.
+     */
+    @Test
+    public void testHashCodeSameObject()
+    {
+        SearchResponseEntryImpl resp = new SearchResponseEntryImpl( 5 );
+        assertTrue( resp.hashCode() == resp.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode when an exact copy is compared.
+     */
+    @Test
+    public void testHashCodeExactCopy() throws LdapException
+    {
+        SearchResponseEntryImpl resp0 = new SearchResponseEntryImpl( 5 );
+        resp0.setEntry( getEntry() );
+        resp0.setObjectName( new DN( "dc=example,dc=com" ) );
+
+        SearchResponseEntryImpl resp1 = new SearchResponseEntryImpl( 5 );
+        resp1.setEntry( getEntry() );
+        resp1.setObjectName( new DN( "dc=example,dc=com" ) );
+
+        assertTrue( resp0.hashCode() == resp1.hashCode() );
+    }
+
+
+    /**
      * Tests for inequality when the objectName dn is not the same.
      */
     @Test

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImplTest.java?rev=946251&r1=946250&r2=946251&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImplTest.java
Wed May 19 16:06:57 2010
@@ -63,7 +63,7 @@ public class SearchResponseReferenceImpl
 
 
     /**
-     * Tests for equality when the same object referrence is used.
+     * Tests for equality when the same object reference is used.
      */
     @Test
     public void testEqualsSameObject()
@@ -169,6 +169,33 @@ public class SearchResponseReferenceImpl
 
 
     /**
+     * Tests for equal hashCode when the same object reference is used.
+     */
+    @Test
+    public void testHashCodeSameObject()
+    {
+        SearchResponseReferenceImpl resp = new SearchResponseReferenceImpl( 5 );
+        getReferral( resp );
+        assertTrue( resp.hashCode() == resp.hashCode() );
+    }
+
+
+    /**
+     * Tests for equal hashCode when an exact copy is compared.
+     */
+    @Test
+    public void testHashCodeExactCopy()
+    {
+        SearchResponseReferenceImpl resp0 = new SearchResponseReferenceImpl( 5 );
+        getReferral( resp0 );
+        SearchResponseReferenceImpl resp1 = new SearchResponseReferenceImpl( 5 );
+        getReferral( resp1 );
+
+        assertTrue( resp0.hashCode() == resp1.hashCode() );
+    }
+
+
+    /**
      * Tests for inequality when the urls are not the same.
      */
     @Test



Mime
View raw message