directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1749380 - in /directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name: Ava.java Dn.java Rdn.java
Date Mon, 20 Jun 2016 18:50:49 GMT
Author: elecharny
Date: Mon Jun 20 18:50:48 2016
New Revision: 1749380

URL: http://svn.apache.org/viewvc?rev=1749380&view=rev
Log:
o Added the processing of RDN with multiple AVAs
o Sped up the DN comparison, using the normName when we have it

Modified:
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java?rev=1749380&r1=1749379&r2=1749380&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
Mon Jun 20 18:50:48 2016
@@ -413,6 +413,8 @@ public class Ava implements Externalizab
         
         this.upName = upName;
     }
+    
+    
     /**
      * Construct an Ava. The type and value are normalized :
      * <li> the type is trimmed and lowercased </li>

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java?rev=1749380&r1=1749379&r2=1749380&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java
Mon Jun 20 18:50:48 2016
@@ -1047,6 +1047,12 @@ public class Dn implements Iterable<Rdn>
             return false;
         }
 
+        // Shortcut if the Dn is normalized
+        if ( isSchemaAware() )
+        {
+            return normName.equals( other.normName );
+        }
+        
         for ( int i = 0; i < this.size(); i++ )
         {
             if ( !other.rdns.get( i ).equals( rdns.get( i ) ) )

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java?rev=1749380&r1=1749379&r2=1749380&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
(original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
Mon Jun 20 18:50:48 2016
@@ -481,34 +481,34 @@ public class Rdn implements Cloneable, E
                     
                     List<Ava> avaList = avaTypes.get( tmpAva.getNormType() );
                     
-                    if ( avaList == null )
+                    boolean empty = avaList == null;
+                    avaList = addOrdered( avaList, tmpAva );
+                    
+                    if ( empty )
                     {
-                        avaList = new ArrayList<>();
-                        avaList.add( tmpAva );
                         avaTypes.put( tmpAva.getNormType(), avaList );
-                        avas.add( tmpAva );
-                    }
-                    else if ( !avaList.contains( tmpAva ) )
-                    {
-                        avaList.add( tmpAva );
-                        avas.add( tmpAva );
                     }
                     
+                    addOrdered( avas, tmpAva );
+                }
+                
+                for ( Ava ava : avas )
+                {
                     if ( isFirst )
                     {
                         isFirst = false;
                     }
                     else
                     {
-                        sb.append( ',' );
+                        sb.append( '+' );
                     }
                     
-                    sb.append( currentAva.getNormType() );
+                    sb.append( ava.getNormType() );
                     sb.append( '=' );
                     
-                    if ( ( currentAva.getValue() != null ) && ( currentAva.getValue().getNormalized()
!= null ) )
+                    if ( ( ava.getValue() != null ) && ( ava.getValue().getNormalized()
!= null ) )
                     {
-                        sb.append( currentAva.getValue().getNormalized() );
+                        sb.append( ava.getValue().getNormalized() );
                     }
                 }
 
@@ -520,6 +520,56 @@ public class Rdn implements Cloneable, E
                 return;
         }
     }
+    
+    
+    /**
+     * Add an AVA in a List of Ava, at the right place (ordered)
+     */
+    private List<Ava> addOrdered( List<Ava> avaList, Ava newAva )
+    {
+        if ( avaList == null )
+        {
+            avaList = new ArrayList<>();
+        }
+        
+        if ( avaList.size() == 0 )
+        {
+            avaList.add( newAva );
+            return avaList;
+        }
+        
+        // Insert the AVA in the list, ordered.
+        int pos = 0;
+        boolean found = false;
+        
+        for ( Ava avaElem : avaList )
+        {
+            int comp = newAva.compareTo( avaElem );
+                
+            if ( comp < 0 )
+            {
+                avaList.add( pos, newAva );
+                found = true;
+                break;
+            }
+            else if ( comp == 0 )
+            {
+                found = true;
+                break;
+            }
+            else 
+            {
+                pos++;
+            }
+        }
+        
+        if ( !found )
+        {
+            avaList.add( newAva );
+        }
+        
+        return avaList;
+    }
 
 
     /**
@@ -702,10 +752,31 @@ public class Rdn implements Cloneable, E
                 else
                 {
                     // We have at least one Ava with the same type, check if it's the same
value
-                    if ( !avaList.contains( addedAva ) )
+                    addOrdered( avaList, addedAva );
+                    
+                    boolean found = false;
+                    
+                    for ( int pos = 0; pos < avas.size(); pos++ )
+                    {
+                        int comp = addedAva.compareTo( avas.get( pos ) );
+                        
+                        if ( comp < 0 )
+                        {
+                            avas.add( pos, addedAva );
+                            found = true;
+                            nbAvas++;
+                            break;
+                        }
+                        else if ( comp == 0 )
+                        {
+                            found = true;
+                            break;
+                        }
+                    }
+                    
+                    // Ok, we can add it at the end if we haven't already added it
+                    if ( !found )
                     {
-                        // Ok, we can add it
-                        avaList.add( addedAva );
                         avas.add( addedAva );
                         nbAvas++;
                     }
@@ -2019,27 +2090,11 @@ public class Rdn implements Cloneable, E
                 }
                 
             default :
-                // Loop on all the Avas. As we have more than one,
-                // we have to order them by their AttributeType.
-                /*
+                // Loop on all the Avas. We expect the Ava to be ordered
                 if ( isSchemaAware() )
                 {
-                    for ( Ava otherAva : otherRdn )
-                    {
-                        List<Ava> attributeAvas = avaTypes.get( otherAva.getAttributeType().getOid()
);
-                        boolean found = false;
-                        
-                        for ( Ava thisAva : attributeAvas )
-                        {
-                            if ( thisAva.compareTo( otherAva ) == 0 )
-                            {
-                                found = true;
-                                break;
-                            }
-                        }
-                    }
+                    return normName.compareTo( otherRdn.normName );
                 }
-                */
                 
                 int pos = 0;
                 



Mime
View raw message