public class ConverterRegistry extends Object implements Serializable
转换器登记中心
将各种类型Convert对象放入登记中心,通过convert方法查找目标类型对应的转换器,将被转换对象转换之。
在此类中,存放着默认转换器和自定义转换器,默认转换器是jarvis-tool中预定义的一些转换器,自定义转换器存放用户自定的转换器。
| 限定符和类型 | 类和说明 |
|---|---|
private static class |
ConverterRegistry.SingletonHolder
类级的内部类,也就是静态的成员式内部类,该内部类的实例与外部类的实例 没有绑定关系,而且只有被调用到才会装载,从而实现了延迟加载
|
| 限定符和类型 | 字段和说明 |
|---|---|
private Map<Type,Converter<?>> |
customConverterMap
用户自定义类型转换器
|
private Map<Type,Converter<?>> |
defaultConverterMap
默认类型转换器
|
private static long |
serialVersionUID |
| 构造器和说明 |
|---|
ConverterRegistry() |
| 限定符和类型 | 方法和说明 |
|---|---|
<T> T |
convert(Type type,
Object value)
转换值为指定类型
|
<T> T |
convert(Type type,
Object value,
T defaultValue)
转换值为指定类型
自定义转换器优先 |
<T> T |
convert(Type type,
Object value,
T defaultValue,
boolean isCustomFirst)
转换值为指定类型
|
private <T> T |
convertSpecial(Type type,
Class<T> rowType,
Object value,
T defaultValue)
特殊类型转换
包括: Collection Map 强转(无需转换) 数组 |
private ConverterRegistry |
defaultConverter()
注册默认转换器
|
<T> Converter<T> |
getConverter(Type type,
boolean isCustomFirst)
获得转换器
|
<T> Converter<T> |
getCustomConverter(Type type)
获得自定义转换器
|
<T> Converter<T> |
getDefaultConverter(Type type)
获得默认转换器
|
static ConverterRegistry |
getInstance()
获得单例的
ConverterRegistry |
ConverterRegistry |
putCustom(Type type,
Class<? extends Converter<?>> converterClass)
登记自定义转换器
|
ConverterRegistry |
putCustom(Type type,
Converter<?> converter)
登记自定义转换器
|
private static final long serialVersionUID
public static ConverterRegistry getInstance()
ConverterRegistrypublic ConverterRegistry putCustom(Type type, Class<? extends Converter<?>> converterClass)
type - 转换的目标类型converterClass - 转换器类,必须有默认构造方法ConverterRegistrypublic ConverterRegistry putCustom(Type type, Converter<?> converter)
type - 转换的目标类型converter - 转换器ConverterRegistrypublic <T> Converter<T> getConverter(Type type, boolean isCustomFirst)
T - 转换的目标类型type - 类型isCustomFirst - 是否自定义转换器优先public <T> Converter<T> getDefaultConverter(Type type)
T - 转换的目标类型(转换器转换到的类型)type - 类型public <T> Converter<T> getCustomConverter(Type type)
T - 转换的目标类型(转换器转换到的类型)type - 类型public <T> T convert(Type type, Object value, T defaultValue, boolean isCustomFirst) throws ConvertException
T - 转换的目标类型(转换器转换到的类型)type - 类型目标value - 被转换值defaultValue - 默认值isCustomFirst - 是否自定义转换器优先ConvertException - 转换器不存在public <T> T convert(Type type, Object value, T defaultValue) throws ConvertException
T - 转换的目标类型(转换器转换到的类型)type - 类型value - 值defaultValue - 默认值ConvertException - 转换器不存在public <T> T convert(Type type, Object value) throws ConvertException
T - 转换的目标类型(转换器转换到的类型)type - 类型value - 值nullConvertException - 转换器不存在private <T> T convertSpecial(Type type, Class<T> rowType, Object value, T defaultValue)
Collection Map 强转(无需转换) 数组
T - 转换的目标类型(转换器转换到的类型)type - 类型value - 值defaultValue - 默认值private ConverterRegistry defaultConverter()
Copyright © 2020. All rights reserved.