package com.netflix.astyanax.serializers;

import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.UUID;

import com.netflix.astyanax.Serializer;

/**
 * Utility class that infers the concrete Serializer needed to turn a value into
 * its binary representation
 * 
 * @author Bozhidar Bozhanov
 * 
 */
public class SerializerTypeInferer {

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static <T> Serializer<T> getSerializer(Object value) {
        Serializer serializer = null;
        if (value == null) {
            serializer = ByteBufferSerializer.get();
        }
        else if (value instanceof UUID) {
            serializer = UUIDSerializer.get();
        }
        else if (value instanceof String) {
            serializer = StringSerializer.get();
        }
        else if (value instanceof Long) {
            serializer = LongSerializer.get();
        }
        else if (value instanceof Integer) {
            serializer = IntegerSerializer.get();
        }
        else if (value instanceof Short) {
            serializer = ShortSerializer.get();
        }
        else if (value instanceof BigInteger) {
            serializer = BigIntegerSerializer.get();
        }
        else if (value instanceof Boolean) {
            serializer = BooleanSerializer.get();
        }
        else if (value instanceof byte[]) {
            serializer = BytesArraySerializer.get();
        }
        else if (value instanceof ByteBuffer) {
            serializer = ByteBufferSerializer.get();
        }
        else if (value instanceof Date) {
            serializer = DateSerializer.get();
        }
        else {
            serializer = ObjectSerializer.get();
        }
        // Add other serializers here

        return serializer;
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static <T> Serializer<T> getSerializer(Class<?> valueClass) {
        Serializer serializer = null;
        if (valueClass.equals(UUID.class)) {
            serializer = UUIDSerializer.get();
        }
        else if (valueClass.equals(String.class)) {
            serializer = StringSerializer.get();
        }
        else if (valueClass.equals(Long.class) || valueClass.equals(long.class)) {
            serializer = LongSerializer.get();
        }
        else if (valueClass.equals(Integer.class) || valueClass.equals(int.class)) {
            serializer = IntegerSerializer.get();
        }
        else if (valueClass.equals(Short.class) || valueClass.equals(short.class)) {
            serializer = ShortSerializer.get();
        }
        else if (valueClass.equals(Boolean.class) || valueClass.equals(boolean.class)) {
            serializer = BooleanSerializer.get();
        }
        else if (valueClass.equals(byte[].class)) {
            serializer = BytesArraySerializer.get();
        }
        else if (valueClass.equals(ByteBuffer.class)) {
            serializer = ByteBufferSerializer.get();
        }
        else if (valueClass.equals(Date.class)) {
            serializer = DateSerializer.get();
        }
        else {
            serializer = ObjectSerializer.get();
        }
        // Add other serializers here

        return serializer;
    }
}

@@ -1021,36 +1021,34 @@
 serializer = Int
-eger
+32
 Serializer.get()
@@ -1101,24 +1101,24 @@
 f Short) %7B%0D%0A
-
             
@@ -1157,32 +1157,238 @@
 ();%0D%0A        %7D%0D%0A
+        else if (value instanceof Float) %7B%0D%0A            serializer = FloatSerializer.get();%0D%0A        %7D%0D%0A        else if (value instanceof Byte) %7B%0D%0A            serializer = ByteSerializer.get();%0D%0A        %7D%0D%0A
         else if 
@@ -2715,20 +2715,18 @@
 er = Int
-eger
+32
 Serializ
@@ -2825,32 +2825,32 @@
 hort.class)) %7B%0D%0A
-
             seri
@@ -2885,32 +2885,321 @@
 ();%0D%0A        %7D%0D%0A
+        else if (valueClass.equals(Float.class) %7C%7C valueClass.equals(float.class)) %7B%0D%0A            serializer = FloatSerializer.get();%0D%0A        %7D%0D%0A        else if (valueClass.equals(Byte.class) %7C%7C valueClass.equals(byte.class)) %7B%0D%0A            serializer = ByteSerializer.get();%0D%0A        %7D%0D%0A
         else if 

Update SerializerTypeInferer for new types