You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/08/23 03:18:49 UTC

svn commit: rev 36728 - incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message

Author: akarasulu
Date: Sun Aug 22 18:18:49 2004
New Revision: 36728

Modified:
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/ReferralImpl.java
Log:
Commit changes ...

 o added equals method
 o switched to using HashSet instead of an ArrayList for faster lookups
 o formatting: cleaned up a_, m_ and fixed semi-colon spacing
 


Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/ReferralImpl.java
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/ReferralImpl.java	(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/ReferralImpl.java	Sun Aug 22 18:18:49 2004
@@ -14,17 +14,13 @@
  *   limitations under the License.
  *
  */
-package org.apache.ldap.common.message ;
+package org.apache.ldap.common.message;
 
 
-import java.util.ArrayList ;
-import java.util.Collection ;
-import java.util.Collections ;
+import java.util.*;
 
-import javax.naming.NamingException ;
-
-import org.apache.ldap.common.Lockable ;
-import org.apache.ldap.common.AbstractLockable ;
+import org.apache.ldap.common.Lockable;
+import org.apache.ldap.common.AbstractLockable;
 
 
 /**
@@ -41,7 +37,7 @@
     extends AbstractLockable implements Referral
 {
     /** Sequence of LDAPUrls composing this Referral */
-    private final Collection m_urls = new ArrayList() ;
+    private final HashSet urls = new HashSet();
 
 
     // ------------------------------------------------------------------------
@@ -53,11 +49,11 @@
      * Creates a non-root Lockable Referral implemenation dependant on a parent
      * Lockable
      *
-     * @param a_parent the overriding parent Lockable.
+     * @param parent the overriding parent Lockable.
      */
-    public ReferralImpl( final Lockable a_parent )
+    public ReferralImpl( final Lockable parent )
     {
-        super( a_parent, false ) ;
+        super( parent, false );
     }
 
 
@@ -73,34 +69,75 @@
      */
     public Collection getLdapUrls()
     {
-        return Collections.unmodifiableCollection( m_urls ) ;
+        return Collections.unmodifiableCollection( urls );
     }
 
 
     /**
      * Adds an LDAPv3 URL to this Referral.
      *
-     * @param a_url the LDAPv3 URL to add
-     * @throws NamingException if the implementation validates for correct 
-     * syntax
+     * @param url the LDAPv3 URL to add
      */
-    public void addLdapUrl( String a_url )
+    public void addLdapUrl( String url )
     {
-        lockCheck( "Atempt to add alternative url to locked Referral!" ) ;
-        m_urls.add( a_url ) ;
+        lockCheck( "Atempt to add alternative url to locked Referral!" );
+        urls.add( url );
     }
 
 
     /**
      * Removes an LDAPv3 URL to this Referral.
      *
-     * @param a_url the LDAPv3 URL to remove
-     * @throws NamingException if the implementation validates for correct 
-     * syntax
+     * @param url the LDAPv3 URL to remove
      */
-    public void removeLdapUrl( String a_url )
+    public void removeLdapUrl( String url )
     {
-        lockCheck( "Atempt to remove alternative url from locked Referral!" ) ;
-        m_urls.remove( a_url ) ;
+        lockCheck( "Atempt to remove alternative url from locked Referral!" );
+        urls.remove( url );
+    }
+
+
+    /**
+     * 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 exactly.  The order of Referral URLs does not matter.
+     *
+     * @param obj the object to compare this ReferralImpl to
+     * @return true if both implementations contain exactly the same URLs
+     */
+    public boolean equals( Object obj )
+    {
+        // just in case for speed return true if obj is this object
+        if ( obj == this )
+        {
+            return true;
+        }
+
+        if ( obj instanceof Referral )
+        {
+            Collection refs = ( ( Referral ) obj ).getLdapUrls();
+
+            // if their sizes do not match they are not equal
+            if ( refs.size() != urls.size() )
+            {
+                return false;
+            }
+
+            Iterator list = urls.iterator();
+            while ( list.hasNext() )
+            {
+                // if one of our urls is not contained in the obj return false
+                if ( ! refs.contains( list.next() ) )
+                {
+                    return false;
+                }
+            }
+
+            // made it through the checks so we have a match
+            return true;
+        }
+
+        return false;
     }
 }