You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2008/03/12 03:02:14 UTC

svn commit: r636172 - in /directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src: main/java/org/apache/directory/server/core/avltree/ test/java/org/apache/directory/server/core/avltree/

Author: akarasulu
Date: Tue Mar 11 19:02:13 2008
New Revision: 636172

URL: http://svn.apache.org/viewvc?rev=636172&view=rev
Log:
Removing dependency on Serializer from JDBM

Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMarshaller.java
    directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/Marshaller.java
    directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java
    directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreePerfTest.java
    directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/IntegerKeyMarshaller.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMarshaller.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMarshaller.java?rev=636172&r1=636171&r2=636172&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMarshaller.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMarshaller.java Tue Mar 11 19:02:13 2008
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.core.avltree;
 
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.DataInputStream;
@@ -26,13 +27,8 @@
 import java.io.IOException;
 import java.util.Comparator;
 
-import jdbm.helper.Serializer;
-
-import org.apache.directory.server.core.avltree.AvlTree;
-import org.apache.directory.server.core.avltree.LinkedAvlNode;
 
 /**
- * 
  * Class to serialize the AvlTree node data.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -41,9 +37,8 @@
 @SuppressWarnings("unchecked")
 public class AvlTreeMarshaller<E> implements Marshaller<AvlTree<E>>
 {
-
     /** marshaller to be used for marshalling the keys */
-    private Serializer keyMarshaller;
+    private Marshaller<E> keyMarshaller;
     
     /** key Comparator for the AvlTree */
     private Comparator<E> comparator;
@@ -58,32 +53,18 @@
      * @param comparator Comparator to be used for key comparision
      * @param keyMarshaller marshaller for keys
      */
-    public AvlTreeMarshaller(Comparator<E> comparator, Marshaller keyMarshaller)
-    {
-        this( comparator, ( Serializer )keyMarshaller );
-    }
-
-    /**
-     * 
-     * Creates a new instance of AvlTreeMarshaller.
-     *
-     * @param comparator Comparator to be used for key comparision
-     * @param keySerializer marshaller for keys
-     */
-    public AvlTreeMarshaller(Comparator<E> comparator, Serializer keySerializer)
+    public AvlTreeMarshaller(Comparator<E> comparator, Marshaller<E> keyMarshaller)
     {
         this.comparator = comparator;
-        this.keyMarshaller = keySerializer;
+        this.keyMarshaller = keyMarshaller;
     }
     
     /**
      * Marshals the given tree to bytes
      * @param tree the tree to be marshalled
      */
-    public byte[] serialize( Object avlTreeObj )
+    public byte[] serialize( AvlTree<E> tree )
     {
-        AvlTree<E> tree = ( AvlTree<E> ) avlTreeObj;
-        
         if( tree.isEmpty() )
         {
             return null;
@@ -117,7 +98,7 @@
      *
      * @param node the node to be marshalled to bytes
      * @param out OutputStream
-     * @throws IOException
+     * @throws IOException on write failures of serialized tree to stream
      */
     private void writeTree( LinkedAvlNode<E> node, DataOutputStream out ) throws IOException
     {
@@ -198,16 +179,21 @@
     /**
      * Reads the data from given InputStream and creates the LinkedAvlNodes to form the tree
      * node = [size] [data-length] [data] [index] [child-marker] [node] [child-marker] [node]
-     * 
+     *
+     * @param in the input stream to deserialize from
+     * @param node the node to deserialize
+     * @return the deserialized AvlTree node
+     * @throws IOException on failures to deserialize or read from the stream
      */
     public LinkedAvlNode<E> readTree( DataInputStream in, LinkedAvlNode<E> node ) throws IOException
     {
       int dLen = in.readInt();
       
       byte[] data = new byte[ dLen ];
-      in.read( data );
+        //noinspection ResultOfMethodCallIgnored
+        in.read( data );
 
-      E key = ( E ) keyMarshaller.deserialize( data );
+      E key = keyMarshaller.deserialize( data );
       node = new LinkedAvlNode( key );
       
       int index = in.readInt();

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/Marshaller.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/Marshaller.java?rev=636172&r1=636171&r2=636172&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/Marshaller.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/main/java/org/apache/directory/server/core/avltree/Marshaller.java Tue Mar 11 19:02:13 2008
@@ -19,7 +19,9 @@
  */
 package org.apache.directory.server.core.avltree;
 
-import jdbm.helper.Serializer;
+
+import java.io.IOException;
+
 
 /**
  * 
@@ -28,6 +30,9 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface Marshaller<E> extends Serializer
+public interface Marshaller<E>
 {
+    byte[] serialize( E object ) throws IOException;
+
+    E deserialize( byte[] bytes ) throws IOException;
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java?rev=636172&r1=636171&r2=636172&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMarshallerTest.java Tue Mar 11 19:02:13 2008
@@ -19,7 +19,7 @@
  */
 package org.apache.directory.server.core.avltree;
 
-import static org.junit.Assert.assertFalse;
+
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
@@ -30,9 +30,9 @@
 import java.io.IOException;
 import java.util.Comparator;
 
-import org.apache.directory.server.core.avltree.AvlTree;
 import org.junit.Before;
 import org.junit.Test;
+
 
 /**
  * TestCase for AvlTreeMarshaller.

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreePerfTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreePerfTest.java?rev=636172&r1=636171&r2=636172&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreePerfTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreePerfTest.java Tue Mar 11 19:02:13 2008
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.core.avltree;
 
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -30,6 +31,7 @@
 
 import org.junit.Before;
 import org.junit.Test;
+
 
 /**
  * 

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/IntegerKeyMarshaller.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/IntegerKeyMarshaller.java?rev=636172&r1=636171&r2=636172&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/IntegerKeyMarshaller.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-avl/src/test/java/org/apache/directory/server/core/avltree/IntegerKeyMarshaller.java Tue Mar 11 19:02:13 2008
@@ -1,12 +1,30 @@
-
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
 package org.apache.directory.server.core.avltree;
 
+
 public class IntegerKeyMarshaller implements Marshaller<Integer>
 {
 
-    public byte[] serialize( Object integerObj )
+    public byte[] serialize( Integer i )
     {
-        Integer i = ( Integer ) integerObj;
         int y = i.intValue();
         byte[] data = new byte[4];
         data[0] = (byte)((y & 0xFF) >>> 24);
@@ -25,12 +43,9 @@
             return null;
         }
        
-        int y =  ( ( data[0] & 0xFF ) << 24 ) 
+        return ( ( data[0] & 0xFF ) << 24 )
                   | (( data[1] & 0xFF ) << 16 )
                   | ( ( data[2] & 0xFF ) << 8 )
                   | ( data[3] & 0xFF );
-        
-        return y;
     }
-
 }