com.github.datalking.common.convert.support.NumberToNumberConverterFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of play-mvc Show documentation
Show all versions of play-mvc Show documentation
simple mvc framework based on java servlet.
The newest version!
package com.github.datalking.common.convert.support;
import com.github.datalking.common.convert.converter.ConditionalConverter;
import com.github.datalking.common.convert.converter.Converter;
import com.github.datalking.common.convert.converter.ConverterFactory;
import com.github.datalking.common.convert.descriptor.TypeDescriptor;
import com.github.datalking.util.NumberUtils;
/**
* @author yaoo on 5/10/18
*/
public final class NumberToNumberConverterFactory
implements ConverterFactory, ConditionalConverter {
public Converter getConverter(Class targetType) {
return new NumberToNumber<>(targetType);
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return !sourceType.equals(targetType);
}
private final static class NumberToNumber implements Converter {
private final Class targetType;
public NumberToNumber(Class targetType) {
this.targetType = targetType;
}
public T convert(Number source) {
return NumberUtils.convertNumberToTargetClass(source, this.targetType);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy