package com.arondor.common.reflection.reflect.instantiator;

import java.util.HashMap;
import java.util.Map;

public class FastPrimitiveConverter
{
    private interface PrimitiveConverter
    {
        Object convert(String value);
    }

    private final Map<String, PrimitiveConverter> primitiveConverterMap = new HashMap<String, FastPrimitiveConverter.PrimitiveConverter>();

    public FastPrimitiveConverter()
    {
        primitiveConverterMap.put("java.lang.String", new PrimitiveConverter()
        {
            public Object convert(String value)
            {
                return value;
            }
        });
        primitiveConverterMap.put("long", new PrimitiveConverter()
        {
            public Object convert(String value)
            {
                return Long.parseLong(value);
            }
        });
        primitiveConverterMap.put("int", new PrimitiveConverter()
        {
            public Object convert(String value)
            {
                return Integer.parseInt(value);
            }
        });
        primitiveConverterMap.put("boolean", new PrimitiveConverter()
        {
            public Object convert(String value)
            {
                return Boolean.parseBoolean(value);
            }
        });
    }

    public Object convert(String value, String primitiveClass)
    {
        PrimitiveConverter converter = primitiveConverterMap.get(primitiveClass);
        if (converter == null)
        {
            throw new IllegalArgumentException("Not supported : primitiveClass=" + primitiveClass);
        }
        return converter.convert(value);
    }
}

package com.arondor.common.reflection.reflect.instantiator;

import java.util.HashMap;
import java.util.Map;

public class FastPrimitiveConverter
{
    private interface PrimitiveConverter
    {
        Object convert(String value);
    }

    private final Map<String, PrimitiveConverter> primitiveConverterMap = new HashMap<String, FastPrimitiveConverter.PrimitiveConverter>();

    public FastPrimitiveConverter()
    {
        primitiveConverterMap.put("java.lang.String", new PrimitiveConverter()
        {
            public Object convert(String value)
            {
                return value;
            }
        });
        primitiveConverterMap.put("long", new PrimitiveConverter()
        {
            public Object convert(String value)
            {
                return Long.parseLong(value);
            }
        });
        primitiveConverterMap.put("int", new PrimitiveConverter()
        {
            public Object convert(String value)
            {
                return Integer.parseInt(value);
            }
        });
        primitiveConverterMap.put("boolean", new PrimitiveConverter()
        {
            public Object convert(String value)
            {
                return Boolean.parseBoolean(value);
            }
        });
        primitiveConverterMap.put("float", new PrimitiveConverter()
        {
            public Object convert(String value)
            {
                return Float.parseFloat(value);
            }
        });
    }

    public Object convert(String value, String primitiveClass)
    {
        PrimitiveConverter converter = primitiveConverterMap.get(primitiveClass);
        if (converter == null)
        {
            throw new IllegalArgumentException("Not supported : primitiveClass=" + primitiveClass);
        }
        return converter.convert(value);
    }
}

Add support for float primitive
Add support for float primitive

git-svn-id: 7e8def7d4256e953abb468098d8cb9b4faff0c63@6213 12255794-1b5b-4525-b599-b0510597569d
