Author: kayyagari
Date: Wed Jul  3 11:41:22 2013
New Revision: 1499333

URL: http://svn.apache.org/r1499333
Log:
o added a checks to avoid ClassCastException while deriving the key type
o set the comparator also while setting the serializer

Modified:
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.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=1499333&r1=1499332&r2=1499333&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 
Wed Jul  3 11:41:22 2013
@@ -496,11 +496,19 @@ public class BTree<K, V>
         // We will extract the Type to use for keys, using the comparator for 
that
         Class<?> comparatorClass = comparator.getClass();
         Type[] types = comparatorClass.getGenericInterfaces();
-        Type[] argumentTypes = ( ( ParameterizedType ) types[0] 
).getActualTypeArguments();
-
-        if ( ( argumentTypes != null ) && ( argumentTypes.length > 0 ) && ( 
argumentTypes[0] instanceof Class<?> ) )
+        
+        if ( types[0] instanceof Class )
+        {
+               keyType = ( Class<?> ) types[0];
+        }
+        else
         {
-            keyType = ( Class<?> ) argumentTypes[0];
+               Type[] argumentTypes = ( ( ParameterizedType ) types[0] 
).getActualTypeArguments();
+               
+               if ( ( argumentTypes != null ) && ( argumentTypes.length > 0 ) 
&& ( argumentTypes[0] instanceof Class<?> ) )
+               {
+                       keyType = ( Class<?> ) argumentTypes[0];
+               }
         }
 
         writeLock = new ReentrantLock();
@@ -1314,6 +1322,7 @@ public class BTree<K, V>
     public void setKeySerializer( ElementSerializer<K> keySerializer )
     {
         this.keySerializer = keySerializer;
+        this.comparator = keySerializer.getComparator();
         btreeHeader.setKeySerializerFQCN( keySerializer.getClass().getName() );
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to