You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by el...@apache.org on 2013/02/01 01:14:28 UTC

svn commit: r1441274 - in /labs/mavibot/trunk/mavibot/src: main/java/org/apache/mavibot/btree/ main/java/org/apache/mavibot/btree/comparator/ main/java/org/apache/mavibot/btree/serializer/ test/java/org/apache/mavibot/btree/ test/java/org/apache/mavibo...

Author: elecharny
Date: Fri Feb  1 00:14:27 2013
New Revision: 1441274

URL: http://svn.apache.org/viewvc?rev=1441274&view=rev
Log:
o Changed the way we inject serializers in the BTree : we now inject the key and value serializer, and not anymore the key comparator, which is now part of the serializers
o Added some missing comparators

Added:
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanComparator.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ByteArrayComparator.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ByteComparator.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/CharComparator.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ShortComparator.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/StringComparator.java
Removed:
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/DefaultSerializer.java
    labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/serializer/DefaultSerializerTest.java
Modified:
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntComparator.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/BooleanSerializer.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ByteArraySerializer.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ByteSerializer.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/CharSerializer.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ElementSerializer.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/IntSerializer.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/LongSerializer.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/Serializer.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ShortSerializer.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/StringSerializer.java
    labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java
    labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java
    labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/InMemoryBTreeTest.java
    labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/LeafTest.java
    labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/MultiThreadedBtreeTest.java

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java Fri Feb  1 00:14:27 2013
@@ -38,8 +38,8 @@ import java.util.concurrent.atomic.Atomi
 import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.mavibot.btree.serializer.BufferHandler;
+import org.apache.mavibot.btree.serializer.ElementSerializer;
 import org.apache.mavibot.btree.serializer.LongSerializer;
-import org.apache.mavibot.btree.serializer.Serializer;
 
 
 /**
@@ -91,10 +91,11 @@ public class BTree<K, V>
     /** The type to use to create the keys */
     protected Class<?> keyType;
 
-    /** The Key and Value serializer used for this tree. If none is provided, 
-     * the BTree will deduce the serializer to use from the generic type, and
-     * use the default Java serialization  */
-    private Serializer<K, V> serializer;
+    /** The Key serializer used for this tree.*/
+    private ElementSerializer<K> keySerializer;
+
+    /** The Value serializer used for this tree. */
+    private ElementSerializer<V> valueSerializer;
 
     /** The associated file. If null, this is an in-memory btree  */
     private File file;
@@ -217,7 +218,7 @@ public class BTree<K, V>
             {
                 if ( modification instanceof Addition )
                 {
-                    byte[] keyBuffer = serializer.serializeKey( modification.getKey() );
+                    byte[] keyBuffer = keySerializer.serialize( modification.getKey() );
                     ByteBuffer bb = ByteBuffer.allocateDirect( keyBuffer.length + 1 );
                     bb.put( Modification.ADDITION );
                     bb.put( keyBuffer );
@@ -225,7 +226,7 @@ public class BTree<K, V>
 
                     channel.write( bb );
 
-                    byte[] valueBuffer = serializer.serializeValue( modification.getValue() );
+                    byte[] valueBuffer = valueSerializer.serialize( modification.getValue() );
                     bb = ByteBuffer.allocateDirect( valueBuffer.length );
                     bb.put( valueBuffer );
                     bb.flip();
@@ -234,7 +235,7 @@ public class BTree<K, V>
                 }
                 else if ( modification instanceof Deletion )
                 {
-                    byte[] keyBuffer = serializer.serializeKey( modification.getKey() );
+                    byte[] keyBuffer = keySerializer.serialize( modification.getKey() );
                     ByteBuffer bb = ByteBuffer.allocateDirect( keyBuffer.length + 1 );
                     bb.put( Modification.DELETION );
                     bb.put( keyBuffer );
@@ -341,8 +342,9 @@ public class BTree<K, V>
         }
 
         pageSize = configuration.getPageSize();
-        comparator = configuration.getComparator();
-        serializer = configuration.getSerializer();
+        keySerializer = configuration.getKeySerializer();
+        valueSerializer = configuration.getValueSerializer();
+        comparator = keySerializer.getComparator();
         readTimeOut = configuration.getReadTimeOut();
         writeBufferSize = configuration.getWriteBufferSize();
 
@@ -357,38 +359,25 @@ public class BTree<K, V>
 
 
     /**
-     * Creates a new in-memory BTree with a default page size and a comparator.
+     * Creates a new in-memory BTree with a default page size and key/value serializers.
      * 
      * @param comparator The comparator to use
      */
-    public BTree( Comparator<K> comparator ) throws IOException
+    public BTree( ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer ) throws IOException
     {
-        this( null, null, comparator, null, DEFAULT_PAGE_SIZE );
+        this( null, null, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE );
     }
 
 
     /**
-     * Creates a new in-memory BTree with a default page size and a comparator.
+     * Creates a new in-memory BTree with a default page size and key/value serializers.
      * 
      * @param comparator The comparator to use
-     * @param serializer The serializer to use
      */
-    public BTree( Comparator<K> comparator, Serializer<K, V> serializer ) throws IOException
-    {
-        this( null, null, comparator, serializer, DEFAULT_PAGE_SIZE );
-    }
-
-
-    /**
-     * Creates a new BTree with a default page size and a comparator, with an associated file.
-     * 
-     * @param path the File path
-     * @param file The file storing the BTree data
-     * @param comparator The comparator to use
-     */
-    public BTree( String path, String file, Comparator<K> comparator ) throws IOException
+    public BTree( ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize )
+        throws IOException
     {
-        this( path, file, comparator, null, DEFAULT_PAGE_SIZE );
+        this( null, null, keySerializer, valueSerializer, pageSize );
     }
 
 
@@ -399,47 +388,10 @@ public class BTree<K, V>
      * @param comparator The comparator to use
      * @param serializer The serializer to use
      */
-    public BTree( String path, String file, Comparator<K> comparator, Serializer<K, V> serializer ) throws IOException
-    {
-        this( path, file, comparator, serializer, DEFAULT_PAGE_SIZE );
-    }
-
-
-    /**
-     * Creates a new in-memory BTree with a specific page size and a comparator.
-     * 
-     * @param comparator The comparator to use
-     * @param pageSize The number of elements we can store in a page
-     */
-    public BTree( Comparator<K> comparator, int pageSize ) throws IOException
-    {
-        this( null, null, comparator, null, pageSize );
-    }
-
-
-    /**
-     * Creates a new in-memory BTree with a specific page size and a comparator.
-     * 
-     * @param comparator The comparator to use
-     * @param serializer The serializer to use
-     * @param pageSize The number of elements we can store in a page
-     */
-    public BTree( Comparator<K> comparator, Serializer<K, V> serializer, int pageSize ) throws IOException
-    {
-        this( null, null, comparator, serializer, pageSize );
-    }
-
-
-    /**
-     * Creates a new BTree with a specific page size and a comparator.
-     * 
-     * @param file The file storing the BTree data
-     * @param comparator The comparator to use
-     * @param pageSize The number of elements we can store in a page
-     */
-    public BTree( String path, String file, Comparator<K> comparator, int pageSize ) throws IOException
+    public BTree( String path, String file, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
+        throws IOException
     {
-        this( path, file, comparator, null, pageSize );
+        this( path, file, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE );
     }
 
 
@@ -451,16 +403,10 @@ public class BTree<K, V>
      * @param serializer The serializer to use
      * @param pageSize The number of elements we can store in a page
      */
-    public BTree( String path, String file, Comparator<K> comparator, Serializer<K, V> serializer, int pageSize )
+    public BTree( String path, String file, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer,
+        int pageSize )
         throws IOException
     {
-        if ( comparator == null )
-        {
-            throw new IllegalArgumentException( "Comparator should not be null" );
-        }
-
-        this.comparator = comparator;
-
         if ( ( path == null ) && ( file == null ) )
         {
             inMemory = true;
@@ -491,7 +437,9 @@ public class BTree<K, V>
         setPageSize( pageSize );
         writeBufferSize = DEFAULT_WRITE_BUFFER_SIZE;
 
-        this.serializer = serializer;
+        this.keySerializer = keySerializer;
+        this.valueSerializer = valueSerializer;
+        comparator = keySerializer.getComparator();
 
         // Now, call the init() method
         init();
@@ -501,7 +449,7 @@ public class BTree<K, V>
     /**
      * Initialize the BTree.
      * 
-     * @throws IOException If we get some exceptio while initializing the BTree
+     * @throws IOException If we get some exception while initializing the BTree
      */
     public void init() throws IOException
     {
@@ -971,6 +919,15 @@ public class BTree<K, V>
 
 
     /**
+     * @return the type for the keys
+     */
+    public Class<?> getKeyType()
+    {
+        return keyType;
+    }
+
+
+    /**
      * @return the comparator
      */
     public Comparator<K> getComparator()
@@ -989,20 +946,20 @@ public class BTree<K, V>
 
 
     /**
-     * @param serializer the serializer to set
+     * @param keySerializer the Key serializer to set
      */
-    public void setSerializer( Serializer<K, V> serializer )
+    public void setKeySerializer( ElementSerializer<K> keySerializer )
     {
-        this.serializer = serializer;
+        this.keySerializer = keySerializer;
     }
 
 
     /**
-     * @return the type for the keys
+     * @param valueSerializer the Value serializer to set
      */
-    public Class<?> getKeyType()
+    public void setValueSerializer( ElementSerializer<V> valueSerializer )
     {
-        return keyType;
+        this.valueSerializer = valueSerializer;
     }
 
 
@@ -1010,7 +967,7 @@ public class BTree<K, V>
      * Write the data in the ByteBuffer, and eventually on disk if needed.
      * 
      * @param channel The channel we want to write to
-     * @param bb The ByteBuffer we wat to feed
+     * @param bb The ByteBuffer we want to feed
      * @param buffer The data to inject
      * @throws IOException If the write failed
      */
@@ -1075,9 +1032,14 @@ public class BTree<K, V>
 
         Cursor<K, V> cursor = browse();
 
-        if ( serializer == null )
+        if ( keySerializer == null )
+        {
+            throw new RuntimeException( "Cannot flush the btree without a Key serializer" );
+        }
+
+        if ( valueSerializer == null )
         {
-            throw new RuntimeException( "Cannot flush the btree without a serializer" );
+            throw new RuntimeException( "Cannot flush the btree without a Value serializer" );
         }
 
         // Write the number of elements first
@@ -1087,11 +1049,11 @@ public class BTree<K, V>
         {
             Tuple<K, V> tuple = cursor.next();
 
-            byte[] keyBuffer = serializer.serializeKey( tuple.getKey() );
+            byte[] keyBuffer = keySerializer.serialize( tuple.getKey() );
 
             writeBuffer( ch, bb, keyBuffer );
 
-            byte[] valueBuffer = serializer.serializeValue( tuple.getValue() );
+            byte[] valueBuffer = valueSerializer.serialize( tuple.getValue() );
 
             writeBuffer( ch, bb, valueBuffer );
         }
@@ -1150,12 +1112,12 @@ public class BTree<K, V>
                 if ( type[0] == Modification.ADDITION )
                 {
                     // Read the key
-                    K key = serializer.deserializeKey( bufferHandler );
+                    K key = keySerializer.deserialize( bufferHandler );
 
                     //keys.add( key );
 
                     // Read the value
-                    V value = serializer.deserializeValue( bufferHandler );
+                    V value = valueSerializer.deserialize( bufferHandler );
 
                     //values.add( value );
 
@@ -1165,7 +1127,7 @@ public class BTree<K, V>
                 else
                 {
                     // Read the key
-                    K key = serializer.deserializeKey( bufferHandler );
+                    K key = keySerializer.deserialize( bufferHandler );
 
                     // Remove the key from the tree
                     delete( key, revision );
@@ -1219,12 +1181,12 @@ public class BTree<K, V>
         for ( long i = 0; i < nbElems; i++ )
         {
             // Read the key
-            K key = serializer.deserializeKey( bufferHandler );
+            K key = keySerializer.deserialize( bufferHandler );
 
             //keys.add( key );
 
             // Read the value
-            V value = serializer.deserializeValue( bufferHandler );
+            V value = valueSerializer.deserialize( bufferHandler );
 
             //values.add( value );
 

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTreeConfiguration.java Fri Feb  1 00:14:27 2013
@@ -20,9 +20,7 @@
 package org.apache.mavibot.btree;
 
 
-import java.util.Comparator;
-
-import org.apache.mavibot.btree.serializer.Serializer;
+import org.apache.mavibot.btree.serializer.ElementSerializer;
 
 
 /**
@@ -42,13 +40,11 @@ public class BTreeConfiguration<K, V>
     /** The size of the buffer used to write data in disk */
     private int writeBufferSize = BTree.DEFAULT_WRITE_BUFFER_SIZE;
 
-    /** Comparator used to order entries. */
-    private Comparator<K> comparator;
-
     /** The Key and Value serializer used for this tree. If none is provided, 
      * the BTree will deduce the serializer to use from the generic type, and
      * use the default Java serialization  */
-    private Serializer<K, V> serializer;
+    private ElementSerializer<K> keySerializer;
+    private ElementSerializer<V> valueSerializer;
 
     /** The path where the BTree file will be stored. Default to the local 
      * temporary directory.
@@ -94,56 +90,67 @@ public class BTreeConfiguration<K, V>
 
 
     /**
-     * @return the comparator
+     * @return the pageSize
      */
-    public Comparator<K> getComparator()
+    public int getPageSize()
     {
-        return comparator;
+        return pageSize;
     }
 
 
     /**
-     * @param comparator the comparator to set
+     * @param pageSize the pageSize to set
      */
-    public void setComparator( Comparator<K> comparator )
+    public void setPageSize( int pageSize )
     {
-        this.comparator = comparator;
+        this.pageSize = pageSize;
     }
 
 
     /**
-     * @return the pageSize
+     * @return the key serializer
      */
-    public int getPageSize()
+    public ElementSerializer<K> getKeySerializer()
     {
-        return pageSize;
+        return keySerializer;
     }
 
 
     /**
-     * @param pageSize the pageSize to set
+     * @return the value serializer
      */
-    public void setPageSize( int pageSize )
+    public ElementSerializer<V> getValueSerializer()
     {
-        this.pageSize = pageSize;
+        return valueSerializer;
+    }
+
+
+    /**
+     * @param keySerializer the key serializer to set
+     * @param valueSerializer the value serializer to set
+     */
+    public void setSerializers( ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
+    {
+        this.keySerializer = keySerializer;
+        this.valueSerializer = valueSerializer;
     }
 
 
     /**
-     * @return the serializer
+     * @param serializer the key serializer to set
      */
-    public Serializer<K, V> getSerializer()
+    public void setKeySerializer( ElementSerializer<K> keySerializer )
     {
-        return serializer;
+        this.keySerializer = keySerializer;
     }
 
 
     /**
-     * @param serializer the serializer to set
+     * @param serializer the key serializer to set
      */
-    public void setSerializer( Serializer<K, V> serializer )
+    public void setValueSerializer( ElementSerializer<V> valueSerializer )
     {
-        this.serializer = serializer;
+        this.valueSerializer = valueSerializer;
     }
 
 

Added: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanComparator.java?rev=1441274&view=auto
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanComparator.java (added)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/BooleanComparator.java Fri Feb  1 00:14:27 2013
@@ -0,0 +1,59 @@
+/*
+ *  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.mavibot.btree.comparator;
+
+
+import java.util.Comparator;
+
+
+/**
+ * Compares booleans
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class BooleanComparator implements Comparator<Boolean>
+{
+    /**
+     * Compare two booleans.
+     * 
+     * @param boolean1 First boolean
+     * @param boolean2 Second boolean
+     * @return 1 if boolean1 > boolean2, 0 if boolean1 == boolean2, -1 if boolean1 < boolean2
+     */
+    public int compare( Boolean boolean1, Boolean boolean2 )
+    {
+        if ( boolean1 == boolean2 )
+        {
+            return 0;
+        }
+
+        if ( boolean1 == null )
+        {
+            throw new IllegalArgumentException( "The first object to compare must not be null" );
+        }
+
+        if ( boolean2 == null )
+        {
+            throw new IllegalArgumentException( "The second object to compare must not be null" );
+        }
+
+        return boolean1.compareTo( boolean2 );
+    }
+}

Added: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ByteArrayComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ByteArrayComparator.java?rev=1441274&view=auto
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ByteArrayComparator.java (added)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ByteArrayComparator.java Fri Feb  1 00:14:27 2013
@@ -0,0 +1,94 @@
+/*
+ *  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.mavibot.btree.comparator;
+
+
+import java.util.Comparator;
+
+
+/**
+ * Compares byte arrays
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class ByteArrayComparator implements Comparator<byte[]>
+{
+    /**
+     * Compare two byte arrays.
+     * 
+     * @param byteArray1 First byteArray
+     * @param byteArray2 Second byteArray
+     * @return 1 if byteArray1 > byteArray2, 0 if byteArray1 == byteArray2, -1 if byteArray1 < byteArray2
+     */
+    public int compare( byte[] byteArray1, byte[] byteArray2 )
+    {
+        if ( byteArray1 == byteArray2 )
+        {
+            return 0;
+        }
+
+        if ( byteArray1 == null )
+        {
+            throw new IllegalArgumentException( "The first object to compare must not be null" );
+        }
+
+        if ( byteArray2 == null )
+        {
+            throw new IllegalArgumentException( "The second object to compare must not be null" );
+        }
+
+        if ( byteArray1.length < byteArray2.length )
+        {
+            return -1;
+        }
+
+        if ( byteArray1.length > byteArray2.length )
+        {
+            return 1;
+        }
+
+        for ( int pos = 0; pos < byteArray1.length; pos++ )
+        {
+            int comp = compare( byteArray1[pos], byteArray2[pos] );
+
+            if ( comp != 0 )
+            {
+                return comp;
+            }
+        }
+
+        return 0;
+    }
+
+
+    private int compare( byte byte1, byte byte2 )
+    {
+        if ( byte1 < byte2 )
+        {
+            return -1;
+        }
+        if ( byte1 > byte2 )
+        {
+            return 1;
+        }
+
+        return 0;
+    }
+}

Added: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ByteComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ByteComparator.java?rev=1441274&view=auto
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ByteComparator.java (added)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ByteComparator.java Fri Feb  1 00:14:27 2013
@@ -0,0 +1,59 @@
+/*
+ *  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.mavibot.btree.comparator;
+
+
+import java.util.Comparator;
+
+
+/**
+ * Compares bytes
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class ByteComparator implements Comparator<Byte>
+{
+    /**
+     * Compare two bytes.
+     * 
+     * @param byte1 First byte
+     * @param byte2 Second byte
+     * @return 1 if byte1 > byte2, 0 if byte1 == byte2, -1 if byte1 < byte2
+     */
+    public int compare( Byte byte1, Byte byte2 )
+    {
+        if ( byte1 == byte2 )
+        {
+            return 0;
+        }
+
+        if ( byte1 == null )
+        {
+            throw new IllegalArgumentException( "The first object to compare must not be null" );
+        }
+
+        if ( byte2 == null )
+        {
+            throw new IllegalArgumentException( "The second object to compare must not be null" );
+        }
+
+        return byte1.compareTo( byte2 );
+    }
+}

Added: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/CharComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/CharComparator.java?rev=1441274&view=auto
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/CharComparator.java (added)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/CharComparator.java Fri Feb  1 00:14:27 2013
@@ -0,0 +1,59 @@
+/*
+ *  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.mavibot.btree.comparator;
+
+
+import java.util.Comparator;
+
+
+/**
+ * Compares chars
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class CharComparator implements Comparator<Character>
+{
+    /**
+     * Compare two chars.
+     * 
+     * @param char1 First char
+     * @param char2 Second char
+     * @return 1 if char1 > char2, 0 if char1 == char2, -1 if char1 < char2
+     */
+    public int compare( Character char1, Character char2 )
+    {
+        if ( char1 == char2 )
+        {
+            return 0;
+        }
+
+        if ( char1 == null )
+        {
+            throw new IllegalArgumentException( "The first object to compare must not be null" );
+        }
+
+        if ( char2 == null )
+        {
+            throw new IllegalArgumentException( "The second object to compare must not be null" );
+        }
+
+        return char1.compareTo( char2 );
+    }
+}

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntComparator.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntComparator.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/IntComparator.java Fri Feb  1 00:14:27 2013
@@ -35,7 +35,7 @@ public class IntComparator implements Co
      * 
      * @param integer1 First integer
      * @param integer2 Second integer
-     * @return 1 if long1 > long2, 0 if long1 == long2, -1 if long1 < long2
+     * @return 1 if integer1 > integer2, 0 if integer1 == integer2, -1 if integer1 < integer2
      */
     public int compare( Integer integer1, Integer integer2 )
     {

Added: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ShortComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ShortComparator.java?rev=1441274&view=auto
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ShortComparator.java (added)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/ShortComparator.java Fri Feb  1 00:14:27 2013
@@ -0,0 +1,59 @@
+/*
+ *  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.mavibot.btree.comparator;
+
+
+import java.util.Comparator;
+
+
+/**
+ * Compares shorts
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class ShortComparator implements Comparator<Short>
+{
+    /**
+     * Compare two shorts.
+     * 
+     * @param short1 First short
+     * @param short2 Second short
+     * @return 1 if short1 > short2, 0 if short1 == short2, -1 if short1 < short2
+     */
+    public int compare( Short short1, Short short2 )
+    {
+        if ( short1 == short2 )
+        {
+            return 0;
+        }
+
+        if ( short1 == null )
+        {
+            throw new IllegalArgumentException( "The first object to compare must not be null" );
+        }
+
+        if ( short2 == null )
+        {
+            throw new IllegalArgumentException( "The second object to compare must not be null" );
+        }
+
+        return short1.compareTo( short2 );
+    }
+}

Added: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/StringComparator.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/StringComparator.java?rev=1441274&view=auto
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/StringComparator.java (added)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/comparator/StringComparator.java Fri Feb  1 00:14:27 2013
@@ -0,0 +1,59 @@
+/*
+ *  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.mavibot.btree.comparator;
+
+
+import java.util.Comparator;
+
+
+/**
+ * Compares Strings
+ * 
+ * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+ */
+public class StringComparator implements Comparator<String>
+{
+    /**
+     * Compare two Strings.
+     * 
+     * @param string1 First String
+     * @param string2 Second String
+     * @return 1 if string1 > String2, 0 if string1 == String2, -1 if string1 < String2
+     */
+    public int compare( String string1, String String2 )
+    {
+        if ( string1 == String2 )
+        {
+            return 0;
+        }
+
+        if ( string1 == null )
+        {
+            throw new IllegalArgumentException( "The first object to compare must not be null" );
+        }
+
+        if ( String2 == null )
+        {
+            throw new IllegalArgumentException( "The second object to compare must not be null" );
+        }
+
+        return string1.compareTo( String2 );
+    }
+}

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/BooleanSerializer.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/BooleanSerializer.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/BooleanSerializer.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/BooleanSerializer.java Fri Feb  1 00:14:27 2013
@@ -21,6 +21,9 @@ package org.apache.mavibot.btree.seriali
 
 
 import java.io.IOException;
+import java.util.Comparator;
+
+import org.apache.mavibot.btree.comparator.BooleanComparator;
 
 
 /**
@@ -30,6 +33,19 @@ import java.io.IOException;
  */
 public class BooleanSerializer implements ElementSerializer<Boolean>
 {
+    /** The associated comparator */
+    private final Comparator<Boolean> comparator;
+
+
+    /**
+     * Create a new instance of BooleanSerializer
+     */
+    public BooleanSerializer()
+    {
+        comparator = new BooleanComparator();
+    }
+
+
     /**
      * {@inheritDoc}
      */
@@ -61,10 +77,57 @@ public class BooleanSerializer implement
     /**
      * {@inheritDoc}
      */
+    @Override
     public Boolean deserialize( BufferHandler bufferHandler ) throws IOException
     {
         byte[] in = bufferHandler.read( 1 );
 
         return deserialize( in );
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int compare( Boolean type1, Boolean type2 )
+    {
+        if ( type1 == type2 )
+        {
+            return 0;
+        }
+
+        if ( type1 == null )
+        {
+            if ( type2 == null )
+            {
+                return 0;
+            }
+            else
+            {
+                return -1;
+            }
+        }
+        else
+        {
+            if ( type2 == null )
+            {
+                return 1;
+            }
+            else
+            {
+                return type1.compareTo( type2 );
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Comparator<Boolean> getComparator()
+    {
+        return comparator;
+    }
 }

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ByteArraySerializer.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ByteArraySerializer.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ByteArraySerializer.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ByteArraySerializer.java Fri Feb  1 00:14:27 2013
@@ -21,6 +21,9 @@ package org.apache.mavibot.btree.seriali
 
 
 import java.io.IOException;
+import java.util.Comparator;
+
+import org.apache.mavibot.btree.comparator.ByteArrayComparator;
 
 
 /**
@@ -30,6 +33,19 @@ import java.io.IOException;
  */
 public class ByteArraySerializer implements ElementSerializer<byte[]>
 {
+    /** The associated comparator */
+    private final Comparator<byte[]> comparator;
+
+
+    /**
+     * Create a new instance of ShortSerializer
+     */
+    public ByteArraySerializer()
+    {
+        comparator = new ByteArrayComparator();
+    }
+
+
     /**
      * {@inheritDoc}
      */
@@ -105,4 +121,97 @@ public class ByteArraySerializer impleme
                 return in;
         }
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int compare( byte[] type1, byte[] type2 )
+    {
+        if ( type1 == type2 )
+        {
+            return 0;
+        }
+
+        if ( type1 == null )
+        {
+            if ( type2 == null )
+            {
+                return 0;
+            }
+            else
+            {
+                return -1;
+            }
+        }
+        else
+        {
+            if ( type2 == null )
+            {
+                return 1;
+            }
+            else
+            {
+                if ( type1.length < type2.length )
+                {
+                    int pos = 0;
+
+                    for ( byte b1 : type1 )
+                    {
+                        byte b2 = type2[pos];
+
+                        if ( b1 == b2 )
+                        {
+                            pos++;
+                        }
+                        else if ( b1 < b2 )
+                        {
+                            return -1;
+                        }
+                        else
+                        {
+                            return 1;
+                        }
+                    }
+
+                    return 1;
+                }
+                else
+                {
+                    int pos = 0;
+
+                    for ( byte b2 : type2 )
+                    {
+                        byte b1 = type1[pos];
+
+                        if ( b1 == b2 )
+                        {
+                            pos++;
+                        }
+                        else if ( b1 < b2 )
+                        {
+                            return -1;
+                        }
+                        else
+                        {
+                            return 1;
+                        }
+                    }
+
+                    return -11;
+                }
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Comparator<byte[]> getComparator()
+    {
+        return comparator;
+    }
 }

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ByteSerializer.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ByteSerializer.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ByteSerializer.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ByteSerializer.java Fri Feb  1 00:14:27 2013
@@ -21,6 +21,9 @@ package org.apache.mavibot.btree.seriali
 
 
 import java.io.IOException;
+import java.util.Comparator;
+
+import org.apache.mavibot.btree.comparator.ByteComparator;
 
 
 /**
@@ -30,6 +33,19 @@ import java.io.IOException;
  */
 public class ByteSerializer implements ElementSerializer<Byte>
 {
+    /** The associated comparator */
+    private final Comparator<Byte> comparator;
+
+
+    /**
+     * Create a new instance of ByteSerializer
+     */
+    public ByteSerializer()
+    {
+        comparator = new ByteComparator();
+    }
+
+
     /**
      * {@inheritDoc}
      */
@@ -67,4 +83,50 @@ public class ByteSerializer implements E
 
         return deserialize( in );
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int compare( Byte type1, Byte type2 )
+    {
+        if ( type1 == type2 )
+        {
+            return 0;
+        }
+
+        if ( type1 == null )
+        {
+            if ( type2 == null )
+            {
+                return 0;
+            }
+            else
+            {
+                return -1;
+            }
+        }
+        else
+        {
+            if ( type2 == null )
+            {
+                return 1;
+            }
+            else
+            {
+                return type1.compareTo( type2 );
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Comparator<Byte> getComparator()
+    {
+        return comparator;
+    }
 }

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/CharSerializer.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/CharSerializer.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/CharSerializer.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/CharSerializer.java Fri Feb  1 00:14:27 2013
@@ -21,6 +21,9 @@ package org.apache.mavibot.btree.seriali
 
 
 import java.io.IOException;
+import java.util.Comparator;
+
+import org.apache.mavibot.btree.comparator.CharComparator;
 
 
 /**
@@ -30,6 +33,19 @@ import java.io.IOException;
  */
 public class CharSerializer implements ElementSerializer<Character>
 {
+    /** The associated comparator */
+    private final Comparator<Character> comparator;
+
+
+    /**
+     * Create a new instance of CharSerializer
+     */
+    public CharSerializer()
+    {
+        comparator = new CharComparator();
+    }
+
+
     /**
      * {@inheritDoc}
      */
@@ -71,4 +87,50 @@ public class CharSerializer implements E
 
         return deserialize( in );
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int compare( Character type1, Character type2 )
+    {
+        if ( type1 == type2 )
+        {
+            return 0;
+        }
+
+        if ( type1 == null )
+        {
+            if ( type2 == null )
+            {
+                return 0;
+            }
+            else
+            {
+                return -1;
+            }
+        }
+        else
+        {
+            if ( type2 == null )
+            {
+                return 1;
+            }
+            else
+            {
+                return type1.compareTo( type2 );
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Comparator<Character> getComparator()
+    {
+        return comparator;
+    }
 }

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ElementSerializer.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ElementSerializer.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ElementSerializer.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ElementSerializer.java Fri Feb  1 00:14:27 2013
@@ -21,12 +21,13 @@ package org.apache.mavibot.btree.seriali
 
 
 import java.io.IOException;
+import java.util.Comparator;
 
 
 /**
- * This interface is used by implementations elements serializers.
+ * This interface is used by implementations of serializer, deserializr and comparator.
  * 
- * @param <T> The type for the element
+ * @param <T> The type for the element to serialize and compare
  * 
  * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
  */
@@ -49,4 +50,25 @@ public interface ElementSerializer<T>
      * @throws IOException If the deserialization failed
      */
     T deserialize( BufferHandler bufferHandler ) throws IOException;
+
+
+    /**
+     * Returns the comparison of two types. <br/>
+     * <ul>
+     * <li>If type1 < type2, return -1</li>
+     * <li>If type1 > type2, return 1</li>
+     * <li>If type1 == type2, return 0</li>
+     * </ul>
+     * 
+     * @param type1 The first type to compare 
+     * @param type2 The second type to compare 
+     * @return The comparison result
+     */
+    int compare( T type1, T type2 );
+
+
+    /**
+     * @return the comparator for the used type
+     */
+    Comparator<T> getComparator();
 }

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/IntSerializer.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/IntSerializer.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/IntSerializer.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/IntSerializer.java Fri Feb  1 00:14:27 2013
@@ -21,6 +21,9 @@ package org.apache.mavibot.btree.seriali
 
 
 import java.io.IOException;
+import java.util.Comparator;
+
+import org.apache.mavibot.btree.comparator.IntComparator;
 
 
 /**
@@ -30,6 +33,19 @@ import java.io.IOException;
  */
 public class IntSerializer implements ElementSerializer<Integer>
 {
+    /** The associated comparator */
+    private final Comparator<Integer> comparator;
+
+
+    /**
+     * Create a new instance of IntSerializer
+     */
+    public IntSerializer()
+    {
+        comparator = new IntComparator();
+    }
+
+
     /**
      * {@inheritDoc}
      */
@@ -75,4 +91,50 @@ public class IntSerializer implements El
 
         return deserialize( in );
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int compare( Integer type1, Integer type2 )
+    {
+        if ( type1 == type2 )
+        {
+            return 0;
+        }
+
+        if ( type1 == null )
+        {
+            if ( type2 == null )
+            {
+                return 0;
+            }
+            else
+            {
+                return -1;
+            }
+        }
+        else
+        {
+            if ( type2 == null )
+            {
+                return 1;
+            }
+            else
+            {
+                return type1.compareTo( type2 );
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Comparator<Integer> getComparator()
+    {
+        return comparator;
+    }
 }

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/LongSerializer.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/LongSerializer.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/LongSerializer.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/LongSerializer.java Fri Feb  1 00:14:27 2013
@@ -21,6 +21,9 @@ package org.apache.mavibot.btree.seriali
 
 
 import java.io.IOException;
+import java.util.Comparator;
+
+import org.apache.mavibot.btree.comparator.LongComparator;
 
 
 /**
@@ -30,6 +33,19 @@ import java.io.IOException;
  */
 public class LongSerializer implements ElementSerializer<Long>
 {
+    /** The associated comparator */
+    private final Comparator<Long> comparator;
+
+
+    /**
+     * Create a new instance of LongSerializer
+     */
+    public LongSerializer()
+    {
+        comparator = new LongComparator();
+    }
+
+
     /**
      * {@inheritDoc}
      */
@@ -85,4 +101,50 @@ public class LongSerializer implements E
 
         return deserialize( in );
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int compare( Long type1, Long type2 )
+    {
+        if ( type1 == type2 )
+        {
+            return 0;
+        }
+
+        if ( type1 == null )
+        {
+            if ( type2 == null )
+            {
+                return 0;
+            }
+            else
+            {
+                return -1;
+            }
+        }
+        else
+        {
+            if ( type2 == null )
+            {
+                return 1;
+            }
+            else
+            {
+                return type1.compareTo( type2 );
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Comparator<Long> getComparator()
+    {
+        return comparator;
+    }
 }

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/Serializer.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/Serializer.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/Serializer.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/Serializer.java Fri Feb  1 00:14:27 2013
@@ -24,49 +24,44 @@ import java.io.IOException;
 
 
 /**
- * This interface is used by implementations of the key and value serializers.
+ * This interface is used by implementations of serializer, deserializr and comparator.
  * 
- * @param <K> The type for the keys
- * @param <V> The type for the stored values
+ * @param <T> The type for the element to serialize
  * 
  * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
  */
-public interface Serializer<K, V>
+public interface Serializer<T>
 {
     /**
-     * Produce the byte[] representation of the key
+     * Produce the byte[] representation of the type
      * 
-     * @param key The key to serialize
-     * @return The byte[] containing the serialized key
+     * @param type The type to serialize
+     * @return The byte[] containing the serialized type
      */
-    byte[] serializeKey( K key );
+    byte[] serialize( T type );
 
 
     /**
-     * Deserialize a key from a byte[]
+     * Deserialize a type from a byte[]
      * 
      * @param bufferHandler The incoming BufferHandler
-     * @return The deserialized key
+     * @return The deserialized type
      * @throws IOException If the deserialization failed
      */
-    K deserializeKey( BufferHandler bufferHandler ) throws IOException;
+    T deserialize( BufferHandler bufferHandler ) throws IOException;
 
 
     /**
-     * Produce the byte[] representation of the value
+     * Returns the comparison of two types. <br/>
+     * <ul>
+     * <li>If type1 < type2, return -1</li>
+     * <li>If type1 > type2, return 1</li>
+     * <li>If type1 == type2, return 0</li>
+     * </ul>
      * 
-     * @param value The value to serialize
-     * @return The byte[] containing the serialized value
+     * @param type1 The first type to compare 
+     * @param type2 The second type to compare 
+     * @return The comparison result
      */
-    byte[] serializeValue( V value );
-
-
-    /**
-     * Deserialize a value from a byte[]
-     * 
-     * @param bufferHandler The incoming BufferHandler
-     * @return The deserialized value
-     * @throws IOException If the deserialization failed
-     */
-    V deserializeValue( BufferHandler bufferHandler ) throws IOException;
+    int compare( T type1, T type2 );
 }

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ShortSerializer.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ShortSerializer.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ShortSerializer.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/ShortSerializer.java Fri Feb  1 00:14:27 2013
@@ -21,6 +21,9 @@ package org.apache.mavibot.btree.seriali
 
 
 import java.io.IOException;
+import java.util.Comparator;
+
+import org.apache.mavibot.btree.comparator.ShortComparator;
 
 
 /**
@@ -30,6 +33,19 @@ import java.io.IOException;
  */
 public class ShortSerializer implements ElementSerializer<Short>
 {
+    /** The associated comparator */
+    private final Comparator<Short> comparator;
+
+
+    /**
+     * Create a new instance of ShortSerializer
+     */
+    public ShortSerializer()
+    {
+        comparator = new ShortComparator();
+    }
+
+
     /**
      * {@inheritDoc}
      */
@@ -70,4 +86,50 @@ public class ShortSerializer implements 
 
         return deserialize( in );
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int compare( Short type1, Short type2 )
+    {
+        if ( type1 == type2 )
+        {
+            return 0;
+        }
+
+        if ( type1 == null )
+        {
+            if ( type2 == null )
+            {
+                return 0;
+            }
+            else
+            {
+                return -1;
+            }
+        }
+        else
+        {
+            if ( type2 == null )
+            {
+                return 1;
+            }
+            else
+            {
+                return type1.compareTo( type2 );
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Comparator<Short> getComparator()
+    {
+        return comparator;
+    }
 }

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/StringSerializer.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/StringSerializer.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/StringSerializer.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/serializer/StringSerializer.java Fri Feb  1 00:14:27 2013
@@ -22,6 +22,9 @@ package org.apache.mavibot.btree.seriali
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.util.Comparator;
+
+import org.apache.mavibot.btree.comparator.StringComparator;
 
 
 /**
@@ -31,6 +34,19 @@ import java.io.UnsupportedEncodingExcept
  */
 public class StringSerializer implements ElementSerializer<String>
 {
+    /** The associated comparator */
+    private final Comparator<String> comparator;
+
+
+    /**
+     * Create a new instance of StringSerializer
+     */
+    public StringSerializer()
+    {
+        comparator = new StringComparator();
+    }
+
+
     /**
      * {@inheritDoc}
      */
@@ -123,4 +139,50 @@ public class StringSerializer implements
                 }
         }
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int compare( String type1, String type2 )
+    {
+        if ( type1 == type2 )
+        {
+            return 0;
+        }
+
+        if ( type1 == null )
+        {
+            if ( type2 == null )
+            {
+                return 0;
+            }
+            else
+            {
+                return -1;
+            }
+        }
+        else
+        {
+            if ( type2 == null )
+            {
+                return 1;
+            }
+            else
+            {
+                return type1.compareTo( type2 );
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Comparator<String> getComparator()
+    {
+        return comparator;
+    }
 }

Modified: labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java (original)
+++ labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeConfigurationTest.java Fri Feb  1 00:14:27 2013
@@ -25,8 +25,8 @@ import static org.junit.Assert.assertNot
 import java.io.File;
 import java.io.IOException;
 
-import org.apache.mavibot.btree.comparator.IntComparator;
-import org.apache.mavibot.btree.serializer.DefaultSerializer;
+import org.apache.mavibot.btree.serializer.IntSerializer;
+import org.apache.mavibot.btree.serializer.StringSerializer;
 import org.junit.Test;
 
 
@@ -114,8 +114,7 @@ public class BTreeConfigurationTest
     {
         BTreeConfiguration<Integer, String> config = new BTreeConfiguration<Integer, String>();
         config.setPageSize( 32 );
-        config.setComparator( new IntComparator() );
-        config.setSerializer( new DefaultSerializer<Integer, String>( Integer.class, String.class ) );
+        config.setSerializers( new IntSerializer(), new StringSerializer() );
 
         // Create the BTree
         BTree<Integer, String> btree = new BTree<Integer, String>( config );
@@ -156,8 +155,7 @@ public class BTreeConfigurationTest
         {
             BTreeConfiguration<Integer, String> config = new BTreeConfiguration<Integer, String>();
             config.setPageSize( 32 );
-            config.setComparator( new IntComparator() );
-            config.setSerializer( new DefaultSerializer<Integer, String>( Integer.class, String.class ) );
+            config.setSerializers( new IntSerializer(), new StringSerializer() );
 
             config.setFilePath( parent );
             config.setFileName( "mavibot" );

Modified: labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java (original)
+++ labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java Fri Feb  1 00:14:27 2013
@@ -29,9 +29,9 @@ import java.io.IOException;
 import java.util.Random;
 import java.util.Set;
 
-import org.apache.mavibot.btree.comparator.IntComparator;
-import org.apache.mavibot.btree.comparator.LongComparator;
-import org.apache.mavibot.btree.serializer.DefaultSerializer;
+import org.apache.mavibot.btree.serializer.IntSerializer;
+import org.apache.mavibot.btree.serializer.LongSerializer;
+import org.apache.mavibot.btree.serializer.StringSerializer;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -126,8 +126,7 @@ public class BTreeFlushTest
         long delta = l1;
         int nbElems = 1000000;
 
-        BTree<Long, String> btree = new BTree<Long, String>( new LongComparator(),
-            new DefaultSerializer<Long, String>( Long.class, String.class ) );
+        BTree<Long, String> btree = new BTree<Long, String>( new LongSerializer(), new StringSerializer() );
         btree.setPageSize( 32 );
 
         for ( int i = 0; i < nbElems; i++ )
@@ -221,9 +220,6 @@ public class BTreeFlushTest
     public void testFlushBTree() throws Exception
     {
         // Create a BTree with pages containing 8 elements
-        DefaultSerializer<Integer, String> serializer = new DefaultSerializer<Integer, String>( Integer.class,
-            String.class );
-
         // Create the file, it will be deleted on exit
         File tempFile = File.createTempFile( "testFlush", null );
         String path = tempFile.getParent();
@@ -234,7 +230,8 @@ public class BTreeFlushTest
 
         try
         {
-            BTree<Integer, String> btree = new BTree<Integer, String>( path, fileName, new IntComparator(), serializer );
+            BTree<Integer, String> btree = new BTree<Integer, String>( path, fileName, new IntSerializer(),
+                new StringSerializer() );
             btree.setPageSize( 8 );
 
             // Inject the values
@@ -255,8 +252,8 @@ public class BTreeFlushTest
             assertEquals( 0, journal.length() );
 
             // Load the data into a new tree
-            BTree<Integer, String> btreeLoaded = new BTree<Integer, String>( path, fileName, new IntComparator(),
-                serializer );
+            BTree<Integer, String> btreeLoaded = new BTree<Integer, String>( path, fileName, new IntSerializer(),
+                new StringSerializer() );
             btree.setPageSize( 8 );
 
             Cursor<Integer, String> cursor1 = btree.browse();
@@ -297,9 +294,8 @@ public class BTreeFlushTest
         BTree<Long, String> btree = new BTree<Long, String>(
             dataFile.getParent(),
             dataFile.getName(),
-            new LongComparator(),
-            new DefaultSerializer<Long, String>( Long.class, String.class ) );
+            new LongSerializer(),
+            new StringSerializer() );
         btree.setPageSize( 32 );
-
     }
 }

Modified: labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/InMemoryBTreeTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/InMemoryBTreeTest.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/InMemoryBTreeTest.java (original)
+++ labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/InMemoryBTreeTest.java Fri Feb  1 00:14:27 2013
@@ -34,8 +34,9 @@ import java.util.List;
 import java.util.Random;
 import java.util.Set;
 
-import org.apache.mavibot.btree.comparator.IntComparator;
-import org.apache.mavibot.btree.comparator.LongComparator;
+import org.apache.mavibot.btree.serializer.IntSerializer;
+import org.apache.mavibot.btree.serializer.LongSerializer;
+import org.apache.mavibot.btree.serializer.StringSerializer;
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -162,7 +163,7 @@ public class InMemoryBTreeTest
 
         for ( int j = 0; j < nbTrees; j++ )
         {
-            BTree<Long, String> btree = new BTree<Long, String>( new LongComparator() );
+            BTree<Long, String> btree = new BTree<Long, String>( new LongSerializer(), new StringSerializer() );
             btree.setPageSize( 32 );
 
             for ( int i = 0; i < nbElems; i++ )
@@ -262,7 +263,7 @@ public class InMemoryBTreeTest
 
         for ( int j = 0; j < nbTrees; j++ )
         {
-            BTree<Long, String> btree = new BTree<Long, String>( new LongComparator() );
+            BTree<Long, String> btree = new BTree<Long, String>( new LongSerializer(), new StringSerializer() );
             btree.setPageSize( 8 );
 
             for ( int i = 0; i < nbElems; i++ )
@@ -374,7 +375,7 @@ public class InMemoryBTreeTest
                 368, 245, 1005, 226, 939, 320, 396, 437, 373, 61
         };
 
-        BTree<Long, String> btree = new BTree<Long, String>( new LongComparator() );
+        BTree<Long, String> btree = new BTree<Long, String>( new LongSerializer(), new StringSerializer() );
         btree.setPageSize( 8 );
 
         for ( long value : values )
@@ -435,7 +436,7 @@ public class InMemoryBTreeTest
 
         Random random = new Random( System.nanoTime() );
 
-        BTree<Long, String> btree = new BTree<Long, String>( new LongComparator() );
+        BTree<Long, String> btree = new BTree<Long, String>( new LongSerializer(), new StringSerializer() );
         btree.setPageSize( 8 );
 
         // Insert some values
@@ -491,7 +492,7 @@ public class InMemoryBTreeTest
     @Ignore
     public void testPageInsertDebug() throws Exception
     {
-        BTree<Long, String> btree = new BTree<Long, String>( new LongComparator() );
+        BTree<Long, String> btree = new BTree<Long, String>( new LongSerializer(), new StringSerializer() );
         btree.setPageSize( 4 );
 
         Long[] elems = new Long[]
@@ -593,7 +594,7 @@ public class InMemoryBTreeTest
     public void testBrowseForward() throws Exception
     {
         // Create a BTree with pages containing 8 elements
-        BTree<Integer, String> btree = new BTree<Integer, String>( new IntComparator() );
+        BTree<Integer, String> btree = new BTree<Integer, String>( new IntSerializer(), new StringSerializer() );
         btree.setPageSize( 8 );
 
         // Inject the values
@@ -677,7 +678,7 @@ public class InMemoryBTreeTest
     public void testBrowseBackward() throws Exception
     {
         // Create a BTree with pages containing 8 elements
-        BTree<Integer, String> btree = new BTree<Integer, String>( new IntComparator() );
+        BTree<Integer, String> btree = new BTree<Integer, String>( new IntSerializer(), new StringSerializer() );
         btree.setPageSize( 8 );
 
         // Inject the values
@@ -752,7 +753,7 @@ public class InMemoryBTreeTest
     public void testBrowseEmptyTree() throws Exception
     {
         // Create a BTree with pages containing 8 elements
-        BTree<Integer, String> btree = new BTree<Integer, String>( new IntComparator() );
+        BTree<Integer, String> btree = new BTree<Integer, String>( new IntSerializer(), new StringSerializer() );
         btree.setPageSize( 8 );
 
         Cursor<Integer, String> cursor = btree.browse();
@@ -772,7 +773,7 @@ public class InMemoryBTreeTest
     public void testBrowseForwardBackward() throws Exception
     {
         // Create a BTree with pages containing 4 elements
-        BTree<Integer, String> btree = new BTree<Integer, String>( new IntComparator() );
+        BTree<Integer, String> btree = new BTree<Integer, String>( new IntSerializer(), new StringSerializer() );
         btree.setPageSize( 4 );
 
         for ( int i = 0; i < 16; i++ )
@@ -988,7 +989,7 @@ public class InMemoryBTreeTest
      */
     private BTree<Integer, String> createTwoLevelBTreeFullLeaves() throws IOException
     {
-        BTree<Integer, String> btree = new BTree<Integer, String>( new IntComparator() );
+        BTree<Integer, String> btree = new BTree<Integer, String>( new IntSerializer(), new StringSerializer() );
         btree.setPageSize( 4 );
 
         // Create a tree with 5 children containing 4 elements each. The tree is full.
@@ -1010,7 +1011,7 @@ public class InMemoryBTreeTest
      */
     private BTree<Integer, String> createTwoLevelBTreeHalfFullLeaves() throws IOException
     {
-        BTree<Integer, String> btree = new BTree<Integer, String>( new IntComparator() );
+        BTree<Integer, String> btree = new BTree<Integer, String>( new IntSerializer(), new StringSerializer() );
         btree.setPageSize( 4 );
 
         // Create a tree with 5 children containing 4 elements each. The tree is full.
@@ -1041,7 +1042,8 @@ public class InMemoryBTreeTest
         // Create a BTree with pages containing 4 elements
         int pageSize = 4;
 
-        BTree<Integer, String> btree = new BTree<Integer, String>( new IntComparator(), pageSize );
+        BTree<Integer, String> btree = new BTree<Integer, String>( new IntSerializer(), new StringSerializer(),
+            pageSize );
 
         Node<Integer, String> root = new Node<Integer, String>( btree, 1L, pageSize );
 
@@ -1627,7 +1629,7 @@ public class InMemoryBTreeTest
         long delta = System.currentTimeMillis();
 
         // Create a BTree with 5 million entries
-        BTree<Long, String> btree = new BTree<Long, String>( new LongComparator() );
+        BTree<Long, String> btree = new BTree<Long, String>( new LongSerializer(), new StringSerializer() );
         btree.setPageSize( 32 );
 
         for ( int i = 0; i < nbElems; i++ )

Modified: labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/LeafTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/LeafTest.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/LeafTest.java (original)
+++ labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/LeafTest.java Fri Feb  1 00:14:27 2013
@@ -26,7 +26,8 @@ import static org.junit.Assert.assertTru
 
 import java.io.IOException;
 
-import org.apache.mavibot.btree.comparator.LongComparator;
+import org.apache.mavibot.btree.serializer.LongSerializer;
+import org.apache.mavibot.btree.serializer.StringSerializer;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -48,7 +49,7 @@ public class LeafTest
     @Before
     public void setup() throws IOException
     {
-        btree = new BTree<Long, String>( new LongComparator() );
+        btree = new BTree<Long, String>( new LongSerializer(), new StringSerializer() );
         btree.setPageSize( 8 );
     }
 

Modified: labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/MultiThreadedBtreeTest.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/MultiThreadedBtreeTest.java?rev=1441274&r1=1441273&r2=1441274&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/MultiThreadedBtreeTest.java (original)
+++ labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/MultiThreadedBtreeTest.java Fri Feb  1 00:14:27 2013
@@ -26,7 +26,8 @@ import java.io.IOException;
 import java.util.Random;
 import java.util.concurrent.CountDownLatch;
 
-import org.apache.mavibot.btree.comparator.LongComparator;
+import org.apache.mavibot.btree.serializer.LongSerializer;
+import org.apache.mavibot.btree.serializer.StringSerializer;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -50,7 +51,7 @@ public class MultiThreadedBtreeTest
     @BeforeClass
     public static void setup() throws IOException
     {
-        btree = new BTree<Long, String>( new LongComparator() );
+        btree = new BTree<Long, String>( new LongSerializer(), new StringSerializer() );
     }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org