@Test public void testHasParentElement() throws Exception { DnNode<Dn> dnLookupTree = new DnNode<Dn>(); Dn dn1 = new Dn( "dc=directory,dc=apache,dc=org" ); Dn dn2 = new Dn( "dc=mina,dc=apache,dc=org" ); Dn dn3 = new Dn( "dc=test,dc=com" ); Dn dn4 = new Dn( "dc=acme,dc=com" ); Dn dn5 = new Dn( "dc=acme,c=us,dc=com" ); Dn dn6 = new Dn( "dc=empty" ); Dn org = new Dn( "dc=org" ); dnLookupTree.add( dn1, dn1 ); dnLookupTree.add( dn2, dn2 ); dnLookupTree.add( dn3, dn3 ); dnLookupTree.add( dn4, dn4 ); dnLookupTree.add( dn5 ); dnLookupTree.add( dn6, dn6 ); dnLookupTree.add( org, org ); assertTrue( dnLookupTree.hasParentElement( new Dn( "dc=apache,dc=org" ) ) ); assertTrue( dnLookupTree.hasDescendantElement( org ) ); assertFalse( dnLookupTree.hasDescendantElement( new Dn( "c=us,dc=com" ) ) ); Dn dn7 = new Dn( "dc=elem,dc=mina,dc=apache,dc=org" ); dnLookupTree.add( dn7, dn7 ); List<Dn> dns = dnLookupTree.getDescendantElements( org ); assertNotNull( dns ); assertEquals( 2, dns.size() ); assertTrue( dns.contains( dn1 ) ); assertTrue( dns.contains( dn2 ) ); dns = dnLookupTree.getDescendantElements( dn6 ); assertEquals( 0, dns.size() ); }
public synchronized boolean hasParentElement( Dn dn ) { List<Rdn> rdns = dn.getRdns(); DnNode<N> currentNode = this; boolean hasElement = false; for ( int i = rdns.size() - 1; i >= 0; i-- ) { Rdn rdn = rdns.get( i ); if ( currentNode.hasChildren() ) { currentNode = currentNode.children.get( rdn.getNormName() ); if ( currentNode == null ) { break; } if ( currentNode.hasElement() ) { hasElement = true; } parent = currentNode; } else { break; } } return hasElement; }
DnNode { public synchronized boolean hasParentElement( Dn dn ) { List<Rdn> rdns = dn.getRdns(); DnNode<N> currentNode = this; boolean hasElement = false; for ( int i = rdns.size() - 1; i >= 0; i-- ) { Rdn rdn = rdns.get( i ); if ( currentNode.hasChildren() ) { currentNode = currentNode.children.get( rdn.getNormName() ); if ( currentNode == null ) { break; } if ( currentNode.hasElement() ) { hasElement = true; } parent = currentNode; } else { break; } } return hasElement; } }
DnNode { public synchronized boolean hasParentElement( Dn dn ) { List<Rdn> rdns = dn.getRdns(); DnNode<N> currentNode = this; boolean hasElement = false; for ( int i = rdns.size() - 1; i >= 0; i-- ) { Rdn rdn = rdns.get( i ); if ( currentNode.hasChildren() ) { currentNode = currentNode.children.get( rdn.getNormName() ); if ( currentNode == null ) { break; } if ( currentNode.hasElement() ) { hasElement = true; } parent = currentNode; } else { break; } } return hasElement; } DnNode();  DnNode( N element );  DnNode( Dn dn, N element ); }
DnNode { public synchronized boolean hasParentElement( Dn dn ) { List<Rdn> rdns = dn.getRdns(); DnNode<N> currentNode = this; boolean hasElement = false; for ( int i = rdns.size() - 1; i >= 0; i-- ) { Rdn rdn = rdns.get( i ); if ( currentNode.hasChildren() ) { currentNode = currentNode.children.get( rdn.getNormName() ); if ( currentNode == null ) { break; } if ( currentNode.hasElement() ) { hasElement = true; } parent = currentNode; } else { break; } } return hasElement; } DnNode();  DnNode( N element );  DnNode( Dn dn, N element ); synchronized boolean isLeaf(); synchronized boolean isLeaf( Dn dn ); synchronized int size(); synchronized N getElement(); synchronized N getElement( Dn dn ); synchronized boolean hasElement(); synchronized boolean hasElement( Dn dn ); synchronized boolean hasDescendantElement( Dn dn ); synchronized List<N> getDescendantElements( Dn dn ); synchronized boolean hasChildren(); synchronized boolean hasChildren( Dn dn ); synchronized Map<String, DnNode<N>> getChildren(); synchronized DnNode<N> getParent(); synchronized boolean hasParent(); synchronized boolean hasParent( Dn dn ); synchronized DnNode<N> add( Dn dn ); synchronized DnNode<N> add( Dn dn, N element ); synchronized void remove( Dn dn ); synchronized boolean contains( Rdn rdn ); synchronized DnNode<N> getChild( Rdn rdn ); synchronized Rdn getRdn(); synchronized DnNode<N> getNode( Dn dn ); synchronized boolean hasParentElement( Dn dn ); synchronized DnNode<N> getParentWithElement( Dn dn ); synchronized DnNode<N> getParentWithElement(); synchronized void rename( Rdn newRdn ); synchronized void move( Dn newParent ); @Override String toString(); synchronized Dn getDn(); }
DnNode { public synchronized boolean hasParentElement( Dn dn ) { List<Rdn> rdns = dn.getRdns(); DnNode<N> currentNode = this; boolean hasElement = false; for ( int i = rdns.size() - 1; i >= 0; i-- ) { Rdn rdn = rdns.get( i ); if ( currentNode.hasChildren() ) { currentNode = currentNode.children.get( rdn.getNormName() ); if ( currentNode == null ) { break; } if ( currentNode.hasElement() ) { hasElement = true; } parent = currentNode; } else { break; } } return hasElement; } DnNode();  DnNode( N element );  DnNode( Dn dn, N element ); synchronized boolean isLeaf(); synchronized boolean isLeaf( Dn dn ); synchronized int size(); synchronized N getElement(); synchronized N getElement( Dn dn ); synchronized boolean hasElement(); synchronized boolean hasElement( Dn dn ); synchronized boolean hasDescendantElement( Dn dn ); synchronized List<N> getDescendantElements( Dn dn ); synchronized boolean hasChildren(); synchronized boolean hasChildren( Dn dn ); synchronized Map<String, DnNode<N>> getChildren(); synchronized DnNode<N> getParent(); synchronized boolean hasParent(); synchronized boolean hasParent( Dn dn ); synchronized DnNode<N> add( Dn dn ); synchronized DnNode<N> add( Dn dn, N element ); synchronized void remove( Dn dn ); synchronized boolean contains( Rdn rdn ); synchronized DnNode<N> getChild( Rdn rdn ); synchronized Rdn getRdn(); synchronized DnNode<N> getNode( Dn dn ); synchronized boolean hasParentElement( Dn dn ); synchronized DnNode<N> getParentWithElement( Dn dn ); synchronized DnNode<N> getParentWithElement(); synchronized void rename( Rdn newRdn ); synchronized void move( Dn newParent ); @Override String toString(); synchronized Dn getDn();  }