directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1529392 - in /directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer: AbstractElementSerializer.java ElementSerializer.java LongArraySerializer.java
Date Sat, 05 Oct 2013 06:42:08 GMT
Author: elecharny
Date: Sat Oct  5 06:42:08 2013
New Revision: 1529392

URL: http://svn.apache.org/r1529392
Log:
Injected the type into the serializers

Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/AbstractElementSerializer.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ElementSerializer.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongArraySerializer.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/AbstractElementSerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/AbstractElementSerializer.java?rev=1529392&r1=1529391&r2=1529392&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/AbstractElementSerializer.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/AbstractElementSerializer.java
Sat Oct  5 06:42:08 2013
@@ -20,6 +20,8 @@
 package org.apache.directory.mavibot.btree.serializer;
 
 
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.util.Comparator;
 
 
@@ -35,13 +37,34 @@ public abstract class AbstractElementSer
     /** The associated comparator */
     private final Comparator<T> comparator;
 
+    /** The type which is being serialized */
+    private Class<?> type;
+
 
     /**
-     * Create a new instance of BooleanSerializer
+     * Create a new instance of Serializer
      */
     public AbstractElementSerializer( Comparator<T> comparator )
     {
         this.comparator = comparator;
+
+        // We will extract the Type to use for values, using the serializer for that
+        Class<?> valueSerializerClass = comparator.getClass();
+        Type[] types = valueSerializerClass.getGenericInterfaces();
+
+        if ( types[0] instanceof Class )
+        {
+            type = ( Class<?> ) types[0];
+        }
+        else
+        {
+            Type[] argumentTypes = ( ( ParameterizedType ) types[0] ).getActualTypeArguments();
+
+            if ( ( argumentTypes != null ) && ( argumentTypes.length > 0 ) &&
( argumentTypes[0] instanceof Class<?> ) )
+            {
+                type = ( Class<?> ) argumentTypes[0];
+            }
+        }
     }
 
 
@@ -62,4 +85,14 @@ public abstract class AbstractElementSer
     {
         return comparator;
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Class<?> getType()
+    {
+        return type;
+    }
 }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ElementSerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ElementSerializer.java?rev=1529392&r1=1529391&r2=1529392&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ElementSerializer.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ElementSerializer.java
Sat Oct  5 06:42:08 2013
@@ -82,4 +82,10 @@ public interface ElementSerializer<T>
      * @return the comparator for the used type
      */
     Comparator<T> getComparator();
+
+
+    /**
+     * @return the type being serialized
+     */
+    Class<?> getType();
 }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongArraySerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongArraySerializer.java?rev=1529392&r1=1529391&r2=1529392&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongArraySerializer.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongArraySerializer.java
Sat Oct  5 06:42:08 2013
@@ -22,7 +22,6 @@ package org.apache.directory.mavibot.btr
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.util.Comparator;
 
 import org.apache.directory.mavibot.btree.comparator.LongArrayComparator;
 
@@ -32,18 +31,14 @@ import org.apache.directory.mavibot.btre
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class LongArraySerializer implements ElementSerializer<long[]>
+public class LongArraySerializer extends AbstractElementSerializer<long[]>
 {
-    /** The associated comparator */
-    private final Comparator<long[]> comparator;
-
-
     /**
      * Create a new instance of LongSerializer
      */
     public LongArraySerializer()
     {
-        comparator = new LongArrayComparator();
+        super( new LongArrayComparator() );
     }
 
 
@@ -261,14 +256,4 @@ public class LongArraySerializer impleme
             }
         }
     }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Comparator<long[]> getComparator()
-    {
-        return comparator;
-    }
 }



Mime
View raw message