All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.datalking.common.convert.support.StringToNumberConverterFactory Maven / Gradle / Ivy

The newest version!
package com.github.datalking.common.convert.support;

import com.github.datalking.common.convert.converter.Converter;
import com.github.datalking.common.convert.converter.ConverterFactory;
import com.github.datalking.util.NumberUtils;

/**
 */
public final class StringToNumberConverterFactory implements ConverterFactory {

    public  Converter getConverter(Class targetType) {

        return new StringToNumber<>(targetType);
    }

    private static final class StringToNumber implements Converter {

        private final Class targetType;

        public StringToNumber(Class targetType) {
            this.targetType = targetType;
        }

        public T convert(String source) {
            if (source.length() == 0) {
                return null;
            }

            return NumberUtils.parseNumber(source, this.targetType);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy