public class NumberConverter extends AbstractConverter<Number>
java.lang.Byte
java.lang.Short
java.lang.Integer
java.util.concurrent.atomic.AtomicInteger
java.lang.Long
java.util.concurrent.atomic.AtomicLong
java.lang.Float
java.lang.Double
java.math.BigDecimal
java.math.BigInteger
Constructor and Description |
---|
NumberConverter() |
NumberConverter(Class<? extends Number> clazz)
构造
|
Modifier and Type | Method and Description |
---|---|
protected static Number |
convert(Object value,
Class<?> targetType,
Function<Object,String> toStrFunc)
转换对象为数字
|
protected Number |
convertInternal(Object value)
内部转换器,被
AbstractConverter.convert(Object, Object) 调用,实现基本转换逻辑内部转换器转换后如果转换失败可以做如下操作,处理结果都为返回默认值: |
protected String |
convertToStr(Object value)
值转为String,用于内部转换中需要使用String中转的情况
转换规则为: |
Class<Number> |
getTargetType()
获得此类实现类的泛型类型
|
convert, convertQuietly
protected Number convertInternal(Object value)
AbstractConverter
AbstractConverter.convert(Object, Object)
调用,实现基本转换逻辑1、返回null
2、抛出一个RuntimeException
异常
convertInternal
in class AbstractConverter<Number>
value
- 值protected static Number convert(Object value, Class<?> targetType, Function<Object,String> toStrFunc)
value
- 对象值targetType
- 目标的数字类型toStrFunc
- 转换为字符串的函数protected String convertToStr(Object value)
AbstractConverter
1、字符串类型将被强转 2、数组将被转换为逗号分隔的字符串 3、其它类型将调用默认的toString()方法
convertToStr
in class AbstractConverter<Number>
value
- 值public Class<Number> getTargetType()
AbstractConverter
getTargetType
in class AbstractConverter<Number>
null
Copyright © 2021. All rights reserved.