org.apache.directory.shared.ldap.util.tree
Class DnBranchNode<N>

java.lang.Object
  extended by org.apache.directory.shared.ldap.util.tree.DnBranchNode<N>
All Implemented Interfaces:
DnNode<N>

public class DnBranchNode<N>
extends java.lang.Object
implements DnNode<N>

The Hierarchical Container holds elements ordered by their DN.
We can see them as directories, where the leaves are the files.
This class is *not* thread safe

Author:
Apache Directory Project

Constructor Summary
DnBranchNode()
          Creates a new instance of a DnBranchNode.
 
Method Summary
 void add(DN dn, N element)
          TODO add.
 DnNode<N> addNode(java.lang.String rdn, DnNode<N> child)
          Directly adds a new child DnNode to the current DnBranchNode.
 boolean contains(java.lang.String rdn)
          Tells if the current DnBranchNode contains another node associated with an rdn.
 DnNode<N> getChild(java.lang.String rdn)
          Get's a child using an rdn string.
 N getParentElement(DN dn)
          Get the parent of a given DN, if present in the tree.
 boolean hasChildren()
          Tells if a branchNode has some children or not
 boolean hasParentElement(DN dn)
          Tells if the DN contains a parent in the tree.
 boolean isLeaf()
          Tells if the implementation is a leaf node.
 void remove(N element)
          Removes an element from the tree.
 int size()
          Returns the number of entries under this node.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DnBranchNode

public DnBranchNode()
Creates a new instance of a DnBranchNode.

Method Detail

isLeaf

public boolean isLeaf()
Description copied from interface: DnNode
Tells if the implementation is a leaf node. If it's a branch node then false is returned.

Specified by:
isLeaf in interface DnNode<N>
Returns:
true if the class is a leaf node, false otherwise.
See Also:
DnNode.isLeaf()

addNode

public DnNode<N> addNode(java.lang.String rdn,
                         DnNode<N> child)
Directly adds a new child DnNode to the current DnBranchNode.

Parameters:
rdn - The rdn of the child node to add
child - The child node to add
Returns:
The modified branch node after the insertion

contains

public boolean contains(java.lang.String rdn)
Tells if the current DnBranchNode contains another node associated with an rdn.

Parameters:
rdn - The name we are looking for
Returns:
true if the tree instance contains this name

getChild

public DnNode<N> getChild(java.lang.String rdn)
Get's a child using an rdn string.

Parameters:
rdn - the rdn to use as the node key
Returns:
the child node corresponding to the rdn.

getParentElement

public N getParentElement(DN dn)
Get the parent of a given DN, if present in the tree. This parent should be a subset of the given dn.
For instance, if we have stored dc=acme, dc=org into the tree, the DN: ou=example, dc=acme, dc=org will have a parent, and dc=acme, dc=org will be returned.
For the DN ou=apache, dc=org, there is no parent, so null will be returned.

Parameters:
dn - the normalized distinguished name to resolve to a parent
Returns:
the parent associated with the normalized dn

hasParentElement

public boolean hasParentElement(DN dn)
Tells if the DN contains a parent in the tree. This parent should be a subset of the given dn.
For instance, if we have stored dc=acme, dc=org into the tree, the DN: ou=example, dc=acme, dc=org will have a parent.

Parameters:
dn - the normalized distinguished name to resolve to a parent
Returns:
the parent associated with the normalized dn

hasChildren

public boolean hasChildren()
Tells if a branchNode has some children or not

Returns:
true if the node has some children

add

public void add(DN dn,
                N element)
         throws LdapException
TODO add.

Parameters:
dn -
element -
Throws:
NamingException
LdapException

remove

public void remove(N element)
Removes an element from the tree.

Parameters:
element - The element to remove

size

public int size()
Returns the number of entries under this node. It includes the node itself, plus the sum of all it children and descendents.

Specified by:
size in interface DnNode<N>
Returns:
The number of descendents

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.