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 2012/07/02 14:08:58 UTC

svn commit: r1356199 - in /labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree: AbstractDeleteResult.java AbstractPage.java BorrowedFromLeftResult.java BorrowedFromRightResult.java NotPresentResult.java ParentPos.java RemoveResult.java

Author: elecharny
Date: Mon Jul  2 12:08:57 2012
New Revision: 1356199

URL: http://svn.apache.org/viewvc?rev=1356199&view=rev
Log:
o Reorganized the DeleteResult hierarchy, adding an Abstract class
o Added some javadoc

Added:
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractDeleteResult.java
Modified:
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BorrowedFromLeftResult.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BorrowedFromRightResult.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/NotPresentResult.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/ParentPos.java
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RemoveResult.java

Added: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractDeleteResult.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractDeleteResult.java?rev=1356199&view=auto
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractDeleteResult.java (added)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractDeleteResult.java Mon Jul  2 12:08:57 2012
@@ -0,0 +1,81 @@
+/*
+ *  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;
+
+/**
+ * An abstract class to gather common elements of the DeleteResult
+ * 
+ * @param <K> The type for the Key
+ * @param <V> The type for the stored value
+
+ * @author <a href="mailto:labs@laps.apache.org">Mavibot labs Project</a>
+ */
+/* No qualifier */ abstract class AbstractDeleteResult<K, V> implements DeleteResult<K, V>
+{
+    /** The modified page reference */
+    protected Page<K, V> modifiedPage;
+    
+    /** The removed element if the key was found in the tree*/
+    protected Tuple<K, V> removedElement;
+    
+    /** The new leftmost element if the removed k was on position 0. Null otherwise */
+    protected K newLeftMost;
+    
+    /**
+     * The default constructor for AbstractDeleteResult.
+     * 
+     * @param modifiedPage The modified page
+     * @param removedElement The removed element (can be null if the key wasn't present in the tree)
+     * @param newLeftMost The element on the left of he current page
+     */
+    /* No qualifier */ AbstractDeleteResult( Page<K, V> modifiedPage, Tuple<K, V> removedElement, K newLeftMost )
+    {
+        this.modifiedPage = modifiedPage;
+        this.removedElement = removedElement;
+        this.newLeftMost = newLeftMost;
+    }
+    
+    
+    /**
+     * @return the modifiedPage
+     */
+    /* No qualifier */ Page<K, V> getModifiedPage()
+    {
+        return modifiedPage;
+    }
+
+
+    /**
+     * @return the removed element
+     */
+    /* No qualifier */ Tuple<K, V> getRemovedElement()
+    {
+        return removedElement;
+    }
+
+
+    /**
+     * @return the newLeftMost
+     */
+    /* No qualifier */ K getNewLeftMost()
+    {
+        return newLeftMost;
+    }
+}

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java?rev=1356199&r1=1356198&r2=1356199&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/AbstractPage.java Mon Jul  2 12:08:57 2012
@@ -69,6 +69,8 @@ public abstract class AbstractPage<K, V>
         this.revision = revision;
         this.nbElems = nbElems;
         
+        // We get the type of array to create from the btree
+        // Yes, this is an hack...
         Class<?> keyType = btree.getKeyType();
         this.keys = (K[])Array.newInstance( keyType, nbElems );
         
@@ -83,6 +85,7 @@ public abstract class AbstractPage<K, V>
     {
         return nbElems;
     }
+    
 
     /**
      * Find the position of the given key in the page. If we have found the key,

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BorrowedFromLeftResult.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BorrowedFromLeftResult.java?rev=1356199&r1=1356198&r2=1356199&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BorrowedFromLeftResult.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BorrowedFromLeftResult.java Mon Jul  2 12:08:57 2012
@@ -20,7 +20,8 @@
 package org.apache.mavibot.btree;
 
 /**
- * The result of a delete operation, when the child has not been merged. It contains the
+ * The result of a delete operation, when the child has not been merged, and when
+ * we have borrowed an element from the left sibling. It contains the
  * reference to the modified page, and the removed element.
  * 
  * @param <K> The type for the Key
@@ -28,70 +29,33 @@ package org.apache.mavibot.btree;
 
  * @author <a href="mailto:labs@laps.apache.org">Mavibot labs Project</a>
  */
-/* No qualifier */ class BorrowedFromLeftResult<K, V> implements DeleteResult<K, V>
+/* No qualifier */ class BorrowedFromLeftResult<K, V> extends AbstractDeleteResult<K, V>
 {
-    /** The modified page reference */
-    protected Page<K, V> modifiedPage;
-    
     /** The modified sibling reference */
-    protected Page<K, V> modifiedSibling;
-    
-    /** The removed element if the key was found in the tree*/
-    protected Tuple<K, V> removedElement;
-    
-    /** The new leftmost element if the removed k was on position 0. Null otherwise */
-    protected K newLeftMost;
+    private Page<K, V> modifiedSibling;
     
     /**
      * The default constructor for RemoveResult.
      * 
      * @param modifiedPage The modified page
-     * @param
+     * @param modifiedSibling The modified sibling
      * @param removedElement The removed element (can be null if the key wasn't present in the tree)
+     * @param newLeftMost The element on the left of he current page
      */
-    public BorrowedFromLeftResult( Page<K, V> modifiedPage, Page<K, V> modifiedSibling, Tuple<K, V> removedElement, K newLeftMost )
+    /* No qualifier */ BorrowedFromLeftResult( Page<K, V> modifiedPage, Page<K, V> modifiedSibling, Tuple<K, V> removedElement, K newLeftMost )
     {
-        this.modifiedPage = modifiedPage;
+        super( modifiedPage, removedElement, newLeftMost );
         this.modifiedSibling = modifiedSibling;
-        this.removedElement = removedElement;
-        this.newLeftMost = newLeftMost;
     }
     
-
-    /**
-     * @return the modifiedPage
-     */
-    public Page<K, V> getModifiedPage()
-    {
-        return modifiedPage;
-    }
     
-
     /**
      * @return the modifiedSibling
      */
-    public Page<K, V> getModifiedSibling()
+    /* No qualifier */ Page<K, V> getModifiedSibling()
     {
         return modifiedSibling;
     }
-
-
-    /**
-     * @return the removed element
-     */
-    public Tuple<K, V> getRemovedElement()
-    {
-        return removedElement;
-    }
-
-
-    /**
-     * @return the newLeftMost
-     */
-    public K getNewLeftMost()
-    {
-        return newLeftMost;
-    }
     
     
     /**

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BorrowedFromRightResult.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BorrowedFromRightResult.java?rev=1356199&r1=1356198&r2=1356199&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BorrowedFromRightResult.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BorrowedFromRightResult.java Mon Jul  2 12:08:57 2012
@@ -28,19 +28,10 @@ package org.apache.mavibot.btree;
 
  * @author <a href="mailto:labs@laps.apache.org">Mavibot labs Project</a>
  */
-/* No qualifier */ class BorrowedFromRightResult<K, V> implements DeleteResult<K, V>
+/* No qualifier */ class BorrowedFromRightResult<K, V> extends AbstractDeleteResult<K, V>
 {
-    /** The modified page reference */
-    protected Page<K, V> modifiedPage;
-    
     /** The modified sibling reference */
-    protected Page<K, V> modifiedSibling;
-    
-    /** The removed element if the key was found in the tree*/
-    protected Tuple<K, V> removedElement;
-    
-    /** The new leftmost element if the removed k was on position 0. Null otherwise */
-    protected K newLeftMost;
+    private Page<K, V> modifiedSibling;
     
     /**
      * The default constructor for RemoveResult.
@@ -49,49 +40,20 @@ package org.apache.mavibot.btree;
      * @param
      * @param removedElement The removed element (can be null if the key wasn't present in the tree)
      */
-    public BorrowedFromRightResult( Page<K, V> modifiedPage, Page<K, V> modifiedSibling, Tuple<K, V> removedElement, K newLeftMost )
+    /* No qualifier */ BorrowedFromRightResult( Page<K, V> modifiedPage, Page<K, V> modifiedSibling, Tuple<K, V> removedElement, K newLeftMost )
     {
-        this.modifiedPage = modifiedPage;
+        super( modifiedPage, removedElement, newLeftMost );
         this.modifiedSibling = modifiedSibling;
-        this.removedElement = removedElement;
-        this.newLeftMost = newLeftMost;
-    }
-    
-
-    /**
-     * @return the modifiedPage
-     */
-    public Page<K, V> getModifiedPage()
-    {
-        return modifiedPage;
     }
     
 
     /**
      * @return the modifiedSibling
      */
-    public Page<K, V> getModifiedSibling()
+    /* No qualifier */ Page<K, V> getModifiedSibling()
     {
         return modifiedSibling;
     }
-
-
-    /**
-     * @return the removed element
-     */
-    public Tuple<K, V> getRemovedElement()
-    {
-        return removedElement;
-    }
-
-
-    /**
-     * @return the newLeftMost
-     */
-    public K getNewLeftMost()
-    {
-        return newLeftMost;
-    }
     
     
     /**

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/NotPresentResult.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/NotPresentResult.java?rev=1356199&r1=1356198&r2=1356199&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/NotPresentResult.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/NotPresentResult.java Mon Jul  2 12:08:57 2012
@@ -27,10 +27,15 @@ package org.apache.mavibot.btree;
 
  * @author <a href="mailto:labs@laps.apache.org">Mavibot labs Project</a>
  */
-class NotPresentResult<K, V> implements DeleteResult<K, V>
+/* No qualifier */ class NotPresentResult<K, V> implements DeleteResult<K, V>
 {
-    public static final NotPresentResult NOT_PRESENT = new NotPresentResult();
+    /** The unique instance for this class */
+    @SuppressWarnings("rawtypes")
+    /* No qualifier */ static final NotPresentResult NOT_PRESENT = new NotPresentResult();
     
+    /**
+     * A private void constructor, as we won't have any other instance.
+     */
     private NotPresentResult()
     {
         // Do nothing

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/ParentPos.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/ParentPos.java?rev=1356199&r1=1356198&r2=1356199&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/ParentPos.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/ParentPos.java Mon Jul  2 12:08:57 2012
@@ -20,13 +20,15 @@
 package org.apache.mavibot.btree;
 
 /**
+ * This class is used to store the parent page and the position in it during
+ * a browse operation. We have as many ParentPos instance than the depth of the tree.
  * 
  * @author <a href="mailto:labs@laps.apache.org">Mavibot labs Project</a>
  *
  * @param <K> The type for the Key
  * @param <V> The type for the stored value
  */
-public class ParentPos<K, V>
+/* No qualifier*/ class ParentPos<K, V>
 {
     /** The page we are browsing */
     /* No qualifier*/ Page<K, V> page;
@@ -34,7 +36,12 @@ public class ParentPos<K, V>
     /** The current position in the page */
     /* No qualifier*/ int pos;
     
-    public ParentPos( Page<K, V> page, int pos )
+    /**
+     * Creates a new instance of ParentPos
+     * @param page The current Page
+     * @param pos The current position in the page
+     */
+    /* No qualifier*/ ParentPos( Page<K, V> page, int pos )
     {
         this.page = page;
         this.pos = pos;

Modified: labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RemoveResult.java
URL: http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RemoveResult.java?rev=1356199&r1=1356198&r2=1356199&view=diff
==============================================================================
--- labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RemoveResult.java (original)
+++ labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/RemoveResult.java Mon Jul  2 12:08:57 2012
@@ -28,55 +28,18 @@ package org.apache.mavibot.btree;
 
  * @author <a href="mailto:labs@laps.apache.org">Mavibot labs Project</a>
  */
-/* No qualifier */ class RemoveResult<K, V> implements DeleteResult<K, V>
+/* No qualifier */ class RemoveResult<K, V> extends AbstractDeleteResult<K, V>
 {
-    /** The modified page reference */
-    protected Page<K, V> modifiedPage;
-    
-    /** The removed element if the key was found in the tree*/
-    protected Tuple<K, V> removedElement;
-    
-    /** The new leftmost element if the removed k was on position 0. Null otherwise */
-    protected K newLeftMost;
-    
     /**
      * The default constructor for RemoveResult.
      * 
      * @param modifiedPage The modified page
      * @param removedElement The removed element (can be null if the key wasn't present in the tree)
+     * @param newLeftMost The element on the left of he current page
      */
-    public RemoveResult( Page<K, V> modifiedPage, Tuple<K, V> removedElement, K newLeftMost )
-    {
-        this.modifiedPage = modifiedPage;
-        this.removedElement = removedElement;
-        this.newLeftMost = newLeftMost;
-    }
-    
-
-    /**
-     * @return the modifiedPage
-     */
-    public Page<K, V> getModifiedPage()
-    {
-        return modifiedPage;
-    }
-
-
-    /**
-     * @return the removed element
-     */
-    public Tuple<K, V> getRemovedElement()
-    {
-        return removedElement;
-    }
-
-
-    /**
-     * @return the newLeftMost
-     */
-    public K getNewLeftMost()
+    /* No qualifier */ RemoveResult( Page<K, V> modifiedPage, Tuple<K, V> removedElement, K newLeftMost )
     {
-        return newLeftMost;
+        super( modifiedPage, removedElement, newLeftMost );
     }
     
     



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