directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1235258 [8/8] - in /directory/apacheds/trunk: core-annotations/src/main/java/org/apache/directory/server/core/annotations/ core-annotations/src/main/java/org/apache/directory/server/core/factory/ core-annotations/src/test/java/org/apache/d...
Date Tue, 24 Jan 2012 14:11:01 GMT
Modified: directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java?rev=1235258&r1=1235257&r2=1235258&view=diff
==============================================================================
--- directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java (original)
+++ directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java Tue Jan 24 14:10:56 2012
@@ -19,7 +19,7 @@
  */
 package org.apache.directory.server.core.avltree;
 
- 
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -53,56 +53,57 @@ import org.slf4j.LoggerFactory;
 public class AvlTreeMarshallerTest
 {
     private static final long[] AVLTREE_KEYS_PRE_REMOVE =
-    {
-        2, 14, 26, 86, 110, 122, 134, 182
+        {
+            2, 14, 26, 86, 110, 122, 134, 182
     };
-        
+
     private static final long[] AVLTREE_EXPECTED_KEYS_POST_REMOVE =
-    {
-        2, 14, 26, 86, 122, 134, 182
+        {
+            2, 14, 26, 86, 122, 134, 182
     };
-        
+
     private static final byte[] SERIALIZED_AVLTREE_PRE_REMOVE =
-    {
-        0, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 
-        110, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 
-        0, 0, 0, 0, 26, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 
-        8, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 
-        0, 0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 
-        14, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-        4, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 86, 0, 0, 0, 
-        3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 
-        8, 0, 0, 0, 0, 0, 0, 0, -122, 0, 0, 0, 6, 0, 0, 0, 
-        2, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 122, 0, 0, 0, 
-        5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 
-        8, 0, 0, 0, 0, 0, 0, 0, -74, 0, 0, 0, 7, 0, 0, 0, 
-        0, 0, 0, 0, 0 
+        {
+            0, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0,
+            110, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0,
+            0, 0, 0, 0, 26, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0,
+            8, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0,
+            14, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+            4, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 86, 0, 0, 0,
+            3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0,
+            8, 0, 0, 0, 0, 0, 0, 0, -122, 0, 0, 0, 6, 0, 0, 0,
+            2, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 122, 0, 0, 0,
+            5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0,
+            8, 0, 0, 0, 0, 0, 0, 0, -74, 0, 0, 0, 7, 0, 0, 0,
+            0, 0, 0, 0, 0
     };
-    
-//    private static final byte[] SERIALIZED_AVLTREE_POST_REMOVE = 
-//    { 
-//        0, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 
-//        86, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 
-//        0, 0, 0, 0, 26, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 
-//        0, 0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, -122, 
-//        0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 0, 
-//        0, 0, 0, 122, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 
-//        0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, -74, 
-//        0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0 
-//    };
-   
+
+    //    private static final byte[] SERIALIZED_AVLTREE_POST_REMOVE = 
+    //    { 
+    //        0, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 
+    //        86, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 
+    //        0, 0, 0, 0, 26, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 
+    //        0, 0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, -122, 
+    //        0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 0, 
+    //        0, 0, 0, 122, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 
+    //        0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, -74, 
+    //        0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0 
+    //    };
+
     static AvlTree<Integer> savedTree;
-    
-    static File treeFile = new File( System.getProperty( "java.io.tmpdir" ) + File.separator + "avl.tree");
-    
+
+    static File treeFile = new File( System.getProperty( "java.io.tmpdir" ) + File.separator + "avl.tree" );
+
     private static Comparator<Integer> comparator;
-    
+
     private static final Logger LOG = LoggerFactory.getLogger( AvlTreeMarshallerTest.class.getSimpleName() );
 
+
     @BeforeClass
     public static void createComparator()
     {
-        comparator = new Comparator<Integer>() 
+        comparator = new Comparator<Integer>()
         {
             public int compare( Integer i1, Integer i2 )
             {
@@ -110,29 +111,31 @@ public class AvlTreeMarshallerTest
             }
         };
     }
+
+
     private AvlTree<Integer> createTree()
     {
         return new AvlTreeImpl<Integer>( comparator );
     }
 
-    
+
     private AvlTreeMarshaller<Integer> createTreeMarshaller()
     {
         return new AvlTreeMarshaller<Integer>( comparator, new IntegerKeyMarshaller() );
     }
 
-    
+
     @AfterClass
     public static void deleteFiles()
     {
         treeFile.delete();
     }
-    
-    
+
+
     @Test
     public void testRemoveBug() throws IOException
     {
-        Comparator<Long> comparator = new Comparator<Long>() 
+        Comparator<Long> comparator = new Comparator<Long>()
         {
             public int compare( Long i1, Long i2 )
             {
@@ -148,17 +151,17 @@ public class AvlTreeMarshallerTest
 
         AvlTreeMarshaller<Long> treeMarshaller = new AvlTreeMarshaller<Long>( comparator, new LongMarshaller() );
         AvlTree<Long> tree = treeMarshaller.deserialize( SERIALIZED_AVLTREE_PRE_REMOVE );
-        
+
         for ( long key : AVLTREE_KEYS_PRE_REMOVE )
         {
             assertNotNull( "Should find " + key, tree.find( key ) );
         }
-        
+
         /*
          * Now we remove the key 110 and this should show that we don't have 
          * the expected keys.  We will be missing 134, 2 and 14.
          */
-        
+
         tree.remove( 110L );
 
         for ( long key : AVLTREE_EXPECTED_KEYS_POST_REMOVE )
@@ -166,7 +169,7 @@ public class AvlTreeMarshallerTest
             assertNotNull( "Should find " + key, tree.find( key ) );
         }
     }
-    
+
 
     @Test
     public void testMarshalEmptyTree() throws IOException
@@ -339,7 +342,8 @@ public class AvlTreeMarshallerTest
     @Test
     public void testRoundTripManyEntriesDefaultSerialization() throws Exception
     {
-        Comparator<Bar> barComparator = new Comparator<Bar>() {
+        Comparator<Bar> barComparator = new Comparator<Bar>()
+        {
             public int compare( Bar o1, Bar o2 )
             {
                 return o1.intValue.compareTo( o2.intValue );
@@ -368,7 +372,6 @@ public class AvlTreeMarshallerTest
         }
     }
 
-
     static class Bar implements Serializable
     {
         private static final long serialVersionUID = -6304421912253987925L;
@@ -385,7 +388,6 @@ public class AvlTreeMarshallerTest
         }
     }
 
-
     static class Foo implements Serializable
     {
         private static final long serialVersionUID = 2036800942831561377L;
@@ -413,66 +415,65 @@ public class AvlTreeMarshallerTest
         FileOutputStream fout = new FileOutputStream( treeFile );
         fout.write( treeMarshaller.serialize( tree ) );
         fout.close();
-        
+
         savedTree = tree; // to reference in other tests
-        
-        if( LOG.isDebugEnabled() )
+
+        if ( LOG.isDebugEnabled() )
         {
-            LOG.debug("saved tree\n--------");
+            LOG.debug( "saved tree\n--------" );
             tree.printTree();
         }
-        
+
         assertTrue( true );
 
         // UnMarshall
-        FileInputStream fin = new FileInputStream(treeFile);
-        
-        byte[] data = new byte[ ( int )treeFile.length() ];
+        FileInputStream fin = new FileInputStream( treeFile );
+
+        byte[] data = new byte[( int ) treeFile.length()];
         fin.read( data );
-        
+
         AvlTree<Integer> unmarshalledTree = treeMarshaller.deserialize( data );
-        
-        if( LOG.isDebugEnabled() )
+
+        if ( LOG.isDebugEnabled() )
         {
-            LOG.debug("\nunmarshalled tree\n---------------");
+            LOG.debug( "\nunmarshalled tree\n---------------" );
             unmarshalledTree.printTree();
         }
-        
+
         assertTrue( savedTree.getRoot().getKey() == unmarshalledTree.getRoot().getKey() );
 
         unmarshalledTree.insert( 6 ); // will change the root as part of balancing
-        
+
         assertTrue( savedTree.getRoot().getKey() == unmarshalledTree.getRoot().getKey() );
         assertTrue( 8 == unmarshalledTree.getRoot().getKey() ); // new root
-        
+
         assertTrue( 37 == unmarshalledTree.getLast().getKey() );
         unmarshalledTree.insert( 99 );
         assertTrue( 99 == unmarshalledTree.getLast().getKey() );
 
         assertTrue( 6 == unmarshalledTree.getFirst().getKey() );
-        
+
         unmarshalledTree.insert( 0 );
         assertTrue( 0 == unmarshalledTree.getFirst().getKey() );
-        
-        if( LOG.isDebugEnabled() )
+
+        if ( LOG.isDebugEnabled() )
         {
-            LOG.debug("\nmodified tree after unmarshalling\n---------------");
+            LOG.debug( "\nmodified tree after unmarshalling\n---------------" );
             unmarshalledTree.printTree();
         }
-        
-        assertNotNull(unmarshalledTree.getFirst());
-        assertNotNull(unmarshalledTree.getLast());
-    }
-    
-    
-    @Test( expected = IOException.class )
+
+        assertNotNull( unmarshalledTree.getFirst() );
+        assertNotNull( unmarshalledTree.getLast() );
+    }
+
+
+    @Test(expected = IOException.class)
     public void testDeserializeNullData() throws IOException
     {
         AvlTreeMarshaller<Integer> treeMarshaller = createTreeMarshaller();
         treeMarshaller.deserialize( null );
     }
-    
-    
+
     public class LongMarshaller implements Marshaller<Long>
     {
         public byte[] serialize( Long obj ) throws IOException
@@ -496,7 +497,7 @@ public class AvlTreeMarshallerTest
         public Long deserialize( byte[] bites ) throws IOException
         {
             long id;
-            id = bites[0]  + ( ( bites[0] < 0 ) ? 256 : 0 );
+            id = bites[0] + ( ( bites[0] < 0 ) ? 256 : 0 );
             id <<= 8;
             id += bites[1] + ( ( bites[1] < 0 ) ? 256 : 0 );
             id <<= 8;

Modified: directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreePerfTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreePerfTest.java?rev=1235258&r1=1235257&r2=1235258&view=diff
==============================================================================
--- directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreePerfTest.java (original)
+++ directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreePerfTest.java Tue Jan 24 14:10:56 2012
@@ -46,285 +46,288 @@ import org.slf4j.LoggerFactory;
 public class AvlTreePerfTest
 {
     AvlTree<Integer> tree;
-    
+
     static String tempDir = System.getProperty( "java.io.tmpdir" );
-   
+
     static File setSerialFile = new File( tempDir + File.separator + "hashset.ser" );
     static File treeSerialFile = new File( tempDir + File.separator + "avltree.ser" );
-    
+
     Set<Integer> set;
-    
+
     long start, end;
 
     int numKeys = 1000000;
 
-    Comparator<Integer> comparator = new Comparator<Integer>() 
+    Comparator<Integer> comparator = new Comparator<Integer>()
     {
-      public int compare( Integer i1, Integer i2 )
-      {
-          return i1.compareTo( i2 );
-      }
-    
+        public int compare( Integer i1, Integer i2 )
+        {
+            return i1.compareTo( i2 );
+        }
+
     };
-    
+
     AvlTreeMarshaller<Integer> treeMarshaller = new AvlTreeMarshaller<Integer>( comparator, new IntegerKeyMarshaller() );
 
     private final static Logger LOG = LoggerFactory.getLogger( AvlTreePerfTest.class );
-    
+
+
     @Before
     public void createTree()
     {
-      tree = new AvlTreeImpl<Integer>( new Comparator<Integer>() 
-          {
+        tree = new AvlTreeImpl<Integer>( new Comparator<Integer>()
+        {
 
             public int compare( Integer i1, Integer i2 )
             {
                 return i1.compareTo( i2 );
             }
-          
-          });  
-      
-      set = new HashSet<Integer>();
-      
-      start = end = 0;
+
+        } );
+
+        set = new HashSet<Integer>();
+
+        start = end = 0;
     }
-    
-    
+
+
     @AfterClass
     public static void deleteFiles()
     {
         setSerialFile.delete();
         treeSerialFile.delete();
     }
-    
-    
+
+
     @Test
     public void testRBTreeInsertPerf()
     {
         start = System.nanoTime();
-        
-        for( int i=0; i < numKeys; i++ )
+
+        for ( int i = 0; i < numKeys; i++ )
         {
             set.add( i );
         }
-        
+
         end = System.nanoTime();
-     
-        System.out.println( "total time for inserting " + numKeys + " items into the RBTree-->" +  getTime( start, end ) );
-        
+
+        System.out
+            .println( "total time for inserting " + numKeys + " items into the RBTree-->" + getTime( start, end ) );
+
     }
 
-    
+
     @Test
     @Ignore
     public void testRBTreeLookupPerf()
     {
-        for( int i=0; i < numKeys; i++ )
+        for ( int i = 0; i < numKeys; i++ )
         {
             set.add( i );
         }
-        
+
         start = System.nanoTime();
-       
+
         set.contains( 70 );
         set.contains( -1000 );
         set.contains( 10 );
         set.contains( 90 );
         set.contains( 9999 );
-        
-       end = System.nanoTime();
-       
-       System.out.println( "total time took to read an item from set " + getTime( start, end ) ) ;
+
+        end = System.nanoTime();
+
+        System.out.println( "total time took to read an item from set " + getTime( start, end ) );
     }
-    
-    
+
+
     @Test
     @Ignore
     public void testRemoveFromRBTree()
     {
-        for( int i=0; i < numKeys; i++ )
+        for ( int i = 0; i < numKeys; i++ )
         {
             set.add( i );
         }
-        
+
         start = System.nanoTime();
-        
+
         set.remove( 90 );
         set.remove( 912 );
         set.remove( -1 );
         set.remove( 192 );
-        
+
         end = System.nanoTime();
-        
-        System.out.println( "total time took to remove an item from set " + getTime( start, end ) ) ;
+
+        System.out.println( "total time took to remove an item from set " + getTime( start, end ) );
 
     }
-    
-    
+
+
     @Test
     public void testAvlTreeInsertPerf()
     {
         start = System.nanoTime();
-        
-        for( int i=0; i < numKeys; i++ )
+
+        for ( int i = 0; i < numKeys; i++ )
         {
             tree.insert( i );
         }
 
         end = System.nanoTime();
-        
-        System.out.println("total time for inserting " + numKeys + " items into the AVLTree-->" + getTime(start, end));
+
+        System.out
+            .println( "total time for inserting " + numKeys + " items into the AVLTree-->" + getTime( start, end ) );
     }
-    
-    
+
+
     @Test
     @Ignore
     public void testAVLTreeLookupPerf()
     {
-        
-        for( int i=0; i < numKeys; i++ )
+
+        for ( int i = 0; i < numKeys; i++ )
         {
             tree.insert( i );
         }
-        
+
         start = System.nanoTime();
-        
+
         tree.find( 70 );
         tree.find( -1000 );
         tree.find( 10 );
         tree.find( 90 );
         tree.find( 9999 );
-        
+
         end = System.nanoTime();
-        
-        System.out.println("total time took to read an item from tree " + getTime( start, end ) ) ;
+
+        System.out.println( "total time took to read an item from tree " + getTime( start, end ) );
     }
-    
-    
+
+
     @Test
     @Ignore
     public void testAVLTreeRemovePerf()
     {
-        for( int i=0; i < numKeys; i++ )
+        for ( int i = 0; i < numKeys; i++ )
         {
             tree.insert( i );
         }
-        
+
         start = System.nanoTime();
-        
+
         tree.remove( 90 );
         tree.remove( 912 );
         tree.remove( -1 );
         tree.remove( 192 );
-        
+
         end = System.nanoTime();
-        
-        System.out.println("total time took to remove an item from AVLTree " + getTime( start, end ) ) ;
+
+        System.out.println( "total time took to remove an item from AVLTree " + getTime( start, end ) );
 
     }
-    
-    
+
+
     @Test
     @Ignore
     public void testRBTreeSerializationPerf() throws Exception
     {
         FileOutputStream fout = new FileOutputStream( setSerialFile );
         ObjectOutputStream objOut = new ObjectOutputStream( fout );
-        
+
         Set<Integer> set = new HashSet<Integer>();
-        
-        for( int i=0; i < numKeys; i++ )
+
+        for ( int i = 0; i < numKeys; i++ )
         {
             set.add( i );
         }
-        
+
         long start = System.nanoTime();
-        
+
         objOut.writeObject( set );
         objOut.flush();
         objOut.close();
-        
+
         long end = System.nanoTime();
-        
+
         System.out.println( "total time taken for serializing HashSet ->" + getTime( start, end ) );
     }
-    
-    
+
+
     @SuppressWarnings("unchecked")
     @Test
     @Ignore
     public void testRBTreeDeserializationPerf() throws Exception
     {
-     // read test
+        // read test
         FileInputStream fin = new FileInputStream( setSerialFile );
         ObjectInputStream objIn = new ObjectInputStream( fin );
-        
+
         start = System.nanoTime();
-        
+
         set = ( HashSet ) objIn.readObject();
-        
+
         end = System.nanoTime();
-        
-        System.out.println("total time taken for reconstructing a serialized HashSet ->" + getTime( start, end ) );
+
+        System.out.println( "total time taken for reconstructing a serialized HashSet ->" + getTime( start, end ) );
     }
-    
-    
+
+
     @Test
     @Ignore
     public void testAVLTreeSerializationPerf() throws Exception
     {
-      
-      for( int i=0; i < numKeys; i++ )
-      {
-          tree.insert( i );
-      }
-      
-      FileOutputStream fout = new FileOutputStream( treeSerialFile );
-    
-      start = System.nanoTime();
-      
-      fout.write( treeMarshaller.serialize( tree ) );
-      fout.flush();
-      fout.close();
-      
-      end = System.nanoTime();
-      
-      System.out.println( "total time taken for serializing AVLTree ->" + getTime( start, end ) );
+
+        for ( int i = 0; i < numKeys; i++ )
+        {
+            tree.insert( i );
+        }
+
+        FileOutputStream fout = new FileOutputStream( treeSerialFile );
+
+        start = System.nanoTime();
+
+        fout.write( treeMarshaller.serialize( tree ) );
+        fout.flush();
+        fout.close();
+
+        end = System.nanoTime();
+
+        System.out.println( "total time taken for serializing AVLTree ->" + getTime( start, end ) );
     }
 
-    
+
     @Test
     @Ignore
     public void testAVLTreeDeserializationPerf() throws Exception
     {
         FileInputStream fin = new FileInputStream( treeSerialFile );
 
-        byte data[] = new byte[ ( int ) treeSerialFile.length() ];
-        
+        byte data[] = new byte[( int ) treeSerialFile.length()];
+
         start = System.nanoTime();
-        
-        fin.read(data);
-        tree = (AvlTree<Integer>) treeMarshaller.deserialize( data );
-        
+
+        fin.read( data );
+        tree = ( AvlTree<Integer> ) treeMarshaller.deserialize( data );
+
         end = System.nanoTime();
-        System.out.println("total time taken for reconstructing a serialized AVLTree ->" + getTime( start, end ) );
+        System.out.println( "total time taken for reconstructing a serialized AVLTree ->" + getTime( start, end ) );
     }
-    
-    
+
+
     /**
      * calculates the total time taken in milli seconds by taking the start and end time in nano seconds. 
      */
-    private String getTime(long nanoStartTime, long nanoEndTime)
+    private String getTime( long nanoStartTime, long nanoEndTime )
     {
         long temp = nanoEndTime - nanoStartTime;
-        
-        if( temp == 0)
+
+        if ( temp == 0 )
         {
             return "0 msec";
         }
-        
-       double d = temp / (1000 * 1000);
-        
-       return String.valueOf( d ) + " msec";
+
+        double d = temp / ( 1000 * 1000 );
+
+        return String.valueOf( d ) + " msec";
     }
 }

Modified: directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeTest.java?rev=1235258&r1=1235257&r2=1235258&view=diff
==============================================================================
--- directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeTest.java (original)
+++ directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeTest.java Tue Jan 24 14:10:56 2012
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.core.avltree;
 
+
 import static junit.framework.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -36,6 +37,7 @@ import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
  * An AVL tree testcase.
  *
@@ -47,40 +49,41 @@ public class AvlTreeTest
 {
 
     private static final Logger LOG = LoggerFactory.getLogger( AvlTreeTest.class );
-    
+
+
     private AvlTree<Integer> createTree()
     {
-      return new AvlTreeImpl<Integer>( new Comparator<Integer>() 
-          {
+        return new AvlTreeImpl<Integer>( new Comparator<Integer>()
+        {
 
             public int compare( Integer i1, Integer i2 )
             {
                 return i1.compareTo( i2 );
             }
-          
-          });  
+
+        } );
     }
-    
-    
+
+
     @Test
     public void testEmpty()
     {
-      AvlTree<Integer> tree = createTree();
-      assertTrue( tree.isEmpty() );
-      assertNull( tree.getFirst() );
-      assertNull( tree.getLast() );
-      
-      tree.remove( 97 ); // remove a non-existing key
-      assertTrue( tree.isEmpty() );
-      
-      if( LOG.isDebugEnabled() ) 
-      {
-          tree.printTree();
-      }
-    }
-    
-    
-    @Test 
+        AvlTree<Integer> tree = createTree();
+        assertTrue( tree.isEmpty() );
+        assertNull( tree.getFirst() );
+        assertNull( tree.getLast() );
+
+        tree.remove( 97 ); // remove a non-existing key
+        assertTrue( tree.isEmpty() );
+
+        if ( LOG.isDebugEnabled() )
+        {
+            tree.printTree();
+        }
+    }
+
+
+    @Test
     public void testFirstAndLast()
     {
         AvlTree<Integer> tree = createTree();
@@ -88,7 +91,7 @@ public class AvlTreeTest
         assertFalse( tree.isEmpty() );
         assertNotNull( tree.getFirst() );
         assertNotNull( tree.getLast() );
-        
+
         tree.insert( 10 );
         assertEquals( 2, tree.getSize() );
         assertNotNull( tree.getFirst() );
@@ -96,38 +99,38 @@ public class AvlTreeTest
         assertFalse( tree.getFirst().equals( tree.getLast() ) );
         assertTrue( tree.getFirst().getKey().equals( 7 ) );
         assertTrue( tree.getLast().getKey().equals( 10 ) );
-        
+
         tree.insert( 3 );
         assertTrue( tree.getFirst().getKey().equals( 3 ) );
         assertTrue( tree.getLast().getKey().equals( 10 ) );
-        
+
         tree.insert( 11 );
         assertTrue( tree.getFirst().getKey().equals( 3 ) );
         assertTrue( tree.getLast().getKey().equals( 11 ) );
     }
-    
-    
+
+
     @Test
     public void testInsert()
     {
         AvlTree<Integer> tree = createTree();
         assertNull( tree.insert( 3 ) );
         assertFalse( tree.isEmpty() );
-        
+
         assertTrue( 3 == tree.insert( 3 ) );// should be ignored
         assertTrue( 1 == tree.getSize() );
 
         assertNotNull( tree.getFirst() );
         assertNotNull( tree.getLast() );
         assertTrue( tree.getFirst() == tree.getLast() );
-        
+
         tree.remove( 3 );
-        
+
         tree.insert( 37 );
         tree.insert( 70 );
         tree.insert( 12 );
         assertTrue( 3 == tree.getSize() );
-        
+
         tree.insert( 90 );
         tree.insert( 25 );
         tree.insert( 99 );
@@ -135,69 +138,72 @@ public class AvlTreeTest
         tree.insert( 24 );
         tree.insert( 28 );
         tree.insert( 26 );
-        
-        if( LOG.isDebugEnabled() ) 
+
+        if ( LOG.isDebugEnabled() )
         {
             tree.printTree();
         }
-        
+
         tree.remove( 24 ); // this causes a single left rotation on node with key 12
-        if( LOG.isDebugEnabled() ) 
-        { 
+        if ( LOG.isDebugEnabled() )
+        {
             tree.printTree();
         }
         assertTrue( tree.getRoot().getLeft().key == 26 );
     }
-    
-    
+
+
     @Test
     public void testSingleRightRotation()
     {
-      AvlTree<Integer> tree = createTree();
-      // right rotation
-      tree.insert( 3 );
-      tree.insert( 2 );
-      tree.insert( 1 );
-      
-      assertEquals("1,2,3", getInorderForm( tree ));
+        AvlTree<Integer> tree = createTree();
+        // right rotation
+        tree.insert( 3 );
+        tree.insert( 2 );
+        tree.insert( 1 );
+
+        assertEquals( "1,2,3", getInorderForm( tree ) );
     }
 
+
     @Test
     public void testSingleLeftRotation()
     {
-      AvlTree<Integer> tree = createTree();
-      // left rotation
-      tree.insert( 1 );
-      tree.insert( 2 );
-      tree.insert( 3 );
-      
-      assertEquals("1,2,3", getInorderForm( tree ));
+        AvlTree<Integer> tree = createTree();
+        // left rotation
+        tree.insert( 1 );
+        tree.insert( 2 );
+        tree.insert( 3 );
+
+        assertEquals( "1,2,3", getInorderForm( tree ) );
     }
 
-    
+
     @Test
     public void testDoubleLeftRotation() // left-right totation
     {
-      AvlTree<Integer> tree = createTree();
-      // double left rotation
-      tree.insert( 1 );
-      tree.insert( 3 );
-      tree.insert( 2 );
-      
-      assertEquals("1,2,3", getInorderForm( tree ));
+        AvlTree<Integer> tree = createTree();
+        // double left rotation
+        tree.insert( 1 );
+        tree.insert( 3 );
+        tree.insert( 2 );
+
+        assertEquals( "1,2,3", getInorderForm( tree ) );
     }
-    
+
+
     @Test
     public void testDoubleRightRotation() // right-left totation
     {
-      AvlTree<Integer> tree = createTree();
-      // double left rotation
-      tree.insert( 3 );
-      tree.insert( 1 );
-      tree.insert( 2 );
-      assertEquals("1,2,3", getInorderForm( tree ));
+        AvlTree<Integer> tree = createTree();
+        // double left rotation
+        tree.insert( 3 );
+        tree.insert( 1 );
+        tree.insert( 2 );
+        assertEquals( "1,2,3", getInorderForm( tree ) );
     }
-    
+
+
     @Test
     public void testLinks()
     {
@@ -209,11 +215,12 @@ public class AvlTreeTest
         tree.insert( 11 );
         tree.insert( 25 );
         tree.insert( 5 );
-        
+
         assertTrue( 1 == tree.getFirst().key );
         assertTrue( 37 == tree.getLast().key );
     }
-    
+
+
     @Test
     public void testRemove()
     {
@@ -221,20 +228,20 @@ public class AvlTreeTest
         tree.insert( 3 );
         tree.insert( 2 );
         tree.insert( 1 );
-        
-        LOG.debug(getLinkedText( tree ));
+
+        LOG.debug( getLinkedText( tree ) );
         tree.remove( 2 );
-        LOG.debug(getLinkedText( tree ));
-        assertEquals("1,3", getInorderForm( tree ));
-        
+        LOG.debug( getLinkedText( tree ) );
+        assertEquals( "1,3", getInorderForm( tree ) );
+
         tree.remove( 1 );
-        assertEquals("3", getInorderForm( tree ));
+        assertEquals( "3", getInorderForm( tree ) );
         assertTrue( 3 == tree.getRoot().key );
-        
+
         assertNull( tree.remove( 777 ) );// key not present
         assertTrue( 3 == tree.remove( 3 ) );
-        assertTrue(tree.isEmpty());
-        
+        assertTrue( tree.isEmpty() );
+
         tree.insert( 37 );
         tree.insert( 39 );
         tree.insert( 27 );
@@ -252,45 +259,47 @@ public class AvlTreeTest
 
         tree.remove( 39 );
         assertEquals( "21,27,37,38", getInorderForm( tree ) );
-        
+
         assertTrue( 37 == tree.getRoot().key ); // check the root value
-        
+
         tree.remove( 38 ); // a double right rotation has to happen after this
         assertTrue( 27 == tree.getRoot().key ); // check the root value after double right rotation
         assertEquals( "21,27,37", getInorderForm( tree ) );
-        
-        if( LOG.isDebugEnabled() ) 
+
+        if ( LOG.isDebugEnabled() )
         {
             tree.printTree();
         }
     }
 
+
     @Test
     public void testLinkedNodes()
     {
         AvlTree<Integer> tree = createTree();
-        for( int i=0; i< 3; i++)
+        for ( int i = 0; i < 3; i++ )
         {
-           tree.insert( i ); 
+            tree.insert( i );
         }
-        
-        assertEquals( "[0]-->[1]-->[2]-->NULL", getLinkedText( tree ));
-        
+
+        assertEquals( "[0]-->[1]-->[2]-->NULL", getLinkedText( tree ) );
+
         tree.remove( 1 );
-        assertEquals( "[0]-->[2]-->NULL", getLinkedText( tree ));
-        
+        assertEquals( "[0]-->[2]-->NULL", getLinkedText( tree ) );
+
         tree.insert( 4 );
         tree.insert( 3 );
-        
-        assertEquals( "[0]-->[2]-->[3]-->[4]-->NULL", getLinkedText( tree ));
-        
+
+        assertEquals( "[0]-->[2]-->[3]-->[4]-->NULL", getLinkedText( tree ) );
+
         tree.remove( 0 );
-        assertEquals( "[2]-->[3]-->[4]-->NULL", getLinkedText( tree ));
-        
+        assertEquals( "[2]-->[3]-->[4]-->NULL", getLinkedText( tree ) );
+
         tree.remove( 3 );
-        assertEquals( "[2]-->[4]-->NULL", getLinkedText( tree ));
+        assertEquals( "[2]-->[4]-->NULL", getLinkedText( tree ) );
     }
-    
+
+
     @Test
     public void testFind()
     {
@@ -301,42 +310,44 @@ public class AvlTreeTest
         tree.insert( 12 );
         tree.insert( 27 );
         tree.insert( 11 );
-        
+
         assertNotNull( tree.find( 11 ) );
-        assertNull( tree.find( 0 ));
-        
+        assertNull( tree.find( 0 ) );
+
         ( ( AvlTreeImpl ) tree ).setRoot( null );
-        assertNull( tree.find( 3 ));
+        assertNull( tree.find( 3 ) );
     }
-    
+
+
     @Test
     public void testFindGreater()
     {
         AvlTree<Integer> tree = createTree();
         assertNull( tree.findGreater( 1 ) );
-        
+
         tree.insert( 1 );
         assertNull( tree.findGreater( 1 ) );
-        
+
         tree.insert( 0 );
         tree.insert( 3 );
         tree.insert( 7 );
         tree.insert( 6 );
         tree.insert( 2 );
         tree.insert( 8 );
-        
+
         assertFalse( 1 == tree.findGreater( 1 ).key );
         assertTrue( 2 == tree.findGreater( 1 ).key );
         assertTrue( 6 == tree.findGreater( 4 ).key );
         assertNull( tree.findGreater( 8 ) );
     }
-    
+
+
     @Test
     public void testFindLess()
     {
         AvlTree<Integer> tree = createTree();
         assertNull( tree.findLess( 1 ) );
-        
+
         tree.insert( 1 );
         assertNull( tree.findLess( 1 ) );
 
@@ -346,28 +357,30 @@ public class AvlTreeTest
         tree.insert( 6 );
         tree.insert( 0 );
         tree.insert( 37 );
-        
+
         assertFalse( 0 == tree.findLess( 5 ).key );
         assertTrue( 3 == tree.findLess( 5 ).key );
         assertTrue( 7 == tree.findLess( 8 ).key );
         assertNull( tree.findLess( 0 ) );
     }
-    
+
+
     @Test
     public void testFindMaxMin()
     {
         AvlTree<Integer> tree = createTree();
         tree.insert( 72 );
         tree.insert( 79 );
-        
+
         tree.remove( 72 );// should call findMax internally
         assertTrue( 79 == tree.getRoot().key );
-        
+
         tree.insert( 11 );
         tree.remove( 79 ); // should call findMin internally
         assertTrue( 11 == tree.getRoot().key );
     }
-    
+
+
     @Test
     public void testGetKeys()
     {
@@ -379,22 +392,25 @@ public class AvlTreeTest
         tree.insert( 3 );
         tree.insert( 7 );
         tree.insert( 34 );
-        
+
         assertTrue( 7 == tree.getKeys().size() );
     }
-    
+
+
     @Test
     public void testTreeRoationAtLeftChildAfterDeletingRoot()
     {
         AvlTree<Integer> tree = createTree();
-        int[] keys = { 86, 110, 122, 2, 134, 26, 14, 182 }; // order is important to produce the expected tree
-        int[] expectedKeys = { 2, 14, 26, 86, 122, 134, 182 };
-        
-        for( int key:keys )
+        int[] keys =
+            { 86, 110, 122, 2, 134, 26, 14, 182 }; // order is important to produce the expected tree
+        int[] expectedKeys =
+            { 2, 14, 26, 86, 122, 134, 182 };
+
+        for ( int key : keys )
         {
             tree.insert( key );
         }
-        
+
         tree.remove( 110 );
 
         for ( int key : expectedKeys )
@@ -402,21 +418,22 @@ public class AvlTreeTest
             assertNotNull( "Should find " + key, tree.find( key ) );
         }
     }
-    
+
 
     @Test
     public void testDetachNodesAtLeftChildAfterDeletingRoot()
     {
         AvlTree<Integer> tree = createTree();
-        int[] keys = { 110, 122, 2, 134, 86, 14, 26, 182 }; // order is important to produce the expected tree
-        
-        for( int key:keys )
+        int[] keys =
+            { 110, 122, 2, 134, 86, 14, 26, 182 }; // order is important to produce the expected tree
+
+        for ( int key : keys )
         {
             tree.insert( key );
         }
 
         tree.remove( 110 );
-        
+
         assertEquals( 26, ( int ) tree.find( 14 ).right.key );
     }
 
@@ -425,26 +442,28 @@ public class AvlTreeTest
     public void testRemoveInRightSubtree()
     {
         AvlTree<Integer> tree = createTree();
-        int[] keys = { 8, 4, 13, 6, 15, 7, 10, 5, 14, 2, 11, 3, 9, 1 }; // order is important to produce the expected tree
-        
-        for( int key:keys )
+        int[] keys =
+            { 8, 4, 13, 6, 15, 7, 10, 5, 14, 2, 11, 3, 9, 1 }; // order is important to produce the expected tree
+
+        for ( int key : keys )
         {
             tree.insert( key );
         }
 
         tree.remove( 13 );
-        
+
         assertEquals( 11, ( int ) tree.find( 8 ).right.key );
     }
 
-   
+
     @Test
     public void testRemoveInLeftSubtree()
     {
         AvlTree<Integer> tree = createTree();
-        int[] keys = { 8, 4, 12, 6, 7, 16, 10, 5, 11, 9, 17, 5, 14, 2, 13, 1, 3 }; // order is important to produce the expected tree
-        
-        for( int key:keys )
+        int[] keys =
+            { 8, 4, 12, 6, 7, 16, 10, 5, 11, 9, 17, 5, 14, 2, 13, 1, 3 }; // order is important to produce the expected tree
+
+        for ( int key : keys )
         {
             tree.insert( key );
         }
@@ -456,58 +475,60 @@ public class AvlTreeTest
         assertEquals( 14, ( int ) tree.getRoot().right.right.key );
         assertEquals( 13, ( int ) tree.find( 14 ).left.key );
     }
-    
-    
-    private String getLinkedText( AvlTree<Integer> tree ) 
+
+
+    private String getLinkedText( AvlTree<Integer> tree )
     {
         LinkedAvlNode<Integer> first = tree.getFirst();
         StringBuilder sb = new StringBuilder();
-        
-        while( first != null )
+
+        while ( first != null )
         {
             sb.append( first )
-              .append( "-->" );
-            
+                .append( "-->" );
+
             first = first.next;
         }
         sb.append( "NULL" );
         return sb.toString();
     }
-    
+
+
     private String getInorderForm( AvlTree<Integer> tree )
     {
-      StringBuilder sb = new StringBuilder();
-      List<LinkedAvlNode<Integer>> path = new ArrayList<LinkedAvlNode<Integer>>();
-      
-      traverse( tree.getRoot(), path );
-      int i;
-      for( i=0; i < path.size() -1; i++ )
-      {
-          sb.append( path.get( i ).key )
-            .append( ',' );
-      }
-      
-      sb.append( path.get( i ).key );
-      
-      return sb.toString();
+        StringBuilder sb = new StringBuilder();
+        List<LinkedAvlNode<Integer>> path = new ArrayList<LinkedAvlNode<Integer>>();
+
+        traverse( tree.getRoot(), path );
+        int i;
+        for ( i = 0; i < path.size() - 1; i++ )
+        {
+            sb.append( path.get( i ).key )
+                .append( ',' );
+        }
+
+        sb.append( path.get( i ).key );
+
+        return sb.toString();
     }
-    
+
+
     private void traverse( LinkedAvlNode<Integer> startNode, List<LinkedAvlNode<Integer>> path )
     {
-      //1. pre-order
-        
-      if( startNode.left != null )
-      {
-          traverse( startNode.left, path );
-      }
-      
-      path.add( startNode ); //2. in-order NOTE: change this line's position to change the type of traversal
-
-      if( startNode.right != null )
-      {
-         traverse( startNode.right, path ); 
-      }
-      //3. post-order
+        //1. pre-order
+
+        if ( startNode.left != null )
+        {
+            traverse( startNode.left, path );
+        }
+
+        path.add( startNode ); //2. in-order NOTE: change this line's position to change the type of traversal
+
+        if ( startNode.right != null )
+        {
+            traverse( startNode.right, path );
+        }
+        //3. post-order
     }
 
 
@@ -516,11 +537,11 @@ public class AvlTreeTest
     {
         AvlTree<Integer> tree = createTree();
         tree.remove( null );
-        
+
         assertEquals( 0, tree.getSize() );
 
         tree.remove( 1 );
-        
+
         assertEquals( 0, tree.getSize() );
     }
 
@@ -531,7 +552,7 @@ public class AvlTreeTest
         AvlTree<Integer> tree = createTree();
         tree.insert( 1 );
         assertEquals( 1, tree.getSize() );
-        
+
         tree.remove( 1 );
         assertEquals( 0, tree.getSize() );
     }
@@ -545,7 +566,7 @@ public class AvlTreeTest
         tree.insert( 2 );
         assertEquals( 2, tree.getSize() );
         assertEquals( "1,2", getInorderForm( tree ) );
-        
+
         tree.remove( 1 );
         assertEquals( 1, tree.getSize() );
         assertEquals( Integer.valueOf( 2 ), tree.getRoot().getKey() );

Modified: directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/DefaultMarshallerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/DefaultMarshallerTest.java?rev=1235258&r1=1235257&r2=1235258&view=diff
==============================================================================
--- directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/DefaultMarshallerTest.java (original)
+++ directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/DefaultMarshallerTest.java Tue Jan 24 14:10:56 2012
@@ -64,7 +64,6 @@ public class DefaultMarshallerTest
         assertTrue( ArrayUtils.isEquals( serialized, marshaller.serialize( deserialized ) ) );
     }
 
-
     static class Bar implements Serializable
     {
         private static final long serialVersionUID = 2982919006977619754L;
@@ -75,7 +74,6 @@ public class DefaultMarshallerTest
         Foo fooValue = new Foo();
     }
 
-
     static class Foo implements Serializable
     {
         private static final long serialVersionUID = -1366956596647335984L;

Modified: directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/IntegerKeyMarshaller.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/IntegerKeyMarshaller.java?rev=1235258&r1=1235257&r2=1235258&view=diff
==============================================================================
--- directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/IntegerKeyMarshaller.java (original)
+++ directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/IntegerKeyMarshaller.java Tue Jan 24 14:10:56 2012
@@ -27,25 +27,25 @@ public class IntegerKeyMarshaller implem
     {
         int y = i.intValue();
         byte[] data = new byte[4];
-        data[0] = (byte)((y & 0xFF) >>> 24);
-        data[1] = (byte)((y & 0xFF) >>> 16);
-        data[2] = (byte)((y & 0xFF) >>> 8);
-        data[3] = (byte)(y & 0xFF);
-        
+        data[0] = ( byte ) ( ( y & 0xFF ) >>> 24 );
+        data[1] = ( byte ) ( ( y & 0xFF ) >>> 16 );
+        data[2] = ( byte ) ( ( y & 0xFF ) >>> 8 );
+        data[3] = ( byte ) ( y & 0xFF );
+
         return data;
     }
 
 
     public Integer deserialize( byte[] data )
     {
-        if( data == null || data.length == 0)
+        if ( data == null || data.length == 0 )
         {
             return null;
         }
-       
+
         return ( ( data[0] & 0xFF ) << 24 )
-                  | (( data[1] & 0xFF ) << 16 )
-                  | ( ( data[2] & 0xFF ) << 8 )
-                  | ( data[3] & 0xFF );
+            | ( ( data[1] & 0xFF ) << 16 )
+            | ( ( data[2] & 0xFF ) << 8 )
+            | ( data[3] & 0xFF );
     }
 }

Modified: directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/avl/AvlTreePerfTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/avl/AvlTreePerfTest.java?rev=1235258&r1=1235257&r2=1235258&view=diff
==============================================================================
--- directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/avl/AvlTreePerfTest.java (original)
+++ directory/apacheds/trunk/core-avl/src/test/java/org/apache/directory/server/core/avltree/avl/AvlTreePerfTest.java Tue Jan 24 14:10:56 2012
@@ -48,221 +48,224 @@ import org.slf4j.LoggerFactory;
 public class AvlTreePerfTest
 {
     AvlTreeSet<Integer> tree;
-    
+
     static String tempDir = System.getProperty( "java.io.tmpdir" );
-   
+
     static File setSerialFile = new File( tempDir + File.separator + "hashset.ser" );
     static File treeSerialFile = new File( tempDir + File.separator + "avltree.ser" );
-    
+
     Set<Integer> set;
-    
+
     long start, end;
 
     int numKeys = 1000000;
 
-    Comparator<Integer> comparator = new Comparator<Integer>() 
+    Comparator<Integer> comparator = new Comparator<Integer>()
     {
-      public int compare( Integer i1, Integer i2 )
-      {
-          return i1.compareTo( i2 );
-      }
-    
+        public int compare( Integer i1, Integer i2 )
+        {
+            return i1.compareTo( i2 );
+        }
+
     };
-    
+
     AvlTreeMarshaller<Integer> treeMarshaller = new AvlTreeMarshaller<Integer>( comparator, new IntegerKeyMarshaller() );
 
     private final static Logger LOG = LoggerFactory.getLogger( AvlTreePerfTest.class );
-    
+
+
     @Before
     public void createTree()
     {
-      tree = new AvlTreeSet<Integer>();  
-      
-      set = new HashSet<Integer>();
-      
-      start = end = 0;
+        tree = new AvlTreeSet<Integer>();
+
+        set = new HashSet<Integer>();
+
+        start = end = 0;
     }
-    
-    
+
+
     @AfterClass
     public static void deleteFiles()
     {
         setSerialFile.delete();
         treeSerialFile.delete();
     }
-    
-    
+
+
     @Test
     public void testRBTreeInsertPerf()
     {
         start = System.nanoTime();
-        
-        for( int i=0; i < numKeys; i++ )
+
+        for ( int i = 0; i < numKeys; i++ )
         {
             set.add( i );
         }
-        
+
         end = System.nanoTime();
-     
-        System.out.println( "total time for inserting " + numKeys + " items into the RBTree-->" +  getTime( start, end ) );
-        
+
+        System.out
+            .println( "total time for inserting " + numKeys + " items into the RBTree-->" + getTime( start, end ) );
+
     }
 
-    
+
     @Test
     @Ignore
     public void testRBTreeLookupPerf()
     {
-        for( int i=0; i < numKeys; i++ )
+        for ( int i = 0; i < numKeys; i++ )
         {
             set.add( i );
         }
-        
+
         start = System.nanoTime();
-       
+
         set.contains( 70 );
         set.contains( -1000 );
         set.contains( 10 );
         set.contains( 90 );
         set.contains( 9999 );
-        
-       end = System.nanoTime();
-       
-       System.out.println( "total time took to read an item from set " + getTime( start, end ) ) ;
+
+        end = System.nanoTime();
+
+        System.out.println( "total time took to read an item from set " + getTime( start, end ) );
     }
-    
-    
+
+
     @Test
     @Ignore
     public void testRemoveFromRBTree()
     {
-        for( int i=0; i < numKeys; i++ )
+        for ( int i = 0; i < numKeys; i++ )
         {
             set.add( i );
         }
-        
+
         start = System.nanoTime();
-        
+
         set.remove( 90 );
         set.remove( 912 );
         set.remove( -1 );
         set.remove( 192 );
-        
+
         end = System.nanoTime();
-        
-        System.out.println( "total time took to remove an item from set " + getTime( start, end ) ) ;
+
+        System.out.println( "total time took to remove an item from set " + getTime( start, end ) );
 
     }
-    
-    
+
+
     @Test
     public void testAvlTreeInsertPerf()
     {
         start = System.nanoTime();
-        
-        for( int i=0; i < numKeys; i++ )
+
+        for ( int i = 0; i < numKeys; i++ )
         {
             tree.insert( i );
         }
 
         end = System.nanoTime();
-        
-        System.out.println("total time for inserting " + numKeys + " items into the AVLTree-->" + getTime(start, end));
+
+        System.out
+            .println( "total time for inserting " + numKeys + " items into the AVLTree-->" + getTime( start, end ) );
     }
-    
-    
+
+
     @Test
     @Ignore
     public void testAVLTreeLookupPerf()
     {
-        
-        for( int i=0; i < numKeys; i++ )
+
+        for ( int i = 0; i < numKeys; i++ )
         {
             tree.insert( i );
         }
-        
+
         start = System.nanoTime();
-        
+
         tree.contains( 70 );
         tree.contains( -1000 );
         tree.contains( 10 );
         tree.contains( 90 );
         tree.contains( 9999 );
-        
+
         end = System.nanoTime();
-        
-        System.out.println("total time took to read an item from tree " + getTime( start, end ) ) ;
+
+        System.out.println( "total time took to read an item from tree " + getTime( start, end ) );
     }
-    
-    
+
+
     @Test
     @Ignore
     public void testAVLTreeRemovePerf()
     {
-        for( int i=0; i < numKeys; i++ )
+        for ( int i = 0; i < numKeys; i++ )
         {
             tree.insert( i );
         }
-        
+
         start = System.nanoTime();
-        
+
         tree.remove( 90 );
         tree.remove( 912 );
         tree.remove( -1 );
         tree.remove( 192 );
-        
+
         end = System.nanoTime();
-        
-        System.out.println("total time took to remove an item from AVLTree " + getTime( start, end ) ) ;
+
+        System.out.println( "total time took to remove an item from AVLTree " + getTime( start, end ) );
 
     }
-    
-    
+
+
     @Test
     @Ignore
     public void testRBTreeSerializationPerf() throws Exception
     {
         FileOutputStream fout = new FileOutputStream( setSerialFile );
         ObjectOutputStream objOut = new ObjectOutputStream( fout );
-        
+
         Set<Integer> set = new HashSet<Integer>();
-        
-        for( int i=0; i < numKeys; i++ )
+
+        for ( int i = 0; i < numKeys; i++ )
         {
             set.add( i );
         }
-        
+
         long start = System.nanoTime();
-        
+
         objOut.writeObject( set );
         objOut.flush();
         objOut.close();
-        
+
         long end = System.nanoTime();
-        
+
         System.out.println( "total time taken for serializing HashSet ->" + getTime( start, end ) );
     }
-    
-    
+
+
     @SuppressWarnings("unchecked")
     @Test
     @Ignore
     public void testRBTreeDeserializationPerf() throws Exception
     {
-     // read test
+        // read test
         FileInputStream fin = new FileInputStream( setSerialFile );
         ObjectInputStream objIn = new ObjectInputStream( fin );
-        
+
         start = System.nanoTime();
-        
+
         set = ( HashSet ) objIn.readObject();
-        
+
         end = System.nanoTime();
-        
-        System.out.println("total time taken for reconstructing a serialized HashSet ->" + getTime( start, end ) );
+
+        System.out.println( "total time taken for reconstructing a serialized HashSet ->" + getTime( start, end ) );
     }
-    
-    
+
+
     /*
     @Test
     public void testAVLTreeSerializationPerf() throws Exception
@@ -303,22 +306,21 @@ public class AvlTreePerfTest
         System.out.println("total time taken for reconstructing a serialized AVLTree ->" + getTime( start, end ) );
     }
     */
-    
-    
+
     /**
      * calculates the total time taken in milli seconds by taking the start and end time in nano seconds. 
      */
-    private String getTime(long nanoStartTime, long nanoEndTime)
+    private String getTime( long nanoStartTime, long nanoEndTime )
     {
         long temp = nanoEndTime - nanoStartTime;
-        
-        if( temp == 0)
+
+        if ( temp == 0 )
         {
             return "0 msec";
         }
-        
-       double d = temp / (1000 * 1000);
-        
-       return String.valueOf( d ) + " msec";
+
+        double d = temp / ( 1000 * 1000 );
+
+        return String.valueOf( d ) + " msec";
     }
 }



Mime
View raw message