directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1550673 [2/2] - in /directory/mavibot/trunk/mavibot/src: main/java/org/apache/directory/mavibot/btree/ main/java/org/apache/directory/mavibot/btree/managed/ main/java/org/apache/directory/mavibot/btree/memory/ test/java/org/apache/director...
Date Fri, 13 Dec 2013 10:13:22 GMT
Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Leaf.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Leaf.java?rev=1550673&r1=1550672&r2=1550673&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Leaf.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Leaf.java Fri Dec 13 10:13:21 2013
@@ -50,7 +50,7 @@ import org.apache.directory.mavibot.btre
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-/* No qualifier */class Leaf<K, V> extends AbstractPage<K, V>
+/* No qualifier */class Leaf<K, V> extends AbstractInMemoryPage<K, V>
 {
     /** Values associated with keys */
     protected ValueHolder<V>[] values;
@@ -164,7 +164,7 @@ import org.apache.directory.mavibot.btre
         if ( value == null )
         {
             // we have to delete the whole value
-            removedElement = new Tuple<K, V>( keys[index], valueHolder.getCursor().next() ); // the entire value was removed
+            removedElement = new Tuple<K, V>( getKey( index ), valueHolder.getCursor().next() ); // the entire value was removed
             keyRemoved = true;
         }
         else
@@ -175,14 +175,14 @@ import org.apache.directory.mavibot.btre
                 if ( valueHolder.size() == 1 ) 
                 {
                     // Ok, we can remove the value
-                    removedElement = new Tuple<K, V>( keys[index], null ); // the entire value was removed
+                    removedElement = new Tuple<K, V>( getKey( index ), null ); // the entire value was removed
                     keyRemoved = true;
                 }
                 else
                 {
                     // Update the ValueHolder
                     valueHolder.remove( value );
-                    removedElement = new Tuple<K, V>( keys[index], value ); // the entire value was removed
+                    removedElement = new Tuple<K, V>( getKey( index ), value ); // the entire value was removed
                 }
             }
             else
@@ -276,7 +276,7 @@ import org.apache.directory.mavibot.btre
         {
             // Last, not least : we can copy the full page
             // Copy the keys and the values
-            System.arraycopy( keys, 0, newLeaf.keys, 0, nbElems );
+            System.arraycopy( getKeys(), 0, newLeaf.getKeys(), 0, nbElems );
             System.arraycopy( values, 0, newLeaf.values, 0, nbElems );
 
             // The current page is added in the copied page list
@@ -309,30 +309,30 @@ import org.apache.directory.mavibot.btre
         {
             // The sibling is on the left
             // Copy all the elements from the sibling first
-            System.arraycopy( sibling.keys, 0, newLeaf.keys, 0, sibling.nbElems );
+            System.arraycopy( sibling.getKeys(), 0, newLeaf.getKeys(), 0, sibling.nbElems );
             System.arraycopy( sibling.values, 0, newLeaf.values, 0, sibling.nbElems );
 
             // Copy all the elements from the page up to the deletion position
-            System.arraycopy( keys, 0, newLeaf.keys, sibling.nbElems, pos );
+            System.arraycopy( getKeys(), 0, newLeaf.getKeys(), sibling.nbElems, pos );
             System.arraycopy( values, 0, newLeaf.values, sibling.nbElems, pos );
 
             // And copy the remaining elements after the deletion point
-            System.arraycopy( keys, pos + 1, newLeaf.keys, sibling.nbElems + pos, nbElems - pos - 1 );
+            System.arraycopy( getKeys(), pos + 1, newLeaf.getKeys(), sibling.nbElems + pos, nbElems - pos - 1 );
             System.arraycopy( values, pos + 1, newLeaf.values, sibling.nbElems + pos, nbElems - pos - 1 );
         }
         else
         {
             // The sibling is on the right
             // Copy all the elements from the page up to the deletion position
-            System.arraycopy( keys, 0, newLeaf.keys, 0, pos );
+            System.arraycopy( getKeys(), 0, newLeaf.getKeys(), 0, pos );
             System.arraycopy( values, 0, newLeaf.values, 0, pos );
 
             // Then copy the remaining elements after the deletion point
-            System.arraycopy( keys, pos + 1, newLeaf.keys, pos, nbElems - pos - 1 );
+            System.arraycopy( getKeys(), pos + 1, newLeaf.getKeys(), pos, nbElems - pos - 1 );
             System.arraycopy( values, pos + 1, newLeaf.values, pos, nbElems - pos - 1 );
 
             // And copy all the elements from the sibling
-            System.arraycopy( sibling.keys, 0, newLeaf.keys, nbElems - 1, sibling.nbElems );
+            System.arraycopy( sibling.getKeys(), 0, newLeaf.getKeys(), nbElems - 1, sibling.nbElems );
             System.arraycopy( sibling.values, 0, newLeaf.values, nbElems - 1, sibling.nbElems );
         }
 
@@ -362,7 +362,7 @@ import org.apache.directory.mavibot.btre
         throws IOException
     {
         // The sibling is on the left, borrow the rightmost element
-        K siblingKey = sibling.keys[sibling.getNbElems() - 1];
+        K siblingKey = sibling.getKey( sibling.getNbElems() - 1 );
         ValueHolder<V> siblingValue = sibling.values[sibling.getNbElems() - 1];
 
         // Create the new sibling, with one less element at the end
@@ -373,15 +373,15 @@ import org.apache.directory.mavibot.btre
         Leaf<K, V> newLeaf = new Leaf<K, V>( btree, revision, nbElems );
 
         // Insert the borrowed element
-        newLeaf.keys[0] = siblingKey;
+        newLeaf.setKey( 0, siblingKey );
         newLeaf.values[0] = siblingValue;
 
         // Copy the keys and the values up to the insertion position,
-        System.arraycopy( keys, 0, newLeaf.keys, 1, pos );
+        System.arraycopy( getKeys(), 0, newLeaf.getKeys(), 1, pos );
         System.arraycopy( values, 0, newLeaf.values, 1, pos );
 
         // And copy the remaining elements
-        System.arraycopy( keys, pos + 1, newLeaf.keys, pos + 1, keys.length - pos - 1 );
+        System.arraycopy( getKeys(), pos + 1, newLeaf.getKeys(), pos + 1, getKeys().length - pos - 1 );
         System.arraycopy( values, pos + 1, newLeaf.values, pos + 1, values.length - pos - 1 );
 
         DeleteResult<K, V> result = new BorrowedFromLeftResult<K, V>( newLeaf, newSibling, removedElement );
@@ -409,14 +409,14 @@ import org.apache.directory.mavibot.btre
         throws IOException
     {
         // The sibling is on the left, borrow the rightmost element
-        K siblingKey = sibling.keys[0];
+        K siblingKey = sibling.getKey( 0 );
         ValueHolder<V> siblingHolder = sibling.values[0];
 
         // Create the new sibling
         Leaf<K, V> newSibling = new Leaf<K, V>( btree, revision, sibling.getNbElems() - 1 );
 
         // Copy the keys and the values from 1 to N in the new sibling
-        System.arraycopy( sibling.keys, 1, newSibling.keys, 0, sibling.nbElems - 1 );
+        System.arraycopy( sibling.getKeys(), 1, newSibling.getKeys(), 0, sibling.nbElems - 1 );
         System.arraycopy( sibling.values, 1, newSibling.values, 0, sibling.nbElems - 1 );
 
         // Create the new page and add the new element at the end
@@ -424,15 +424,15 @@ import org.apache.directory.mavibot.btre
         Leaf<K, V> newLeaf = new Leaf<K, V>( btree, revision, nbElems );
 
         // Insert the borrowed element at the end
-        newLeaf.keys[nbElems - 1] = siblingKey;
+        newLeaf.setKey( nbElems - 1, siblingKey );
         newLeaf.values[nbElems - 1] = siblingHolder;
 
         // Copy the keys and the values up to the deletion position,
-        System.arraycopy( keys, 0, newLeaf.keys, 0, pos );
+        System.arraycopy( getKeys(), 0, newLeaf.getKeys(), 0, pos );
         System.arraycopy( values, 0, newLeaf.values, 0, pos );
 
         // And copy the remaining elements
-        System.arraycopy( keys, pos + 1, newLeaf.keys, pos, keys.length - pos - 1 );
+        System.arraycopy( getKeys(), pos + 1, newLeaf.getKeys(), pos, getKeys().length - pos - 1 );
         System.arraycopy( values, pos + 1, newLeaf.values, pos, values.length - pos - 1 );
 
         DeleteResult<K, V> result = new BorrowedFromRightResult<K, V>( newLeaf, newSibling, removedElement );
@@ -465,17 +465,17 @@ import org.apache.directory.mavibot.btre
             }
 
             // Copy the keys and the values up to the insertion position
-            System.arraycopy( keys, 0, newLeaf.keys, 0, pos );
+            System.arraycopy( getKeys(), 0, newLeaf.getKeys(), 0, pos );
             System.arraycopy( values, 0, newLeaf.values, 0, pos );
 
             // And copy the elements after the position
-            System.arraycopy( keys, pos + 1, newLeaf.keys, pos, keys.length - pos - 1 );
+            System.arraycopy( getKeys(), pos + 1, newLeaf.getKeys(), pos, getKeys().length - pos - 1 );
             System.arraycopy( values, pos + 1, newLeaf.values, pos, values.length - pos - 1 );
         }
         else
         // one of the many values of the same key was removed, no change in the number of keys
         {
-            System.arraycopy( keys, 0, newLeaf.keys, 0, nbElems );
+            System.arraycopy( getKeys(), 0, newLeaf.getKeys(), 0, nbElems );
             System.arraycopy( values, 0, newLeaf.values, 0, nbElems );
         }
     }
@@ -610,7 +610,7 @@ import org.apache.directory.mavibot.btre
 
             stack[depth] = parentPos;
 
-            cursor = new TupleCursorImpl<K, V>( btree, transaction, stack, depth );
+            cursor = new TupleCursorImpl<K, V>( transaction, stack, depth );
         }
         else
         {
@@ -624,7 +624,7 @@ import org.apache.directory.mavibot.btre
                 
                 stack[depth] = parentPos;
 
-                cursor = new TupleCursorImpl<K, V>( btree, transaction, stack, depth );
+                cursor = new TupleCursorImpl<K, V>( transaction, stack, depth );
             }
             else if ( nbElems > 0 )
             {
@@ -636,7 +636,7 @@ import org.apache.directory.mavibot.btre
                 
                 stack[depth] = parentPos;
 
-                cursor = new TupleCursorImpl<K, V>( btree, transaction, stack, depth );
+                cursor = new TupleCursorImpl<K, V>( transaction, stack, depth );
                 
                 try
                 {
@@ -653,7 +653,7 @@ import org.apache.directory.mavibot.btre
                 // Not found, because there are no elements : return a null cursor
                 stack[depth] = null;
 
-                cursor = new TupleCursorImpl<K, V>( btree, transaction, null, 0 );
+                cursor = new TupleCursorImpl<K, V>( transaction, null, 0 );
             }
         }
 
@@ -674,7 +674,7 @@ import org.apache.directory.mavibot.btre
             // The tree is empty, it's the root, we have nothing to return
             stack[depth] = new ParentPos<K, V>( null, -1 );
 
-            return new TupleCursorImpl<K, V>( btree, transaction, stack, depth );
+            return new TupleCursorImpl<K, V>( transaction, stack, depth );
         }
         else
         {
@@ -686,7 +686,7 @@ import org.apache.directory.mavibot.btre
 
             stack[depth] = parentPos;
 
-            cursor = new TupleCursorImpl<K, V>( btree, transaction, stack, depth );
+            cursor = new TupleCursorImpl<K, V>( transaction, stack, depth );
         }
 
         return cursor;
@@ -705,7 +705,7 @@ import org.apache.directory.mavibot.btre
         Leaf<K, V> newLeaf = new Leaf<K, V>( btree, revision, nbElems );
 
         // Copy the keys and the values
-        System.arraycopy( keys, 0, newLeaf.keys, 0, nbElems );
+        System.arraycopy( getKeys(), 0, newLeaf.getKeys(), 0, nbElems );
         System.arraycopy( values, 0, newLeaf.values, 0, nbElems );
 
         return newLeaf;
@@ -780,22 +780,21 @@ import org.apache.directory.mavibot.btre
         // Deal with the special case of an empty page
         if ( nbElems == 0 )
         {
-            newLeaf.keys[0] = key;
-
+            newLeaf.setKey( 0, key );
             newLeaf.values[0] = valueHolder;
         }
         else
         {
             // Copy the keys and the values up to the insertion position
-            System.arraycopy( keys, 0, newLeaf.keys, 0, pos );
+            System.arraycopy( getKeys(), 0, newLeaf.getKeys(), 0, pos );
             System.arraycopy( values, 0, newLeaf.values, 0, pos );
 
             // Add the new element
-            newLeaf.keys[pos] = key;
+            newLeaf.setKey( pos, key );
             newLeaf.values[pos] = valueHolder;
 
             // And copy the remaining elements
-            System.arraycopy( keys, pos, newLeaf.keys, pos + 1, keys.length - pos );
+            System.arraycopy( getKeys(), pos, newLeaf.getKeys(), pos + 1, getKeys().length - pos );
             System.arraycopy( values, pos, newLeaf.values, pos + 1, values.length - pos );
         }
 
@@ -832,22 +831,22 @@ import org.apache.directory.mavibot.btre
             leftLeaf = new Leaf<K, V>( btree, revision, middle + 1 );
 
             // Copy the keys and the values up to the insertion position
-            System.arraycopy( keys, 0, leftLeaf.keys, 0, pos );
+            System.arraycopy( getKeys(), 0, leftLeaf.getKeys(), 0, pos );
             System.arraycopy( values, 0, leftLeaf.values, 0, pos );
 
             // Add the new element
-            leftLeaf.keys[pos] = key;
+            leftLeaf.setKey( pos, key );
             leftLeaf.values[pos] = valueHolder;
 
             // And copy the remaining elements
-            System.arraycopy( keys, pos, leftLeaf.keys, pos + 1, middle - pos );
+            System.arraycopy( getKeys(), pos, leftLeaf.getKeys(), pos + 1, middle - pos );
             System.arraycopy( values, pos, leftLeaf.values, pos + 1, middle - pos );
 
             // Now, create the right page
             rightLeaf = new Leaf<K, V>( btree, revision, middle );
 
             // Copy the keys and the values in the right page
-            System.arraycopy( keys, middle, rightLeaf.keys, 0, middle );
+            System.arraycopy( getKeys(), middle, rightLeaf.getKeys(), 0, middle );
             System.arraycopy( values, middle, rightLeaf.values, 0, middle );
         }
         else
@@ -856,7 +855,7 @@ import org.apache.directory.mavibot.btre
             leftLeaf = new Leaf<K, V>( btree, revision, middle );
 
             // Copy all the element into the left page
-            System.arraycopy( keys, 0, leftLeaf.keys, 0, middle );
+            System.arraycopy( getKeys(), 0, leftLeaf.getKeys(), 0, middle );
             System.arraycopy( values, 0, leftLeaf.values, 0, middle );
 
             // Now, create the right page
@@ -865,20 +864,20 @@ import org.apache.directory.mavibot.btre
             int rightPos = pos - middle;
 
             // Copy the keys and the values up to the insertion position
-            System.arraycopy( keys, middle, rightLeaf.keys, 0, rightPos );
+            System.arraycopy( getKeys(), middle, rightLeaf.getKeys(), 0, rightPos );
             System.arraycopy( values, middle, rightLeaf.values, 0, rightPos );
 
             // Add the new element
-            rightLeaf.keys[rightPos] = key;
+            rightLeaf.setKey( rightPos, key );
             rightLeaf.values[rightPos] = valueHolder;
 
             // And copy the remaining elements
-            System.arraycopy( keys, pos, rightLeaf.keys, rightPos + 1, nbElems - pos );
+            System.arraycopy( getKeys(), pos, rightLeaf.getKeys(), rightPos + 1, nbElems - pos );
             System.arraycopy( values, pos, rightLeaf.values, rightPos + 1, nbElems - pos );
         }
 
         // Get the pivot
-        K pivot = rightLeaf.keys[0];
+        K pivot = rightLeaf.getKey( 0 );
 
         // Create the result
         InsertResult<K, V> result = new SplitResult<K, V>( pivot, leftLeaf, rightLeaf );
@@ -890,31 +889,13 @@ import org.apache.directory.mavibot.btre
     /**
      * {@inheritDoc}
      */
-    public K getLeftMostKey()
-    {
-        return keys[0];
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public K getRightMostKey()
-    {
-        return keys[nbElems - 1];
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
     public Tuple<K, V> findLeftMost() throws IOException
     {
         V val = null;
 
         val = values[0].getCursor().next();
 
-        return new Tuple<K, V>( keys[0], val );
+        return new Tuple<K, V>( getKey( 0 ), val );
     }
 
 
@@ -929,7 +910,7 @@ import org.apache.directory.mavibot.btre
         valueCursor.afterLast();
         val = valueCursor.prev();
 
-        return new Tuple<K, V>( keys[nbElems - 1], val );
+        return new Tuple<K, V>( getKey( nbElems - 1 ), val );
     }
 
 
@@ -960,7 +941,7 @@ import org.apache.directory.mavibot.btre
                     sb.append( ", " );
                 }
 
-                sb.append( "<" ).append( keys[i] ).append( "," ).append( values[i] ).append( ">" );
+                sb.append( "<" ).append( getKey( i ) ).append( "," ).append( values[i] ).append( ">" );
             }
         }
 
@@ -994,7 +975,7 @@ import org.apache.directory.mavibot.btre
                     sb.append( ", " );
                 }
 
-                sb.append( "<" ).append( keys[i] ).append( "," ).append( values[i] ).append( ">" );
+                sb.append( "<" ).append( getKey( i) ).append( "," ).append( values[i] ).append( ">" );
             }
         }
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java?rev=1550673&r1=1550672&r2=1550673&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java Fri Dec 13 10:13:21 2013
@@ -30,6 +30,7 @@ import org.apache.directory.mavibot.btre
 import org.apache.directory.mavibot.btree.BorrowedFromSiblingResult;
 import org.apache.directory.mavibot.btree.DeleteResult;
 import org.apache.directory.mavibot.btree.InsertResult;
+import org.apache.directory.mavibot.btree.KeyHolder;
 import org.apache.directory.mavibot.btree.ModifyResult;
 import org.apache.directory.mavibot.btree.NotPresentResult;
 import org.apache.directory.mavibot.btree.Page;
@@ -53,7 +54,7 @@ import org.apache.directory.mavibot.btre
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-/* No qualifier */class Node<K, V> extends AbstractPage<K, V>
+/* No qualifier */class Node<K, V> extends AbstractInMemoryPage<K, V>
 {
     /** Children pages associated with keys. */
     protected Page<K, V>[] children;
@@ -104,10 +105,9 @@ import org.apache.directory.mavibot.btre
         // Create the keys array and store the pivot into it
         // We get the type of array to create from the btree
         // Yes, this is an hack...
-        Class<?> keyType = btree.getKeyType();
-        keys = ( K[] ) Array.newInstance( keyType, btree.getPageSize() );
+        setKeys( ( KeyHolder<K>[] ) Array.newInstance( KeyHolder.class, btree.getPageSize() ) );
 
-        keys[0] = key;
+        setKey( 0, key );
     }
 
 
@@ -199,7 +199,7 @@ import org.apache.directory.mavibot.btre
 
         if ( pos < 0 )
         {
-            newPage.keys[index] = removeResult.getModifiedPage().getLeftMostKey();
+            newPage.setKey( index, removeResult.getModifiedPage().getLeftMostKey() );
         }
 
         // Modify the result and return
@@ -264,7 +264,7 @@ import org.apache.directory.mavibot.btre
         K siblingKey = sibling.children[0].getLeftMostKey();
 
         // Copy the keys and children of the old sibling in the new sibling
-        System.arraycopy( sibling.keys, 1, newSibling.keys, 0, newSibling.getNbElems() );
+        System.arraycopy( sibling.getKeys(), 1, newSibling.getKeys(), 0, newSibling.getNbElems() );
         System.arraycopy( sibling.children, 1, newSibling.children, 0, newSibling.getNbElems() + 1 );
 
         // Create the new page and add the new element at the end
@@ -275,13 +275,13 @@ import org.apache.directory.mavibot.btre
         int index = Math.abs( pos );
 
         // Copy the key and children from sibling
-        newNode.keys[nbElems - 1] = siblingKey; // 1
+        newNode.setKey( nbElems - 1, siblingKey ); // 1
         newNode.children[nbElems] = sibling.children[0]; // 8
 
         if ( index < 2 )
         {
             // Copy the keys
-            System.arraycopy( keys, 1, newNode.keys, 0, nbElems - 1 );
+            System.arraycopy( getKeys(), 1, newNode.getKeys(), 0, nbElems - 1 );
 
             // Inject the modified page
             Page<K, V> modifiedPage = mergedResult.getModifiedPage();
@@ -295,16 +295,16 @@ import org.apache.directory.mavibot.btre
             if ( index > 2 )
             {
                 // Copy the keys before the deletion point
-                System.arraycopy( keys, 0, newNode.keys, 0, index - 2 ); // 4
+                System.arraycopy( getKeys(), 0, newNode.getKeys(), 0, index - 2 ); // 4
             }
 
             // Inject the new modified page key
-            newNode.keys[index - 2] = mergedResult.getModifiedPage().getLeftMostKey(); // 2
+            newNode.setKey( index - 2, mergedResult.getModifiedPage().getLeftMostKey() ); // 2
 
             if ( index < nbElems )
             {
                 // Copy the remaining keys after the deletion point
-                System.arraycopy( keys, index, newNode.keys, index - 1, nbElems - index ); // 3
+                System.arraycopy( getKeys(), index, newNode.getKeys(), index - 1, nbElems - index ); // 3
 
                 // Copy the remaining children after the deletion point
                 System.arraycopy( children, index + 1, newNode.children, index, nbElems - index ); // 7
@@ -350,7 +350,7 @@ import org.apache.directory.mavibot.btre
         Node<K, V> newSibling = new Node<K, V>( btree, revision, sibling.getNbElems() - 1 );
 
         // Copy the keys and children of the old sibling in the new sibling
-        System.arraycopy( sibling.keys, 0, newSibling.keys, 0, newSibling.getNbElems() );
+        System.arraycopy( sibling.getKeys(), 0, newSibling.getKeys(), 0, newSibling.getNbElems() );
         System.arraycopy( sibling.children, 0, newSibling.children, 0, newSibling.getNbElems() + 1 );
 
         // Create the new page and add the new element at the beginning
@@ -364,8 +364,8 @@ import org.apache.directory.mavibot.btre
 
         if ( index < 2 )
         {
-            newNode.keys[0] = mergedResult.getModifiedPage().getLeftMostKey();
-            System.arraycopy( keys, 1, newNode.keys, 1, nbElems - 1 );
+            newNode.setKey( 0, mergedResult.getModifiedPage().getLeftMostKey() );
+            System.arraycopy( getKeys(), 1, newNode.getKeys(), 1, nbElems - 1 );
 
             Page<K, V> modifiedPage = mergedResult.getModifiedPage();
             newNode.children[1] = modifiedPage;
@@ -374,21 +374,21 @@ import org.apache.directory.mavibot.btre
         else
         {
             // Set the first key
-            newNode.keys[0] = children[0].getLeftMostKey(); //2
+            newNode.setKey( 0, children[0].getLeftMostKey() ); //2
 
             if ( index > 2 )
             {
                 // Copy the keys before the deletion point
-                System.arraycopy( keys, 0, newNode.keys, 1, index - 2 ); // 4
+                System.arraycopy( getKeys(), 0, newNode.getKeys(), 1, index - 2 ); // 4
             }
 
             // Inject the modified key
-            newNode.keys[index - 1] = mergedResult.getModifiedPage().getLeftMostKey(); // 3
+            newNode.setKey( index - 1, mergedResult.getModifiedPage().getLeftMostKey() ); // 3
 
             if ( index < nbElems )
             {
                 // Add copy the remaining keys after the deletion point
-                System.arraycopy( keys, index, newNode.keys, index, nbElems - index ); // 5
+                System.arraycopy( getKeys(), index, newNode.getKeys(), index, nbElems - index ); // 5
 
                 // Copy the remaining children after the insertion point
                 System.arraycopy( children, index + 1, newNode.children, index + 1, nbElems - index ); // 8
@@ -439,14 +439,14 @@ import org.apache.directory.mavibot.btre
         if ( isLeft )
         {
             // The sibling is on the left. Copy all of its elements in the new node first
-            System.arraycopy( sibling.keys, 0, newNode.keys, 0, half ); //1
+            System.arraycopy( sibling.getKeys(), 0, newNode.getKeys(), 0, half ); //1
             System.arraycopy( sibling.children, 0, newNode.children, 0, half + 1 ); //2
 
             // Then copy all the elements up to the deletion point
             if ( index < 2 )
             {
-                newNode.keys[half] = mergedResult.getModifiedPage().getLeftMostKey();
-                System.arraycopy( keys, 1, newNode.keys, half + 1, half - 1 );
+                newNode.setKey( half, mergedResult.getModifiedPage().getLeftMostKey() );
+                System.arraycopy( getKeys(), 1, newNode.getKeys(), half + 1, half - 1 );
 
                 Page<K, V> modifiedPage = mergedResult.getModifiedPage();
                 newNode.children[half + 1] = modifiedPage;
@@ -456,19 +456,19 @@ import org.apache.directory.mavibot.btre
             {
                 // Copy the left part of the node keys up to the deletion point
                 // Insert the new key
-                newNode.keys[half] = children[0].getLeftMostKey(); // 3
+                newNode.setKey( half, children[0].getLeftMostKey() ); // 3
 
                 if ( index > 2 )
                 {
-                    System.arraycopy( keys, 0, newNode.keys, half + 1, index - 2 ); //4
+                    System.arraycopy( getKeys(), 0, newNode.getKeys(), half + 1, index - 2 ); //4
                 }
 
                 // Inject the new merged key
-                newNode.keys[half + index - 1] = mergedResult.getModifiedPage().getLeftMostKey(); //5
+                newNode.setKey( half + index - 1, mergedResult.getModifiedPage().getLeftMostKey() ); //5
 
                 if ( index < half )
                 {
-                    System.arraycopy( keys, index, newNode.keys, half + index, half - index ); //6
+                    System.arraycopy( getKeys(), index, newNode.getKeys(), half + index, half - index ); //6
                     System.arraycopy( children, index + 1, newNode.children, half + index + 1, half - index ); //9
                 }
 
@@ -486,7 +486,7 @@ import org.apache.directory.mavibot.btre
             if ( index < 2 )
             {
                 // Copy the keys
-                System.arraycopy( keys, 1, newNode.keys, 0, half - 1 );
+                System.arraycopy( getKeys(), 1, newNode.getKeys(), 0, half - 1 );
 
                 // Insert the first child
                 Page<K, V> modifiedPage = mergedResult.getModifiedPage();
@@ -501,14 +501,14 @@ import org.apache.directory.mavibot.btre
                 if ( index > 2 )
                 {
                     // Copy the first keys
-                    System.arraycopy( keys, 0, newNode.keys, 0, index - 2 ); //1
+                    System.arraycopy( getKeys(), 0, newNode.getKeys(), 0, index - 2 ); //1
                 }
 
                 // Copy the first children
                 System.arraycopy( children, 0, newNode.children, 0, index - 1 ); //6
 
                 // Inject the modified key
-                newNode.keys[index - 2] = mergedResult.getModifiedPage().getLeftMostKey(); //2
+                newNode.setKey( index - 2, mergedResult.getModifiedPage().getLeftMostKey() ); //2
 
                 // Inject the modified children
                 Page<K, V> modifiedPage = mergedResult.getModifiedPage();
@@ -517,7 +517,7 @@ import org.apache.directory.mavibot.btre
                 // Add the remaining node's key if needed
                 if ( index < half )
                 {
-                    System.arraycopy( keys, index, newNode.keys, index - 1, half - index ); //5
+                    System.arraycopy( getKeys(), index, newNode.getKeys(), index - 1, half - index ); //5
 
                     // Add the remining children if below half
                     System.arraycopy( children, index + 1, newNode.children, index, half - index ); // 8
@@ -525,10 +525,10 @@ import org.apache.directory.mavibot.btre
             }
 
             // Inject the new key from sibling
-            newNode.keys[half - 1] = sibling.findLeftMost().getKey(); //3
+            newNode.setKey( half - 1, sibling.findLeftMost().getKey() ); //3
 
             // Copy the sibling keys
-            System.arraycopy( sibling.keys, 0, newNode.keys, half, half );
+            System.arraycopy( sibling.getKeys(), 0, newNode.getKeys(), half, half );
 
             // Add the sibling children
             System.arraycopy( sibling.children, 0, newNode.children, half, half + 1 ); // 9
@@ -690,8 +690,8 @@ import org.apache.directory.mavibot.btre
             if ( borrowedResult.isFromRight() )
             {
                 // Update the keys
-                newPage.keys[pos] = modifiedPage.findLeftMost().getKey();
-                newPage.keys[pos + 1] = modifiedSibling.findLeftMost().getKey();
+                newPage.setKey( pos, modifiedPage.findLeftMost().getKey() );
+                newPage.setKey( pos + 1, modifiedSibling.findLeftMost().getKey() );
 
                 // Update the children
                 newPage.children[pos + 1] = modifiedPage;
@@ -700,7 +700,7 @@ import org.apache.directory.mavibot.btre
             else
             {
                 // Update the keys
-                newPage.keys[pos] = modifiedPage.findLeftMost().getKey();
+                newPage.setKey( pos, modifiedPage.findLeftMost().getKey() );
 
                 // Update the children
                 newPage.children[pos] = modifiedSibling;
@@ -712,7 +712,7 @@ import org.apache.directory.mavibot.btre
             if ( borrowedResult.isFromRight() )
             {
                 // Update the keys
-                newPage.keys[pos] = modifiedSibling.findLeftMost().getKey();
+                newPage.setKey( pos, modifiedSibling.findLeftMost().getKey() );
 
                 // Update the children
                 newPage.children[pos] = modifiedPage;
@@ -721,7 +721,7 @@ import org.apache.directory.mavibot.btre
             else
             {
                 // Update the keys
-                newPage.keys[pos - 1] = modifiedPage.findLeftMost().getKey();
+                newPage.setKey( pos - 1, modifiedPage.findLeftMost().getKey() );
 
                 // Update the children
                 newPage.children[pos - 1] = modifiedSibling;
@@ -760,7 +760,7 @@ import org.apache.directory.mavibot.btre
         if ( index < 0 )
         {
             // Copy the keys and the children
-            System.arraycopy( keys, 1, newNode.keys, 0, newNode.nbElems );
+            System.arraycopy( getKeys(), 1, newNode.getKeys(), 0, newNode.nbElems );
             Page<K, V> modifiedPage = mergedResult.getModifiedPage();
             newNode.children[0] = modifiedPage;
             System.arraycopy( children, 2, newNode.children, 1, nbElems - 1 );
@@ -770,14 +770,14 @@ import org.apache.directory.mavibot.btre
             // Copy the keys
             if ( index > 0 )
             {
-                System.arraycopy( keys, 0, newNode.keys, 0, index );
+                System.arraycopy( getKeys(), 0, newNode.getKeys(), 0, index );
             }
 
-            newNode.keys[index] = mergedResult.getModifiedPage().findLeftMost().getKey();
+            newNode.setKey( index, mergedResult.getModifiedPage().findLeftMost().getKey() );
 
             if ( index < nbElems - 2 )
             {
-                System.arraycopy( keys, index + 2, newNode.keys, index + 1, nbElems - index - 2 );
+                System.arraycopy( getKeys(), index + 2, newNode.getKeys(), index + 1, nbElems - index - 2 );
             }
 
             // Copy the children
@@ -1011,12 +1011,12 @@ import org.apache.directory.mavibot.btre
         // Copy the keys and the children up to the insertion position
         if ( nbElems > 0 )
         {
-            System.arraycopy( keys, 0, newNode.keys, 0, pos );
+            System.arraycopy( getKeys(), 0, newNode.getKeys(), 0, pos );
             System.arraycopy( children, 0, newNode.children, 0, pos );
         }
 
         // Add the new key and children
-        newNode.keys[pos] = key;
+        newNode.setKey( pos, key );
 
         // If the BTree is managed, we now have to write the modified page on disk
         // and to add this page to the list of modified pages
@@ -1026,7 +1026,7 @@ import org.apache.directory.mavibot.btre
         // And copy the remaining keys and children
         if ( nbElems > 0 )
         {
-            System.arraycopy( keys, pos, newNode.keys, pos + 1, keys.length - pos );
+            System.arraycopy( getKeys(), pos, newNode.getKeys(), pos + 1, getKeys().length - pos );
             System.arraycopy( children, pos + 1, newNode.children, pos + 2, children.length - pos - 1 );
         }
 
@@ -1071,24 +1071,24 @@ import org.apache.directory.mavibot.btre
         if ( pos < middle )
         {
             // Copy the keys and the children up to the insertion position
-            System.arraycopy( keys, 0, newLeftPage.keys, 0, pos );
+            System.arraycopy( getKeys(), 0, newLeftPage.getKeys(), 0, pos );
             System.arraycopy( children, 0, newLeftPage.children, 0, pos );
 
             // Add the new element
-            newLeftPage.keys[pos] = pivot;
+            newLeftPage.setKey( pos, pivot );
             newLeftPage.children[pos] = leftPage;
             newLeftPage.children[pos + 1] = rightPage;
 
             // And copy the remaining elements minus the new pivot
-            System.arraycopy( keys, pos, newLeftPage.keys, pos + 1, middle - pos - 1 );
+            System.arraycopy( getKeys(), pos, newLeftPage.getKeys(), pos + 1, middle - pos - 1 );
             System.arraycopy( children, pos + 1, newLeftPage.children, pos + 2, middle - pos - 1 );
 
             // Copy the keys and the children in the right page
-            System.arraycopy( keys, middle, newRightPage.keys, 0, middle );
+            System.arraycopy( getKeys(), middle, newRightPage.getKeys(), 0, middle );
             System.arraycopy( children, middle, newRightPage.children, 0, middle + 1 );
 
             // Create the result
-            InsertResult<K, V> result = new SplitResult<K, V>( copiedPages, keys[middle - 1], newLeftPage, newRightPage );
+            InsertResult<K, V> result = new SplitResult<K, V>( copiedPages, getKey( middle - 1 ), newLeftPage, newRightPage );
             result.addCopiedPage( this );
 
             return result;
@@ -1098,12 +1098,12 @@ import org.apache.directory.mavibot.btre
             // A special case : the pivot will be propagated up in the tree
             // The left and right pages will be spread on the two new pages
             // Copy the keys and the children up to the insertion position (here, middle)
-            System.arraycopy( keys, 0, newLeftPage.keys, 0, middle );
+            System.arraycopy( getKeys(), 0, newLeftPage.getKeys(), 0, middle );
             System.arraycopy( children, 0, newLeftPage.children, 0, middle );
             newLeftPage.children[middle] = leftPage;
 
             // And process the right page now
-            System.arraycopy( keys, middle, newRightPage.keys, 0, middle );
+            System.arraycopy( getKeys(), middle, newRightPage.getKeys(), 0, middle );
             System.arraycopy( children, middle + 1, newRightPage.children, 1, middle );
             newRightPage.children[0] = rightPage;
 
@@ -1116,24 +1116,24 @@ import org.apache.directory.mavibot.btre
         else
         {
             // Copy the keys and the children up to the middle
-            System.arraycopy( keys, 0, newLeftPage.keys, 0, middle );
+            System.arraycopy( getKeys(), 0, newLeftPage.getKeys(), 0, middle );
             System.arraycopy( children, 0, newLeftPage.children, 0, middle + 1 );
 
             // Copy the keys and the children in the right page up to the pos
-            System.arraycopy( keys, middle + 1, newRightPage.keys, 0, pos - middle - 1 );
+            System.arraycopy( getKeys(), middle + 1, newRightPage.getKeys(), 0, pos - middle - 1 );
             System.arraycopy( children, middle + 1, newRightPage.children, 0, pos - middle - 1 );
 
             // Add the new element
-            newRightPage.keys[pos - middle - 1] = pivot;
+            newRightPage.setKey( pos - middle - 1, pivot );
             newRightPage.children[pos - middle - 1] = leftPage;
             newRightPage.children[pos - middle] = rightPage;
 
             // And copy the remaining elements minus the new pivot
-            System.arraycopy( keys, pos, newRightPage.keys, pos - middle, nbElems - pos );
+            System.arraycopy( getKeys(), pos, newRightPage.getKeys(), pos - middle, nbElems - pos );
             System.arraycopy( children, pos + 1, newRightPage.children, pos + 1 - middle, nbElems - pos );
 
             // Create the result
-            InsertResult<K, V> result = new SplitResult<K, V>( copiedPages, keys[middle], newLeftPage, newRightPage );
+            InsertResult<K, V> result = new SplitResult<K, V>( copiedPages, getKey( middle ), newLeftPage, newRightPage );
             result.addCopiedPage( this );
 
             return result;
@@ -1152,7 +1152,7 @@ import org.apache.directory.mavibot.btre
         Node<K, V> newPage = new Node<K, V>( btree, revision, nbElems );
 
         // Copy the keys
-        System.arraycopy( keys, 0, newPage.keys, 0, nbElems );
+        System.arraycopy( getKeys(), 0, newPage.getKeys(), 0, nbElems );
 
         // Copy the children
         System.arraycopy( children, 0, newPage.children, 0, nbElems + 1 );
@@ -1164,7 +1164,7 @@ import org.apache.directory.mavibot.btre
     /**
      * {@inheritDoc}
      */
-    public K getLeftMostKey() throws EndOfFileExceededException, IOException
+    public K getLeftMostKey()
     {
         return children[0].getLeftMostKey();
     }
@@ -1173,7 +1173,7 @@ import org.apache.directory.mavibot.btre
     /**
      * {@inheritDoc}
      */
-    public K getRightMostKey() throws EndOfFileExceededException, IOException
+    public K getRightMostKey()
     {
         int index = ( nbElems + 1 ) - 1;
 
@@ -1229,7 +1229,7 @@ import org.apache.directory.mavibot.btre
 
             for ( int i = 0; i < nbElems; i++ )
             {
-                sb.append( "|<" ).append( keys[i] ).append( ">|" );
+                sb.append( "|<" ).append( getKey( i ) ).append( ">|" );
 
                 if ( children[i + 1] == null )
                 {
@@ -1264,7 +1264,7 @@ import org.apache.directory.mavibot.btre
             {
                 sb.append( tabs );
                 sb.append( "<" );
-                sb.append( keys[i] ).append( ">\n" );
+                sb.append( getKey( i ) ).append( ">\n" );
                 sb.append( children[i + 1].dumpPage( tabs + "    " ) );
             }
         }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java?rev=1550673&r1=1550672&r2=1550673&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java Fri Dec 13 10:13:21 2013
@@ -23,12 +23,12 @@ package org.apache.directory.mavibot.btr
 import java.io.IOException;
 import java.util.NoSuchElementException;
 
+import org.apache.directory.mavibot.btree.AbstractTupleCursor;
 import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.Page;
 import org.apache.directory.mavibot.btree.ParentPos;
 import org.apache.directory.mavibot.btree.Transaction;
 import org.apache.directory.mavibot.btree.Tuple;
-import org.apache.directory.mavibot.btree.TupleCursor;
 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
 
 
@@ -43,62 +43,17 @@ import org.apache.directory.mavibot.btre
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class TupleCursorImpl<K, V> implements TupleCursor<K, V>
+public class TupleCursorImpl<K, V> extends AbstractTupleCursor<K, V>
 {
-    /** The transaction used for this cursor */
-    private Transaction<K, V> transaction;
-
-    /** The Tuple used to return the results */
-    private Tuple<K, V> tuple = new Tuple<K, V>();
-
-    /** The stack of pages from the root down to the leaf */
-    private ParentPos<K, V>[] stack;
-    
-    /** The stack's depth */
-    private int depth = 0;
-
-    private boolean allowDuplicates;
-
-
     /**
      * Creates a new instance of Cursor, starting on a page at a given position.
      * 
      * @param transaction The transaction this operation is protected by
      * @param stack The stack of parent's from root to this page
      */
-    TupleCursorImpl( BTree<K, V> btree, Transaction<K, V> transaction, ParentPos<K, V>[] stack, int depth )
-    {
-        this.transaction = transaction;
-        this.stack = stack;
-        this.allowDuplicates = btree.isAllowDuplicates();
-        this.depth = depth;
-    }
-
-
-    /**
-     * Closes the cursor, thus releases the associated transaction
-     */
-    public void close()
+    TupleCursorImpl( Transaction<K, V> transaction, ParentPos<K, V>[] stack, int depth )
     {
-        transaction.close();
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public long getRevision()
-    {
-        return transaction.getRevision();
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public long getCreationDate()
-    {
-        return transaction.getCreationDate();
+        super( transaction, stack, depth );
     }
     
     
@@ -122,12 +77,12 @@ public class TupleCursorImpl<K, V> imple
             if ( child != null )
             {
                 parentPos.page = child;
-                parentPos.pos = ((Node<K, V>)child).nbElems;
+                parentPos.pos = child.getNbElems();
             }
             else
             {
                 // We have N+1 children if the page is a Node, so we don't decrement the nbElems field
-                parentPos.pos = ((Node<K, V>)parentPos.page).nbElems;
+                parentPos.pos = parentPos.page.getNbElems();
             }
 
             child = ((Node<K, V>)parentPos.page).children[parentPos.pos];
@@ -138,12 +93,12 @@ public class TupleCursorImpl<K, V> imple
 
         if ( child == null )
         {
-            parentPos.pos = ((Leaf<K, V>)parentPos.page).nbElems - 1;
+            parentPos.pos = parentPos.page.getNbElems() - 1;
         }
         else
         {
             parentPos.page = child;
-            parentPos.pos = ((Leaf<K, V>)child).nbElems - 1;
+            parentPos.pos = child.getNbElems() - 1;
         }
 
         parentPos.valueCursor = ((Leaf<K, V>)parentPos.page).values[parentPos.pos].getCursor();
@@ -298,7 +253,7 @@ public class TupleCursorImpl<K, V> imple
                     parentPos = stack[currentDepth];
                     parentPos.pos = child.getNbElems();
                     parentPos.page = child;
-                    child = ((Node<K, V>)parentPos.page).children[((Node<K, V>)parentPos.page).nbElems];
+                    child = ((Node<K, V>)parentPos.page).children[parentPos.page.getNbElems()];
                 }
 
                 // and the leaf
@@ -687,7 +642,7 @@ public class TupleCursorImpl<K, V> imple
         }
         
         Leaf<K, V> leaf = ( Leaf<K, V> ) ( parentPos.page );
-        tuple.setKey( leaf.keys[parentPos.pos] );
+        tuple.setKey( leaf.getKey( parentPos.pos ) );
         tuple.setValue( value );
 
         return tuple;
@@ -746,7 +701,7 @@ public class TupleCursorImpl<K, V> imple
 
         // The key
         Leaf<K, V> leaf = ( Leaf<K, V> ) ( parentPos.page );
-        tuple.setKey( leaf.keys[parentPos.pos] );
+        tuple.setKey( leaf.getKey( parentPos.pos ) );
         
         // The value
         ValueHolder<V> valueHolder = leaf.values[parentPos.pos];
@@ -838,7 +793,7 @@ public class TupleCursorImpl<K, V> imple
 
 
         Leaf<K, V> leaf = ( Leaf<K, V> ) ( parentPos.page );
-        tuple.setKey( leaf.keys[parentPos.pos] );
+        tuple.setKey( leaf.getKey( parentPos.pos ) );
         tuple.setValue( value );
 
         return tuple;
@@ -893,7 +848,7 @@ public class TupleCursorImpl<K, V> imple
         Leaf<K, V> leaf = ( Leaf<K, V> ) ( parentPos.page );
 
         // The key
-        tuple.setKey( leaf.keys[parentPos.pos] );
+        tuple.setKey( leaf.getKey( parentPos.pos ) );
 
         // The value
         ValueHolder<V> valueHolder = leaf.values[parentPos.pos];
@@ -903,19 +858,4 @@ public class TupleCursorImpl<K, V> imple
         
         return tuple;
     }
-    
-    
-    public String toString()
-    {
-        StringBuilder sb = new StringBuilder();
-        
-        sb.append( "TupleCursor, depth = " ).append( depth ).append( "\n" );
-        
-        for ( int i = 0; i <= depth; i++ )
-        {
-            sb.append( "    " ).append( stack[i] ).append( "\n" );
-        }
-        
-        return sb.toString();
-    }
 }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/ValueHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/ValueHolder.java?rev=1550673&r1=1550672&r2=1550673&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/ValueHolder.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/ValueHolder.java Fri Dec 13 10:13:21 2013
@@ -26,7 +26,6 @@ import java.util.UUID;
 
 import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.Tuple;
-import org.apache.directory.mavibot.btree.TupleCursor;
 import org.apache.directory.mavibot.btree.ValueCursor;
 import org.apache.directory.mavibot.btree.ValueBTreeCursor;
 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/BTreeBuilderTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/BTreeBuilderTest.java?rev=1550673&r1=1550672&r2=1550673&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/BTreeBuilderTest.java (original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/BTreeBuilderTest.java Fri Dec 13 10:13:21 2013
@@ -45,6 +45,7 @@ public class BTreeBuilderTest
     public void testIntegerTree() throws IOException
     {
         List<Tuple<Integer, Integer>> sortedTuple = new ArrayList<Tuple<Integer, Integer>>();
+        
         for ( int i = 1; i < 8; i++ )
         {
             Tuple<Integer, Integer> t = new Tuple<Integer, Integer>( i, i );

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeTest.java?rev=1550673&r1=1550672&r2=1550673&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeTest.java (original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeTest.java Fri Dec 13 10:13:21 2013
@@ -36,6 +36,7 @@ import java.util.Random;
 import java.util.Set;
 
 import org.apache.directory.mavibot.btree.BTree;
+import org.apache.directory.mavibot.btree.KeyHolder;
 import org.apache.directory.mavibot.btree.Page;
 import org.apache.directory.mavibot.btree.Tuple;
 import org.apache.directory.mavibot.btree.TupleCursor;
@@ -1045,15 +1046,15 @@ public class InMemoryBTreeTest
     {
         Leaf<Integer, String> leaf = new Leaf<Integer, String>( btree );
         int pos = 0;
-        leaf.revision = revision;
-        leaf.nbElems = tuples.length;
-        leaf.keys = new Integer[leaf.nbElems];
+        leaf.setRevision( revision );
+        leaf.setNbElems( tuples.length );
+        leaf.setKeys( new KeyHolder[leaf.getNbElems()] );
         leaf.values = ( ValueHolder<String>[] ) Array
-            .newInstance( ValueHolder.class, leaf.nbElems );
+            .newInstance( ValueHolder.class, leaf.getNbElems() );
 
         for ( Tuple<Integer, String> tuple : tuples )
         {
-            leaf.keys[pos] = tuple.getKey();
+            leaf.setKey( pos, tuple.getKey() );
             leaf.values[pos] = new ValueHolder<String>( btree, tuple.getValue() );
             pos++;
         }
@@ -1069,7 +1070,7 @@ public class InMemoryBTreeTest
 
         if ( pos > 0 )
         {
-            node.keys[pos - 1] = leftmost.getKey();
+            node.setKey( pos - 1, leftmost.getKey() );
         }
 
         node.children[pos] = page;

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/LeafTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/LeafTest.java?rev=1550673&r1=1550672&r2=1550673&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/LeafTest.java (original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/LeafTest.java Fri Dec 13 10:13:21 2013
@@ -254,8 +254,8 @@ public class LeafTest
         parent.children[2] = right;
 
         // Update the parent
-        parent.keys[0] = 6L;
-        parent.keys[1] = 10L;
+        parent.setKey( 0, 6L );
+        parent.setKey( 1, 10L );
 
         // Now, delete the element from the target page
         DeleteResult<Long, String> result = target.delete( 2L, 7L, null, parent, 1 );
@@ -270,20 +270,20 @@ public class LeafTest
         // Check the modified leaf
         Leaf<Long, String> newLeaf = ( Leaf<Long, String> ) borrowed.getModifiedPage();
 
-        assertEquals( 4, newLeaf.nbElems );
-        assertEquals( Long.valueOf( 5L ), newLeaf.keys[0] );
-        assertEquals( Long.valueOf( 6L ), newLeaf.keys[1] );
-        assertEquals( Long.valueOf( 8L ), newLeaf.keys[2] );
-        assertEquals( Long.valueOf( 9L ), newLeaf.keys[3] );
+        assertEquals( 4, newLeaf.getNbElems() );
+        assertEquals( Long.valueOf( 5L ), newLeaf.getKey( 0 ) );
+        assertEquals( Long.valueOf( 6L ), newLeaf.getKey( 1 ) );
+        assertEquals( Long.valueOf( 8L ), newLeaf.getKey( 2 ) );
+        assertEquals( Long.valueOf( 9L ), newLeaf.getKey( 3 ) );
 
         // Check the sibling
         Leaf<Long, String> leftSibling = ( Leaf<Long, String> ) borrowed.getModifiedSibling();
 
-        assertEquals( 4, leftSibling.nbElems );
-        assertEquals( Long.valueOf( 1L ), leftSibling.keys[0] );
-        assertEquals( Long.valueOf( 2L ), leftSibling.keys[1] );
-        assertEquals( Long.valueOf( 3L ), leftSibling.keys[2] );
-        assertEquals( Long.valueOf( 4L ), leftSibling.keys[3] );
+        assertEquals( 4, leftSibling.getNbElems() );
+        assertEquals( Long.valueOf( 1L ), leftSibling.getKey( 0 ) );
+        assertEquals( Long.valueOf( 2L ), leftSibling.getKey( 1 ) );
+        assertEquals( Long.valueOf( 3L ), leftSibling.getKey( 2 ) );
+        assertEquals( Long.valueOf( 4L ), leftSibling.getKey( 3 ) );
     }
 
 
@@ -324,8 +324,8 @@ public class LeafTest
         parent.children[2] = right;
 
         // Update the parent
-        parent.keys[0] = 6L;
-        parent.keys[1] = 10L;
+        parent.setKey( 0, 6L );
+        parent.setKey( 1, 10L );
 
         // Now, delete the element from the target page
         DeleteResult<Long, String> result = target.delete( 2L, 7L, null, parent, 1 );
@@ -341,20 +341,20 @@ public class LeafTest
         // Check the modified leaf
         Leaf<Long, String> newLeaf = ( Leaf<Long, String> ) borrowed.getModifiedPage();
 
-        assertEquals( 4, newLeaf.nbElems );
-        assertEquals( Long.valueOf( 6L ), newLeaf.keys[0] );
-        assertEquals( Long.valueOf( 8L ), newLeaf.keys[1] );
-        assertEquals( Long.valueOf( 9L ), newLeaf.keys[2] );
-        assertEquals( Long.valueOf( 10L ), newLeaf.keys[3] );
+        assertEquals( 4, newLeaf.getNbElems() );
+        assertEquals( Long.valueOf( 6L ), newLeaf.getKey( 0 ) );
+        assertEquals( Long.valueOf( 8L ), newLeaf.getKey( 1 ) );
+        assertEquals( Long.valueOf( 9L ), newLeaf.getKey( 2 ) );
+        assertEquals( Long.valueOf( 10L ), newLeaf.getKey( 3 ) );
 
         // Check the sibling
         Leaf<Long, String> rightSibling = ( Leaf<Long, String> ) borrowed.getModifiedSibling();
 
-        assertEquals( 4, rightSibling.nbElems );
-        assertEquals( Long.valueOf( 11L ), rightSibling.keys[0] );
-        assertEquals( Long.valueOf( 12L ), rightSibling.keys[1] );
-        assertEquals( Long.valueOf( 13L ), rightSibling.keys[2] );
-        assertEquals( Long.valueOf( 14L ), rightSibling.keys[3] );
+        assertEquals( 4, rightSibling.getNbElems() );
+        assertEquals( Long.valueOf( 11L ), rightSibling.getKey( 0 ) );
+        assertEquals( Long.valueOf( 12L ), rightSibling.getKey( 1 ) );
+        assertEquals( Long.valueOf( 13L ), rightSibling.getKey( 2 ) );
+        assertEquals( Long.valueOf( 14L ), rightSibling.getKey( 3 ) );
     }
 
 
@@ -394,8 +394,8 @@ public class LeafTest
         parent.children[2] = right;
 
         // Update the parent
-        parent.keys[0] = 5L;
-        parent.keys[1] = 9L;
+        parent.setKey( 0, 5L );
+        parent.setKey( 1, 9L );
 
         // Now, delete the element from the target page
         DeleteResult<Long, String> result = target.delete( 2L, 7L, null, parent, 1 );
@@ -410,14 +410,14 @@ public class LeafTest
         // Check the modified leaf
         Leaf<Long, String> newLeaf = ( Leaf<Long, String> ) merged.getModifiedPage();
 
-        assertEquals( 7, newLeaf.nbElems );
-        assertEquals( Long.valueOf( 1L ), newLeaf.keys[0] );
-        assertEquals( Long.valueOf( 2L ), newLeaf.keys[1] );
-        assertEquals( Long.valueOf( 3L ), newLeaf.keys[2] );
-        assertEquals( Long.valueOf( 4L ), newLeaf.keys[3] );
-        assertEquals( Long.valueOf( 5L ), newLeaf.keys[4] );
-        assertEquals( Long.valueOf( 6L ), newLeaf.keys[5] );
-        assertEquals( Long.valueOf( 8L ), newLeaf.keys[6] );
+        assertEquals( 7, newLeaf.getNbElems() );
+        assertEquals( Long.valueOf( 1L ), newLeaf.getKey( 0 ) );
+        assertEquals( Long.valueOf( 2L ), newLeaf.getKey( 1 ) );
+        assertEquals( Long.valueOf( 3L ), newLeaf.getKey( 2 ) );
+        assertEquals( Long.valueOf( 4L ), newLeaf.getKey( 3 ) );
+        assertEquals( Long.valueOf( 5L ), newLeaf.getKey( 4 ) );
+        assertEquals( Long.valueOf( 6L ), newLeaf.getKey( 5 ) );
+        assertEquals( Long.valueOf( 8L ), newLeaf.getKey( 6 ) );
     }
 
 



Mime
View raw message