directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r926442 - 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 Tue, 23 Mar 2010 02:48:04 GMT
Author: elecharny
Date: Tue Mar 23 02:48:04 2010
New Revision: 926442

URL: http://svn.apache.org/viewvc?rev=926442&view=rev
Log:
o DN now implements Serializable, Comparator and Iterable
o Added some tests for the iterator

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=926442&r1=926441&r2=926442&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
Tue Mar 23 02:48:04 2010
@@ -25,8 +25,10 @@ import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
@@ -64,7 +66,7 @@ import org.slf4j.LoggerFactory;
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class DN implements Externalizable, Cloneable
+public class DN implements Cloneable, Serializable, Comparable<DN>, Iterable<RDN>
 {
     /** The LoggerFactory used by this class */
     protected static final Logger LOG = LoggerFactory.getLogger( DN.class );
@@ -1319,35 +1321,26 @@ public class DN implements Externalizabl
     /**
      * {@inheritDoc}
      */
-    public int compareTo( Object obj )
+    public int compareTo( DN dn )
     {
-        if ( obj instanceof DN )
+        if ( dn.size() != size() )
         {
-            DN dn = ( DN ) obj;
+            return size() - dn.size();
+        }
 
-            if ( dn.size() != size() )
-            {
-                return size() - dn.size();
-            }
+        for ( int i = rdns.size(); i > 0; i-- )
+        {
+            RDN rdn1 = rdns.get( i - 1 );
+            RDN rdn2 = dn.rdns.get( i - 1 );
+            int res = rdn1.compareTo( rdn2 );
 
-            for ( int i = rdns.size(); i > 0; i-- )
+            if ( res != 0 )
             {
-                RDN rdn1 = rdns.get( i - 1 );
-                RDN rdn2 = dn.rdns.get( i - 1 );
-                int res = rdn1.compareTo( rdn2 );
-
-                if ( res != 0 )
-                {
-                    return res;
-                }
+                return res;
             }
-
-            return EQUAL;
-        }
-        else
-        {
-            return 1;
         }
+
+        return EQUAL;
     }
 
 
@@ -1698,4 +1691,13 @@ public class DN implements Externalizabl
             return null;
         }
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Iterator<RDN> iterator()
+    {
+        return rdns.iterator();
+    }
 }

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=926442&r1=926441&r2=926442&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
Tue Mar 23 02:48:04 2010
@@ -50,7 +50,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 
@@ -3665,4 +3664,55 @@ public class DNTest
             assertEquals( "t+st", ava.getNormValue().get() );
         }
     }
+    
+    
+    //-------------------------------------------------------------------------
+    // test the iterator
+    //-------------------------------------------------------------------------
+    @Test
+    public void testIteratorNullDN()
+    {
+        DN dn = DN.EMPTY_DN;
+        
+        for ( RDN rdn : dn )
+        {
+            fail( "Should not be there" );
+        }
+        
+        assertTrue( true );
+    }
+    
+    
+    @Test
+    public void testIteratorOneRDN() throws Exception
+    {
+        DN dn = new DN( "ou=example" );
+        int count = 0;
+        
+        for ( RDN rdn : dn )
+        {
+            count++;
+            assertEquals( "ou=example", rdn.getName() );
+        }
+        
+        assertEquals( 1, count );
+    }
+    
+    
+    @Test
+    public void testIteratorMultipleRDN() throws Exception
+    {
+        DN dn = new DN( "sn=joe+cn=doe,dc=apache,dc=org" );
+        int count = 0;
+        
+        String[] expected = new String[]{ "sn=joe+cn=doe", "dc=apache", "dc=org" };
+        
+        for ( RDN rdn : dn )
+        {
+            assertEquals( expected[count], rdn.getName() );
+            count++;
+        }
+        
+        assertEquals( 3, count );
+    }
 }



Mime
View raw message