![JAR search and dependency download from the Maven repository](/logo.png)
cn.featherfly.conversion.string.format.FormatConvertor Maven / Gradle / Ivy
package cn.featherfly.conversion.string.format;
import cn.featherfly.common.lang.GenericType;
import cn.featherfly.conversion.string.AbstractToStringConvertor;
import cn.featherfly.conversion.string.ToStringConvertor;
/**
*
* 格式化转换器
*
* @param 转换对象
* @author 钟冀
*/
public abstract class FormatConvertor extends AbstractToStringConvertor>{
private ToStringConvertor convertor;
/**
* @param convertor convertor
*/
public FormatConvertor(ToStringConvertor convertor) {
this.convertor = convertor;
}
/**
* {@inheritDoc}
*/
@Override
protected boolean supportFor(GenericType generecType) {
if (generecType == null) {
return false;
}
return FormatType.class == generecType.getClass();
}
/**
* {@inheritDoc}
*/
@Override
protected String doToString(T value, FormatType genericType) {
String result = formatToString(value, genericType);
if (result == null) {
return convertor.sourceToTarget(value, null);
}
return result;
}
/**
* {@inheritDoc}
*/
@Override
protected T doToObject(String value, FormatType genericType) {
T result = formatToObject(value, genericType);
if (result == null) {
return convertor.targetToSource(value, null);
}
return result;
}
/**
* 返回convertor
* @return convertor
*/
public ToStringConvertor getConvertor() {
return convertor;
}
/**
*
* 对象转换为字符串
*
* @param value 对象
* @param genericType 指定对象的上下文属性
* @return 字符串
*/
protected abstract String formatToString(T value, FormatType genericType);
/**
*
* 字符串转换为对象
*
* @param value 字符串
* @param genericType 指定对象的上下文属性
* @return 对象
*/
protected abstract T formatToObject(String value, FormatType genericType);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy