directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1746660 - in /directory/shared/branches/shared-value/ldap/extras/util/src: main/java/org/apache/directory/api/ldap/util/tree/DnNode.java test/java/org/apache/directory/api/ldap/util/tree/TestDnNode.java
Date Thu, 02 Jun 2016 23:37:06 GMT
Author: elecharny
Date: Thu Jun  2 23:37:06 2016
New Revision: 1746660

URL: http://svn.apache.org/viewvc?rev=1746660&view=rev
Log:
The DnNode map now use the Rdn NormName as a key, instead of a Dn, to speedup the lookup of
a DnNode.

Modified:
    directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java
    directory/shared/branches/shared-value/ldap/extras/util/src/test/java/org/apache/directory/api/ldap/util/tree/TestDnNode.java

Modified: directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java?rev=1746660&r1=1746659&r2=1746660&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java
(original)
+++ directory/shared/branches/shared-value/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java
Thu Jun  2 23:37:06 2016
@@ -68,7 +68,7 @@ public class DnNode<N> implements Clonea
     private DnNode<N> parent;
 
     /** Stores the list of all the descendant */
-    private Map<Rdn, DnNode<N>> children;
+    private Map<String, DnNode<N>> children;
 
 
     //-------------------------------------------------------------------------
@@ -122,7 +122,7 @@ public class DnNode<N> implements Clonea
                 node.nodeDn = rootNode.nodeDn.getParent();
                 node.depth = node.nodeDn.size() + depth;
                 rootNode.parent = node;
-                node.children.put( rootNode.nodeRdn, rootNode );
+                node.children.put( rootNode.nodeRdn.getNormName(), rootNode );
                 rootNode = node;
             }
 
@@ -150,7 +150,7 @@ public class DnNode<N> implements Clonea
      */
     public DnNode()
     {
-        children = new HashMap<Rdn, DnNode<N>>();
+        children = new HashMap<String, DnNode<N>>();
         nodeDn = Dn.EMPTY_DN;
         nodeRdn = Rdn.EMPTY_RDN;
     }
@@ -164,7 +164,7 @@ public class DnNode<N> implements Clonea
     public DnNode( N element )
     {
         this.nodeElement = element;
-        children = new HashMap<Rdn, DnNode<N>>();
+        children = new HashMap<String, DnNode<N>>();
     }
 
 
@@ -178,7 +178,7 @@ public class DnNode<N> implements Clonea
     {
         if ( ( dn == null ) || ( dn.isEmpty() ) )
         {
-            children = new HashMap<Rdn, DnNode<N>>();
+            children = new HashMap<String, DnNode<N>>();
             this.nodeDn = Dn.EMPTY_DN;
 
             return;
@@ -467,7 +467,7 @@ public class DnNode<N> implements Clonea
     /**
      * @return The list of DnNode
      */
-    public synchronized Map<Rdn, DnNode<N>> getChildren()
+    public synchronized Map<String, DnNode<N>> getChildren()
     {
         return children;
     }
@@ -519,7 +519,7 @@ public class DnNode<N> implements Clonea
             }
             else if ( currentNode.hasChildren() )
             {
-                currentNode = currentNode.children.get( rdn );
+                currentNode = currentNode.children.get( rdn.getNormName() );
 
                 if ( currentNode == null )
                 {
@@ -572,7 +572,7 @@ public class DnNode<N> implements Clonea
             // No parent : add a new node to the root
             DnNode<N> childNode = createNode( dn, element, dn.size() );
             childNode.parent = this;
-            children.put( childNode.nodeRdn, childNode );
+            children.put( childNode.nodeRdn.getNormName(), childNode );
             
             return childNode;
         }
@@ -611,7 +611,7 @@ public class DnNode<N> implements Clonea
 
                 // done. now, add the newly created tree to the parent node
                 childNode.parent = parentNode;
-                parentNode.children.put( childNode.nodeRdn, childNode );
+                parentNode.children.put( childNode.nodeRdn.getNormName(), childNode );
 
                 return childNode;
             }
@@ -650,7 +650,7 @@ public class DnNode<N> implements Clonea
 
         for ( Rdn rdn : dn.getRdns() )
         {
-            parentNode.children.remove( rdn );
+            parentNode.children.remove( rdn.getNormName() );
 
             if ( parentNode.children.size() > 0 )
             {
@@ -672,7 +672,7 @@ public class DnNode<N> implements Clonea
      */
     public synchronized boolean contains( Rdn rdn )
     {
-        return children.containsKey( rdn );
+        return children.containsKey( rdn.getNormName() );
     }
 
 
@@ -684,9 +684,9 @@ public class DnNode<N> implements Clonea
      */
     public synchronized DnNode<N> getChild( Rdn rdn )
     {
-        if ( children.containsKey( rdn ) )
+        if ( children.containsKey( rdn.getNormName() ) )
         {
-            return children.get( rdn );
+            return children.get( rdn.getNormName() );
         }
 
         return null;
@@ -714,19 +714,17 @@ public class DnNode<N> implements Clonea
      */
     public synchronized DnNode<N> getNode( Dn dn )
     {
-        List<Rdn> rdns = dn.getRdns();
-
         DnNode<N> currentNode = this;
         DnNode<N> parentNode = null;
 
         // Iterate through all the Rdn until we find the associated partition
-        for ( int i = rdns.size() - 1; i >= 0; i-- )
+        for ( int i = dn.size() - 1; i >= 0; i-- )
         {
-            Rdn rdn = rdns.get( i );
+            Rdn rdn = dn.getRdn( i );
 
             if ( currentNode.hasChildren() )
             {
-                currentNode = currentNode.children.get( rdn );
+                currentNode = currentNode.children.get( rdn.getNormName() );
 
                 if ( currentNode == null )
                 {
@@ -769,7 +767,7 @@ public class DnNode<N> implements Clonea
 
             if ( currentNode.hasChildren() )
             {
-                currentNode = currentNode.children.get( rdn );
+                currentNode = currentNode.children.get( rdn.getNormName() );
 
                 if ( currentNode == null )
                 {
@@ -817,7 +815,7 @@ public class DnNode<N> implements Clonea
 
             if ( currentNode.hasChildren() )
             {
-                currentNode = currentNode.children.get( rdn );
+                currentNode = currentNode.children.get( rdn.getNormName() );
 
                 if ( currentNode == null )
                 {
@@ -887,8 +885,8 @@ public class DnNode<N> implements Clonea
 
         if ( parent != null )
         {
-            parent.children.remove( oldRdn );
-            parent.children.put( nodeRdn, this );
+            parent.children.remove( oldRdn.getNormName() );
+            parent.children.put( nodeRdn.getNormName(), this );
         }
 
         updateAfterModDn( nodeDn );
@@ -944,11 +942,11 @@ public class DnNode<N> implements Clonea
 
         if ( parent != null )
         {
-            parent.children.remove( nodeRdn );
+            parent.children.remove( nodeRdn.getNormName() );
         }
 
         parent = tmp;
-        parent.children.put( nodeRdn, this );
+        parent.children.put( nodeRdn.getNormName(), this );
     }
 
 
@@ -986,7 +984,7 @@ public class DnNode<N> implements Clonea
 
         for ( DnNode<N> node : children.values() )
         {
-            clonedDnNode.children.put( node.getRdn(), node.clone() );
+            clonedDnNode.children.put( node.getRdn().getNormName(), node.clone() );
         }
 
         return clonedDnNode;
@@ -1026,7 +1024,7 @@ public class DnNode<N> implements Clonea
 
         if ( hasChildren )
         {
-            for ( Map.Entry<Rdn, DnNode<N>> entry : children.entrySet() )
+            for ( Map.Entry<String, DnNode<N>> entry : children.entrySet() )
             {
                 if ( isFirst )
                 {

Modified: directory/shared/branches/shared-value/ldap/extras/util/src/test/java/org/apache/directory/api/ldap/util/tree/TestDnNode.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/extras/util/src/test/java/org/apache/directory/api/ldap/util/tree/TestDnNode.java?rev=1746660&r1=1746659&r2=1746660&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/extras/util/src/test/java/org/apache/directory/api/ldap/util/tree/TestDnNode.java
(original)
+++ directory/shared/branches/shared-value/ldap/extras/util/src/test/java/org/apache/directory/api/ldap/util/tree/TestDnNode.java
Thu Jun  2 23:37:06 2016
@@ -78,15 +78,15 @@ public class TestDnNode
 
         assertNotNull( tree );
 
-        Map<Rdn, DnNode<Dn>> children = tree.getChildren();
+        Map<String, DnNode<Dn>> children = tree.getChildren();
         assertNotNull( children );
 
         assertEquals( 1, children.size() );
         assertNull( tree.getElement() );
 
-        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ) );
-        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ) );
-        DnNode<Dn> level3 = level2.getChildren().get( new Rdn( "dc=c" ) );
+        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ).getNormName() );
+        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ).getNormName()
);
+        DnNode<Dn> level3 = level2.getChildren().get( new Rdn( "dc=c" ).getNormName()
);
 
         assertNotNull( level3 );
         assertFalse( level3.hasElement() );
@@ -108,20 +108,20 @@ public class TestDnNode
 
         assertNotNull( tree );
 
-        Map<Rdn, DnNode<Dn>> children = tree.getChildren();
+        Map<String, DnNode<Dn>> children = tree.getChildren();
         assertNotNull( children );
 
         assertEquals( 2, children.size() );
         assertNull( tree.getElement() );
 
-        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ) );
-        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ) );
+        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ).getNormName() );
+        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ).getNormName()
);
 
         assertNotNull( level2 );
         assertFalse( level2.hasElement() );
 
-        level1 = children.get( new Rdn( "dc=e" ) );
-        level2 = level1.getChildren().get( new Rdn( "dc=f" ) );
+        level1 = children.get( new Rdn( "dc=e" ).getNormName() );
+        level2 = level1.getChildren().get( new Rdn( "dc=f" ).getNormName() );
 
         assertNotNull( level2 );
         assertFalse( level2.hasElement() );
@@ -143,16 +143,16 @@ public class TestDnNode
 
         assertNotNull( tree );
 
-        Map<Rdn, DnNode<Dn>> children = tree.getChildren();
+        Map<String, DnNode<Dn>> children = tree.getChildren();
         assertNotNull( children );
 
         assertEquals( 1, children.size() );
         assertNull( tree.getElement() );
 
-        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ) );
-        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ) );
+        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ).getNormName() );
+        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ).getNormName()
);
 
-        Map<Rdn, DnNode<Dn>> childrenDn1 = level1.getChildren();
+        Map<String, DnNode<Dn>> childrenDn1 = level1.getChildren();
         assertNotNull( childrenDn1 );
 
         assertEquals( 2, childrenDn1.size() );
@@ -161,8 +161,8 @@ public class TestDnNode
         assertNotNull( level2 );
         assertFalse( level2.hasElement() );
 
-        level1 = children.get( new Rdn( "dc=a" ) );
-        level2 = level1.getChildren().get( new Rdn( "dc=f" ) );
+        level1 = children.get( new Rdn( "dc=a" ).getNormName() );
+        level2 = level1.getChildren().get( new Rdn( "dc=f" ).getNormName() );
 
         assertNotNull( level2 );
         assertFalse( level2.hasElement() );
@@ -212,15 +212,15 @@ public class TestDnNode
 
         assertNotNull( tree );
 
-        Map<Rdn, DnNode<Dn>> children = tree.getChildren();
+        Map<String, DnNode<Dn>> children = tree.getChildren();
         assertNotNull( children );
 
         assertEquals( 1, children.size() );
         assertNull( tree.getElement() );
 
-        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ) );
-        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ) );
-        DnNode<Dn> level3 = level2.getChildren().get( new Rdn( "dc=c" ) );
+        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ).getNormName() );
+        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ).getNormName()
);
+        DnNode<Dn> level3 = level2.getChildren().get( new Rdn( "dc=c" ).getNormName()
);
 
         assertNotNull( level3 );
         assertEquals( dn, level3.getElement() );
@@ -242,20 +242,20 @@ public class TestDnNode
 
         assertNotNull( tree );
 
-        Map<Rdn, DnNode<Dn>> children = tree.getChildren();
+        Map<String, DnNode<Dn>> children = tree.getChildren();
         assertNotNull( children );
 
         assertEquals( 2, children.size() );
         assertNull( tree.getElement() );
 
-        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ) );
-        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ) );
+        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ).getNormName() );
+        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ).getNormName()
);
 
         assertNotNull( level2 );
         assertEquals( dn1, level2.getElement() );
 
-        level1 = children.get( new Rdn( "dc=e" ) );
-        level2 = level1.getChildren().get( new Rdn( "dc=f" ) );
+        level1 = children.get( new Rdn( "dc=e" ).getNormName() );
+        level2 = level1.getChildren().get( new Rdn( "dc=f" ).getNormName() );
 
         assertNotNull( level2 );
         assertEquals( dn2, level2.getElement() );
@@ -277,16 +277,16 @@ public class TestDnNode
 
         assertNotNull( tree );
 
-        Map<Rdn, DnNode<Dn>> children = tree.getChildren();
+        Map<String, DnNode<Dn>> children = tree.getChildren();
         assertNotNull( children );
 
         assertEquals( 1, children.size() );
         assertNull( tree.getElement() );
 
-        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ) );
-        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ) );
+        DnNode<Dn> level1 = children.get( new Rdn( "dc=a" ).getNormName() );
+        DnNode<Dn> level2 = level1.getChildren().get( new Rdn( "dc=b" ).getNormName()
);
 
-        Map<Rdn, DnNode<Dn>> childrenDn1 = level1.getChildren();
+        Map<String, DnNode<Dn>> childrenDn1 = level1.getChildren();
         assertNotNull( childrenDn1 );
 
         assertEquals( 2, childrenDn1.size() );
@@ -295,8 +295,8 @@ public class TestDnNode
         assertNotNull( level2 );
         assertEquals( dn1, level2.getElement() );
 
-        level1 = children.get( new Rdn( "dc=a" ) );
-        level2 = level1.getChildren().get( new Rdn( "dc=f" ) );
+        level1 = children.get( new Rdn( "dc=a" ).getNormName() );
+        level2 = level1.getChildren().get( new Rdn( "dc=f" ).getNormName() );
 
         assertNotNull( level2 );
         assertEquals( dn2, level2.getElement() );
@@ -329,14 +329,14 @@ public class TestDnNode
         tree.add( dn1 );
 
         assertTrue( tree.hasChildren() );
-        Map<Rdn, DnNode<Dn>> children = tree.getChildren();
+        Map<String, DnNode<Dn>> children = tree.getChildren();
         assertNotNull( children );
 
-        DnNode<Dn> child = children.get( new Rdn( "dc=a" ) );
+        DnNode<Dn> child = children.get( new Rdn( "dc=a" ).getNormName() );
         assertTrue( child.hasChildren() );
 
         children = child.getChildren();
-        child = children.get( new Rdn( "dc=b" ) );
+        child = children.get( new Rdn( "dc=b" ).getNormName() );
         assertFalse( child.hasChildren() );
     }
 



Mime
View raw message