You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2013/06/03 19:16:07 UTC

svn commit: r1489066 - /directory/shared/trunk/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java

Author: pamarcelot
Date: Mon Jun  3 17:16:07 2013
New Revision: 1489066

URL: http://svn.apache.org/r1489066
Log:
Updated the DnNode class to return the created node for the add(...) methods.

Modified:
    directory/shared/trunk/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java

Modified: directory/shared/trunk/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java?rev=1489066&r1=1489065&r2=1489066&view=diff
==============================================================================
--- directory/shared/trunk/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java (original)
+++ directory/shared/trunk/ldap/extras/util/src/main/java/org/apache/directory/api/ldap/util/tree/DnNode.java Mon Jun  3 17:16:07 2013
@@ -542,11 +542,12 @@ public class DnNode<N> implements Clonea
      * Add a new node in the tree. The added node won't have any element.
      *
      * @param dn The node's Dn
+     * @return the corresponding node
      * @throws LdapException if the Dn is null or empty
      */
-    public synchronized void add( Dn dn ) throws LdapException
+    public synchronized DnNode<N> add( Dn dn ) throws LdapException
     {
-        add( dn, null );
+        return add( dn, null );
     }
 
 
@@ -556,9 +557,10 @@ public class DnNode<N> implements Clonea
      *
      * @param dn The node's Dn
      * @param element The element to associate with this Node. Can be null.
+     * @return the corresponding node
      * @throws LdapException if the Dn is null or empty
      */
-    public synchronized void add( Dn dn, N element ) throws LdapException
+    public synchronized DnNode<N> add( Dn dn, N element ) throws LdapException
     {
         checkDn( dn );
 
@@ -571,6 +573,8 @@ public class DnNode<N> implements Clonea
             DnNode<N> childNode = createNode( dn, element, dn.size() );
             childNode.parent = this;
             children.put( childNode.nodeRdn, childNode );
+            
+            return childNode;
         }
         else
         {
@@ -597,15 +601,19 @@ public class DnNode<N> implements Clonea
                 else
                 {
                     parentNode.setElement( element );
+                    
+                    return parentNode;
                 }
             }
             else
             {
-                DnNode<N> rootNode = createNode( dn, element, nbRdns );
+                DnNode<N> childNode = createNode( dn, element, nbRdns );
 
                 // done. now, add the newly created tree to the parent node
-                rootNode.parent = parentNode;
-                parentNode.children.put( rootNode.nodeRdn, rootNode );
+                childNode.parent = parentNode;
+                parentNode.children.put( childNode.nodeRdn, childNode );
+
+                return childNode;
             }
         }
     }