directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r927075 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/name/DN.java test/java/org/apache/directory/shared/ldap/name/DNTest.java
Date Wed, 24 Mar 2010 14:37:27 GMT
Author: elecharny
Date: Wed Mar 24 14:37:26 2010
New Revision: 927075

URL: http://svn.apache.org/viewvc?rev=927075&view=rev
Log:
o Added the isChildOf(String) and isParentOf(String) methods
o Renamed the endsWith to hasSuffix

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java?rev=927075&r1=927074&r2=927075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
Wed Mar 24 14:37:26 2010
@@ -596,6 +596,27 @@ public class DN implements Cloneable, Se
      * @param dn The child
      * @return true if the given DN is a child of the current DN 
      */
+    public boolean isParentOf( String dn )
+    {
+        try
+        {
+            return isParentOf( new DN( dn ) );
+        }
+        catch( LdapInvalidDnException lide )
+        {
+            return false;
+        }
+    }
+    
+
+    /**
+     * Tells if the current DN is a parent of another DN.<br>
+     * For instance, <b>dc=com</b> is a child
+     * of <b>dc=example, dc=com</b>
+     * 
+     * @param dn The child
+     * @return true if the given DN is a child of the current DN 
+     */
     public boolean isParentOf( DN dn )
     {
         if ( dn == null )
@@ -615,6 +636,27 @@ public class DN implements Cloneable, Se
      * @param dn The parent
      * @return true if the given DN is a parent of the current DN 
      */
+    public boolean isChildOf( String dn )
+    {
+        try
+        {
+            return isChildOf( new DN( dn ) );
+        }
+        catch( LdapInvalidDnException lide )
+        {
+            return false;
+        }
+    }
+    
+
+    /**
+     * Tells if a DN is a child of another DN.<br>
+     * For instance, <b>dc=example, dc=com</b> is a child
+     * of <b>dc=com</b>
+     * 
+     * @param dn The parent
+     * @return true if the given DN is a parent of the current DN 
+     */
     public boolean isChildOf( DN dn )
     {
         if ( dn == null )
@@ -652,17 +694,17 @@ public class DN implements Cloneable, Se
 
 
     /**
-     * Determines whether this name is a child of a specified suffix. A name
-     * <tt>name</tt> is a child if its right part contains the given DN
+     * Determines whether this name has a specific suffix. A name
+     * <tt>name</tt> has a DN as a suffix if its right part contains the given
DN
      *
      * Be aware that for a specific
-     * DN like : <b>cn=xxx, ou=yyy</b> the isChildOf method will return true
with
-     * <b>ou=yyy</b>, and false with <b>cn=xxx</b>
+     * DN like : <b>cn=xxx, ou=yyy</b> the hasSuffix method will return false
with
+     * <b>ou=yyy</b>, and true with <b>cn=xxx</b>
      *
      * @param dn the name to check
-     * @return true if <tt>dn</tt> is a child of this name, false otherwise
+     * @return true if <tt>dn</tt> is a suffix of this name, false otherwise
      */
-    public boolean endsWith( DN dn )
+    public boolean hasSuffix( DN dn )
     {
 
         if ( dn == null )

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java?rev=927075&r1=927074&r2=927075&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/DNTest.java
Wed Mar 24 14:37:26 2010
@@ -1107,7 +1107,7 @@ public class DNTest
     public void testDnStartsWithNull() throws LdapException
     {
         DN dn = new DN( "a=b, c=d,e = f" );
-        assertEquals( true, dn.isChildOf( null ) );
+        assertEquals( true, dn.isChildOf( (DN)null ) );
     }
 
 
@@ -1185,7 +1185,7 @@ public class DNTest
     public void testDnEndsWithNull() throws LdapException
     {
         DN dn = new DN( "a=b, c=d,e = f" );
-        assertEquals( true, dn.endsWith( (DN)null ) );
+        assertEquals( true, dn.hasSuffix( (DN)null ) );
     }
 
 
@@ -1196,7 +1196,7 @@ public class DNTest
     public void testDnEndsWithEmpty() throws LdapException
     {
         DN dn = new DN( "a=b, c=d,e = f" );
-        assertEquals( true, dn.endsWith( new DN() ) );
+        assertEquals( true, dn.hasSuffix( new DN() ) );
     }
 
 
@@ -1207,7 +1207,7 @@ public class DNTest
     public void testDnEndsWithSimple() throws LdapException
     {
         DN dn = new DN( "a=b, c=d,e = f" );
-        assertEquals( true, dn.endsWith( new DN( "a=b" ) ) );
+        assertEquals( true, dn.hasSuffix( new DN( "a=b" ) ) );
     }
 
 
@@ -1218,7 +1218,7 @@ public class DNTest
     public void testDnEndsWithComplex() throws LdapException
     {
         DN dn = new DN( "a=b, c=d,e = f" );
-        assertEquals( true, dn.endsWith( new DN( "a =  b, c =  d" ) ) );
+        assertEquals( true, dn.hasSuffix( new DN( "a =  b, c =  d" ) ) );
     }
 
 
@@ -1229,7 +1229,7 @@ public class DNTest
     public void testDnEndsWithComplexMixedCase() throws LdapException
     {
         DN dn = new DN( "a=b, c=d,e = f" );
-        assertEquals( false, dn.endsWith( new DN( "a =  B, C =  d" ) ) );
+        assertEquals( false, dn.hasSuffix( new DN( "a =  B, C =  d" ) ) );
     }
 
 
@@ -1240,7 +1240,7 @@ public class DNTest
     public void testDnEndsWithFull() throws LdapException
     {
         DN dn = new DN( "a=b, c=d,e = f" );
-        assertEquals( true, dn.endsWith( new DN( "a=  b; c =  d, e =  f" ) ) );
+        assertEquals( true, dn.hasSuffix( new DN( "a=  b; c =  d, e =  f" ) ) );
     }
 
 
@@ -1251,7 +1251,7 @@ public class DNTest
     public void testDnEndsWithWrong() throws LdapException
     {
         DN dn = new DN( "a=b, c=d,e = f" );
-        assertEquals( false, dn.endsWith( new DN( "a =  b, e =  f" ) ) );
+        assertEquals( false, dn.hasSuffix( new DN( "a =  b, e =  f" ) ) );
     }
 
 
@@ -2111,15 +2111,15 @@ public class DNTest
         DN name7 = new DN( "cn=HomeDir,cn=John" );
         DN name8 = new DN( "cn=HomeDir,cn=John,ou=Marketing" );
 
-        assertTrue( name0.endsWith( name1 ) );
-        assertTrue( !name0.endsWith( name2 ) );
-        assertTrue( !name0.endsWith( name3 ) );
-        assertTrue( !name0.endsWith( name4 ) );
-        assertTrue( name0.endsWith( name5 ) );
-
-        assertTrue( name0.endsWith( name6 ) );
-        assertTrue( name0.endsWith( name7 ) );
-        assertTrue( name0.endsWith( name8 ) );
+        assertTrue( name0.hasSuffix( name1 ) );
+        assertTrue( !name0.hasSuffix( name2 ) );
+        assertTrue( !name0.hasSuffix( name3 ) );
+        assertTrue( !name0.hasSuffix( name4 ) );
+        assertTrue( name0.hasSuffix( name5 ) );
+
+        assertTrue( name0.hasSuffix( name6 ) );
+        assertTrue( name0.hasSuffix( name7 ) );
+        assertTrue( name0.hasSuffix( name8 ) );
     }
 
 
@@ -2693,19 +2693,19 @@ public class DNTest
         DN n2 =  new DN( "cn=two" );
         DN n1 =  new DN( "cn=one" );
         
-        assertTrue( n3210.endsWith( n3 ) );
-        assertTrue( n3210.endsWith( n32 ) );
-        assertTrue( n3210.endsWith( n321 ) );
-        assertTrue( n3210.endsWith( n3210 ) );
-
-        assertTrue( n210.endsWith( n2 ) );
-        assertTrue( n210.endsWith( n21 ) );
-        assertTrue( n210.endsWith( n210 ) );
+        assertTrue( n3210.hasSuffix( n3 ) );
+        assertTrue( n3210.hasSuffix( n32 ) );
+        assertTrue( n3210.hasSuffix( n321 ) );
+        assertTrue( n3210.hasSuffix( n3210 ) );
+
+        assertTrue( n210.hasSuffix( n2 ) );
+        assertTrue( n210.hasSuffix( n21 ) );
+        assertTrue( n210.hasSuffix( n210 ) );
 
-        assertTrue( n10.endsWith( n1 ) );
-        assertTrue( n10.endsWith( n10 ) );
+        assertTrue( n10.hasSuffix( n1 ) );
+        assertTrue( n10.hasSuffix( n10 ) );
 
-        assertTrue( n0.endsWith( n0 ) );
+        assertTrue( n0.hasSuffix( n0 ) );
     }
 
 



Mime
View raw message