directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1512440 - in /directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree: BTree.java BTreeBuilder.java BTreeFactory.java Node.java ReferenceHolder.java serializer/ByteArraySerializer.java serializer/StringSerializer.java
Date Fri, 09 Aug 2013 18:44:12 GMT
Author: elecharny
Date: Fri Aug  9 18:44:11 2013
New Revision: 1512440

URL: http://svn.apache.org/r1512440
Log:
Some more generic fixes

Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Node.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/ReferenceHolder.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteArraySerializer.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/StringSerializer.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java?rev=1512440&r1=1512439&r2=1512440&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
Fri Aug  9 18:44:11 2013
@@ -1217,11 +1217,11 @@ public class BTree<K, V>
                     leftPage, revision );
 
                 // Store the offset on disk in the page
-                ( ( AbstractPage ) splitResult.getLeftPage() )
+                ( ( AbstractPage<K, V> ) splitResult.getLeftPage() )
                     .setOffset( ( ( ReferenceHolder ) holderLeft ).getOffset() );
 
                 // Store the last offset on disk in the page
-                ( ( AbstractPage ) splitResult.getLeftPage() )
+                ( ( AbstractPage<K, V> ) splitResult.getLeftPage() )
                     .setLastOffset( ( ( ReferenceHolder ) holderLeft ).getLastOffset() );
 
                 ElementHolder<Page<K, V>, K, V> holderRight = recordManager.writePage(
this,
@@ -1607,7 +1607,6 @@ public class BTree<K, V>
      * @throws IOException If we had an issue while accessing the underlying file
      * @throws KeyNotFoundException If the revision does not exist for this Btree
      */
-    @SuppressWarnings("unchecked")
     private Page<K, V> getRootPage( long revision ) throws IOException, KeyNotFoundException
     {
         if ( isManaged() )
@@ -1754,7 +1753,7 @@ public class BTree<K, V>
             if ( value instanceof Page )
             {
                 return new ReferenceHolder<Page<K, V>, K, V>( this, ( Page<K,
V> ) value,
-                    ( ( Page ) value ).getOffset(), ( ( Page ) value ).getLastOffset() );
+                    ( ( Page<K, V> ) value ).getOffset(), ( ( Page<K, V> ) value
).getLastOffset() );
             }
             else if ( isAllowDuplicates() )
             {

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java?rev=1512440&r1=1512439&r2=1512440&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeBuilder.java
Fri Aug  9 18:44:11 2013
@@ -129,7 +129,7 @@ public class BTreeBuilder<K, V>
     }
 
 
-    private Page<K, V> attachNodes( List<Page<K, V>> children, BTree btree
) throws IOException
+    private Page<K, V> attachNodes( List<Page<K, V>> children, BTree<K,
V> btree ) throws IOException
     {
         if ( children.size() == 1 )
         {

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java?rev=1512440&r1=1512439&r2=1512440&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java
Fri Aug  9 18:44:11 2013
@@ -41,9 +41,9 @@ public class BTreeFactory
      * 
      * @return The created BTree
      */
-    public static BTree createBTree()
+    public static <K, V> BTree<K, V> createBTree()
     {
-        BTree btree = new BTree();
+        BTree<K, V> btree = new BTree<K, V>();
 
         return btree;
     }
@@ -57,9 +57,9 @@ public class BTreeFactory
      * @param nbElems The number or elements in this node
      * @return A Node instance
      */
-    public static Node createNode( BTree btree, long revision, int nbElems )
+    public static <K, V> Node<K, V> createNode( BTree<K, V> btree, long
revision, int nbElems )
     {
-        Node node = new Node( btree, revision, nbElems );
+        Node<K, V> node = new Node<K, V>( btree, revision, nbElems );
 
         return node;
     }
@@ -73,9 +73,9 @@ public class BTreeFactory
      * @param nbElems The number or elements in this leaf
      * @return A Leaf instance
      */
-    public static Leaf createLeaf( BTree btree, long revision, int nbElems )
+    public static <K, V> Leaf<K, V> createLeaf( BTree<K, V> btree, long
revision, int nbElems )
     {
-        Leaf leaf = new Leaf( btree, revision, nbElems );
+        Leaf<K, V> leaf = new Leaf<K, V>( btree, revision, nbElems );
 
         return leaf;
     }
@@ -87,7 +87,7 @@ public class BTreeFactory
      * 
      * @param root the new root page.
      */
-    public static void setRoot( BTree<?, ?> btree, Page root )
+    public static <K, V> void setRoot( BTree<K, V> btree, Page<K, V> root
)
     {
         btree.setRoot( root );
     }
@@ -99,7 +99,7 @@ public class BTreeFactory
      * @param btree The Btree we want to root page from
      * @return The root page
      */
-    public static Page getRoot( BTree<?, ?> btree )
+    public static <K, V> Page<K, V> getRoot( BTree<K, V> btree )
     {
         return btree.rootPage;
     }
@@ -108,7 +108,7 @@ public class BTreeFactory
     /**
      * @param nbElems the nbElems to set
      */
-    public static void setNbElems( BTree<?, ?> btree, long nbElems )
+    public static <K, V> void setNbElems( BTree<K, V> btree, long nbElems )
     {
         btree.setNbElems( nbElems );
     }
@@ -117,7 +117,7 @@ public class BTreeFactory
     /**
      * @param revision the revision to set
      */
-    public static void setRevision( BTree<?, ?> btree, long revision )
+    public static <K, V> void setRevision( BTree<K, V> btree, long revision )
     {
         btree.setRevision( revision );
     }
@@ -126,7 +126,7 @@ public class BTreeFactory
     /**
      * @param rootPageOffset the rootPageOffset to set
      */
-    public static void setRootPageOffset( BTree<?, ?> btree, long rootPageOffset )
+    public static <K, V> void setRootPageOffset( BTree<K, V> btree, long rootPageOffset
)
     {
         btree.setRootPageOffset( rootPageOffset );
     }
@@ -135,7 +135,7 @@ public class BTreeFactory
     /**
      * @param nextBTreeOffset the nextBTreeOffset to set
      */
-    public static void setNextBTreeOffset( BTree<?, ?> btree, long nextBTreeOffset
)
+    public static <K, V> void setNextBTreeOffset( BTree<K, V> btree, long nextBTreeOffset
)
     {
         btree.setNextBTreeOffset( nextBTreeOffset );
     }
@@ -144,7 +144,7 @@ public class BTreeFactory
     /**
      * @param name the name to set
      */
-    public static void setName( BTree<?, ?> btree, String name )
+    public static <K, V> void setName( BTree<K, V> btree, String name )
     {
         btree.setName( name );
     }
@@ -159,7 +159,7 @@ public class BTreeFactory
      * @throws InstantiationException 
      * @throws IllegalAccessException
      */
-    public static void setKeySerializer( BTree<?, ?> btree, String keySerializerFqcn
)
+    public static <K, V> void setKeySerializer( BTree<K, V> btree, String keySerializerFqcn
)
         throws ClassNotFoundException, IllegalAccessException, InstantiationException
     {
         Class<?> keySerializer = Class.forName( keySerializerFqcn );
@@ -179,7 +179,7 @@ public class BTreeFactory
      * @throws InstantiationException 
      * @throws IllegalAccessException
      */
-    public static void setValueSerializer( BTree<?, ?> btree, String valueSerializerFqcn
)
+    public static <K, V> void setValueSerializer( BTree<K, V> btree, String valueSerializerFqcn
)
         throws ClassNotFoundException, IllegalAccessException, InstantiationException
     {
         Class<?> valueSerializer = Class.forName( valueSerializerFqcn );
@@ -192,7 +192,7 @@ public class BTreeFactory
      * 
      * @param pageSize The requested page size
      */
-    public static void setPageSize( BTree<?, ?> btree, int pageSize )
+    public static <K, V> void setPageSize( BTree<K, V> btree, int pageSize )
     {
         btree.setPageSize( pageSize );
     }
@@ -203,7 +203,7 @@ public class BTreeFactory
      * 
      * @param recordManager The injected RecordManager
      */
-    public static void setRecordManager( BTree<?, ?> btree, RecordManager recordManager
)
+    public static <K, V> void setRecordManager( BTree<K, V> btree, RecordManager
recordManager )
     {
         btree.setRecordManager( recordManager );
     }
@@ -214,9 +214,9 @@ public class BTreeFactory
      * @param pos The position in the keys array
      * @param key the key to inject
      */
-    public static void setKey( Page page, int pos, Object key )
+    public static <K, V> void setKey( Page<K, V> page, int pos, K key )
     {
-        ( ( AbstractPage ) page ).setKey( pos, key );
+        ( ( AbstractPage<K, V> ) page ).setKey( pos, key );
     }
 
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Node.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Node.java?rev=1512440&r1=1512439&r2=1512440&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Node.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Node.java
Fri Aug  9 18:44:11 2013
@@ -886,7 +886,15 @@ import org.apache.directory.mavibot.btre
         }
         else
         {
-            return children[pos].getValue( btree ).hasKey( key );
+            Page<K, V> page = children[pos].getValue( btree );
+
+            if ( page == null )
+            {
+                System.out.println( "Page is null for pos = " + pos + ", children = " + children[pos]
);
+                System.out.println( "Key = " + key );
+            }
+
+            return page.hasKey( key );
         }
     }
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/ReferenceHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/ReferenceHolder.java?rev=1512440&r1=1512439&r2=1512440&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/ReferenceHolder.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/ReferenceHolder.java
Fri Aug  9 18:44:11 2013
@@ -80,11 +80,15 @@ public class ReferenceHolder<E, K, V> im
         if ( element == null )
         {
             // We have to fetch the element from disk, using the offset now
-            element = fetchElement( btree );
-            reference = new SoftReference( element );
-        }
+            Page<K, V> page = fetchElement( btree );
+            reference = ( SoftReference<E> ) new SoftReference<Page<K, V>>(
page );
 
-        return element;
+            return ( E ) page;
+        }
+        else
+        {
+            return element;
+        }
     }
 
 
@@ -94,9 +98,9 @@ public class ReferenceHolder<E, K, V> im
      * @throws IOException 
      * @throws EndOfFileExceededException 
      */
-    private E fetchElement( BTree<K, V> btree ) throws EndOfFileExceededException,
IOException
+    private Page<K, V> fetchElement( BTree<K, V> btree ) throws EndOfFileExceededException,
IOException
     {
-        E element = ( E ) btree.getRecordManager().deserialize( btree, offset );
+        Page<K, V> element = btree.getRecordManager().deserialize( btree, offset );
 
         return element;
     }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteArraySerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteArraySerializer.java?rev=1512440&r1=1512439&r2=1512440&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteArraySerializer.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteArraySerializer.java
Fri Aug  9 18:44:11 2013
@@ -46,7 +46,7 @@ public class ByteArraySerializer extends
     /**
      * Create a new instance of ByteArraySerializer with custom comparator
      */
-    public ByteArraySerializer( Comparator comparator )
+    public ByteArraySerializer( Comparator<byte[]> comparator )
     {
         super( comparator );
     }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/StringSerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/StringSerializer.java?rev=1512440&r1=1512439&r2=1512440&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/StringSerializer.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/StringSerializer.java
Fri Aug  9 18:44:11 2013
@@ -51,7 +51,7 @@ public class StringSerializer extends Ab
     /**
      * Create a new instance of StringSerializer with custom comparator
      */
-    public StringSerializer( Comparator comparator )
+    public StringSerializer( Comparator<String> comparator )
     {
         super( comparator );
     }



Mime
View raw message