directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r357847 - /directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java
Date Tue, 20 Dec 2005 00:02:12 GMT
Author: elecharny
Date: Mon Dec 19 16:02:08 2005
New Revision: 357847

URL: http://svn.apache.org/viewcvs?rev=357847&view=rev
Log:
- Added a hashCode() method
- fixed the compareTo() method
TODO : finish the toOid method (it does not convert multi-NC RDNs)

Modified:
    directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java

Modified: directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java?rev=357847&r1=357846&r2=357847&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java
(original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/LdapDN.java
Mon Dec 19 16:02:08 2005
@@ -469,6 +469,16 @@
     	
     	return sb.toString();
     }
+    
+    /**
+     * Gets the hashcode of the string representation of this name.
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode()
+    {
+        return upName.hashCode() ;
+    }
+    
 
     /**
      * Get the initial DN (without normalization) 
@@ -954,7 +964,7 @@
 
             for ( int i = 0; i < size(); i++ ) 
             {
-                if ( ( (LdapRDN)name.rdns.get( i ) ).compareTo( rdns.get( i ) ) == LdapRDN.NOT_EQUALS)
+                if ( ( (LdapRDN)name.rdns.get( i ) ).compareTo( rdns.get( i ) ) != LdapRDN.EQUALS)
                 {
                     return false;
                 }
@@ -998,20 +1008,18 @@
             
             if ( ldapDN.size() != size() )
             {
-                return NOT_EQUALS;
+                return size() - ldapDN.size();
             }
-            
-            Iterator dn1Iter = rdns.iterator();
-            Iterator dn2Iter = ldapDN.rdns.iterator();
-            
-            while ( dn1Iter.hasNext() && dn2Iter.hasNext() )
+
+            for ( int i = rdns.size(); i > 0; i-- )
             {
-                LdapRDN rdn1 = (LdapRDN)dn1Iter.next();
-                LdapRDN rdn2 = (LdapRDN)dn2Iter.next();
+            	LdapRDN rdn1 = (LdapRDN) rdns.get( i - 1 );
+            	LdapRDN rdn2 = (LdapRDN) ldapDN.rdns.get( i - 1 );
+                int res = rdn1.compareTo( rdn2 );
                 
-                if ( rdn1.compareTo( rdn2 ) == LdapRDN.NOT_EQUALS )
+                if ( res != 0 )
                 {
-                    return NOT_EQUALS;
+                    return res;
                 }
             }
             
@@ -1019,7 +1027,7 @@
         }
         else
         {
-            return NOT_EQUALS;
+            return 1;
         }
     }
 
@@ -1030,50 +1038,41 @@
     		return dn;
     	}
     	
-    	LdapDN newDn = new LdapDN();
+    	LdapDN newDn = (LdapDN)dn.clone();
     	
-    	Enumeration rdns = dn.getAll();
+    	Enumeration rdns = newDn.getAll();
     	
     	while ( rdns.hasMoreElements() )
     	{
-    		 String rdn = (String)rdns.nextElement();
+    		 LdapRDN rdn = (LdapRDN)rdns.nextElement();
     		 
-    		 if ( rdn.indexOf( '+' ) != -1 )
+    		 if ( rdn.getNbAtavs() > 1 )
     		 {
     			 
     		 }
     		 else
     		 {
-    			 int posEqual = rdn.indexOf( '=' );
-    			 
-    			 if ( posEqual > 0 )
-    			 {
-    				 String name = StringUtils.trim( rdn.substring( 0, posEqual ) );
+    			 AttributeTypeAndValue atav = rdn.getAtav();
+    			 String type = StringUtils.trim( atav.getType() );
     				 
-    				 if ( StringUtils.isEmpty( StringUtils.lowerCase( name ) ) == false )
-    				 {
-    					 String oid = (String)oids.get( name );
+    			if ( StringUtils.isEmpty( StringUtils.lowerCase( type ) ) == false )
+    			{
+    				String oid = (String)oids.get( type );
     					 
-    					 if ( oid != null )
-    					 {
-        					 String newRdn = oid + rdn.substring( posEqual );
-        					 newDn.add( newRdn );
-    					 }
-    					 else
-    					 {
-    						 return null;
-    					 }
-    				 }
-    				 else
-    				 {
-    					 return null;
-    				 }
-    			 }
-    			 else
-    			 {
-    				 return  null;
-    			 }
-				 
+					 if ( oid != null )
+					 {
+						 rdn.removeAttributeTypeAndValue( atav.getType() );
+						 rdn.addAttributeTypeAndValue( oid, atav.getValue() );
+					 }
+					 else
+					 {
+						 return null;
+					 }
+				 }
+				 else
+				 {
+					 return null;
+				 }
 			 }
     	}
     	



Mime
View raw message