类 Convert
java.lang.Object
com.alibaba.ageiport.common.convert.Convert
类型转换器
- 作者:
- xuechao.sxc
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static intbytesToInt(byte[] bytes) byte[]转int值static longbytesToLong(byte[] bytes) byte数组转long
from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-javastatic shortbytesToShort(byte[] bytes) byte数组转shortstatic intbyteToUnsignedInt(byte byteValue) byte转无符号intstatic <T> Tconvert(TypeReference<T> reference, Object value) 转换值为指定类型static <T> T转换值为指定类型static <T> T转换值为指定类型static <T> T转换值为指定类型static <T> T转换值为指定类型static <T> TconvertQuietly(Type type, Object value) 转换值为指定类型,不抛异常转换
当转换失败时返回nullstatic <T> TconvertQuietly(Type type, Object value, T defaultValue) 转换值为指定类型,不抛异常转换
当转换失败时返回默认值static byteintToByte(int intValue) int转bytestatic byte[]intToBytes(int intValue) int转byte数组static byte[]longToBytes(long longValue) long转byte数组
from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-javastatic byte[]shortToBytes(short shortValue) short转byte数组static BigDecimaltoBigDecimal(Object value) 转换为BigDecimal
如果给定的值为空,或者转换失败,返回null
转换失败不会报错static BigDecimaltoBigDecimal(Object value, BigDecimal defaultValue) 转换为BigDecimal
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错static BigIntegertoBigInteger(Object value) 转换为BigInteger
如果给定的值为空,或者转换失败,返回默认值null
转换失败不会报错static BigIntegertoBigInteger(Object value, BigInteger defaultValue) 转换为BigInteger
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错static Boolean转换为boolean
如果给定的值为空,或者转换失败,返回默认值null
转换失败不会报错static Boolean转换为boolean
String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错static Boolean[]toBooleanArray(Object value) 转换为Boolean数组static Byte转换为byte
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错static Byte转换为byte
如果给定的值为null,或者转换失败,返回默认值
转换失败不会报错static Byte[]toByteArray(Object value) 转换为Byte数组static Character转换为字符
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错static Character转换为字符
如果给定的值为null,或者转换失败,返回默认值
转换失败不会报错static Character[]toCharArray(Object value) 转换为Character数组static Date转换为Date
如果给定的值为空,或者转换失败,返回null
转换失败不会报错static Date转换为Date
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错static String全角转半角static String替换全角为半角static Double转换为double
如果给定的值为空,或者转换失败,返回默认值null
转换失败不会报错static Double转换为double
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错static Double[]toDoubleArray(Object value) 转换为Double数组static Float转换为Float
如果给定的值为空,或者转换失败,返回默认值null
转换失败不会报错static Float转换为Float
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错static Float[]toFloatArray(Object value) 转换为Float数组static DateInstant
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错static Integer转换为int
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错static Integer转换为int
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错static Integer[]toIntArray(Object value) 转换为Integer数组static List<?>转换为ArrayList,元素类型默认Objectstatic java.time.LocalDateTimetoLocalDateTime(Object value) 转换为LocalDateTime
如果给定的值为空,或者转换失败,返回null
转换失败不会报错static java.time.LocalDateTimetoLocalDateTime(Object value, java.time.LocalDateTime defaultValue) LocalDateTime
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错static Long转换为long
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错static Long转换为long
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错static Long[]toLongArray(Object value) 转换为Long数组static Number转换为Number
如果给定的值为空,或者转换失败,返回默认值null
转换失败不会报错static Number转换为Number
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错static Number[]toNumberArray(Object value) 转换为Number数组static byte[]toPrimitiveByteArray(Object value) 转换为Byte数组static String半角转全角static String半角转全角static Short转换为Short
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错static Short转换为Short
如果给定的值为null,或者转换失败,返回默认值
转换失败不会报错static Short[]toShortArray(Object value) 转换为Short数组static String转换为字符串
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错static String转换为字符串
如果给定的值为null,或者转换失败,返回默认值
转换失败不会报错static String[]toStrArray(Object value) 转换为String数组static Class<?>包装类转为原始类,非包装类返回原类static Class<?>原始类转为包装类,非原始类返回原类
-
构造器详细资料
-
Convert
public Convert()
-
-
方法详细资料
-
toStr
转换为字符串
如果给定的值为null,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toStr
转换为字符串
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toStrArray
转换为String数组- 参数:
value- 被转换的值- 返回:
- String数组
-
toChar
转换为字符
如果给定的值为null,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toChar
转换为字符
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toCharArray
转换为Character数组- 参数:
value- 被转换的值- 返回:
- Character数组
-
toByte
转换为byte
如果给定的值为null,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toByte
转换为byte
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toByteArray
转换为Byte数组- 参数:
value- 被转换的值- 返回:
- Byte数组
-
toPrimitiveByteArray
转换为Byte数组- 参数:
value- 被转换的值- 返回:
- Byte数组
-
toShort
转换为Short
如果给定的值为null,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toShort
转换为Short
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toShortArray
转换为Short数组- 参数:
value- 被转换的值- 返回:
- Short数组
-
toNumber
转换为Number
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toNumber
转换为Number
如果给定的值为空,或者转换失败,返回默认值null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toNumberArray
转换为Number数组- 参数:
value- 被转换的值- 返回:
- Number数组
-
toInt
转换为int
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toInt
转换为int
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toIntArray
转换为Integer数组- 参数:
value- 被转换的值- 返回:
- 结果
-
toLong
转换为long
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toLong
转换为long
如果给定的值为null,或者转换失败,返回默认值null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toLongArray
转换为Long数组- 参数:
value- 被转换的值- 返回:
- 结果
-
toDouble
转换为double
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toDouble
转换为double
如果给定的值为空,或者转换失败,返回默认值null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toDoubleArray
转换为Double数组- 参数:
value- 被转换的值- 返回:
- 结果
-
toFloat
转换为Float
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toFloat
转换为Float
如果给定的值为空,或者转换失败,返回默认值null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toFloatArray
转换为Float数组- 参数:
value- 被转换的值- 返回:
- 结果
-
toBool
转换为boolean
String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toBool
转换为boolean
如果给定的值为空,或者转换失败,返回默认值null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toBooleanArray
转换为Boolean数组- 参数:
value- 被转换的值- 返回:
- 结果
-
toBigInteger
转换为BigInteger
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toBigInteger
转换为BigInteger
如果给定的值为空,或者转换失败,返回默认值null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toBigDecimal
转换为BigDecimal
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toBigDecimal
转换为BigDecimal
如果给定的值为空,或者转换失败,返回null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toDate
转换为Date
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toLocalDateTime
public static java.time.LocalDateTime toLocalDateTime(Object value, java.time.LocalDateTime defaultValue) LocalDateTime
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toLocalDateTime
转换为LocalDateTime
如果给定的值为空,或者转换失败,返回null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toInstant
Instant
如果给定的值为空,或者转换失败,返回默认值
转换失败不会报错- 参数:
value- 被转换的值defaultValue- 转换错误时的默认值- 返回:
- 结果
-
toDate
转换为Date
如果给定的值为空,或者转换失败,返回null
转换失败不会报错- 参数:
value- 被转换的值- 返回:
- 结果
-
toList
转换为ArrayList,元素类型默认Object- 参数:
value- 被转换的值- 返回:
List
-
convert
转换值为指定类型- 类型参数:
T- 目标类型- 参数:
type- 类型value- 值- 返回:
- 转换后的值
- 抛出:
ConvertException- 转换器不存在
-
convert
转换值为指定类型- 类型参数:
T- 目标类型- 参数:
reference- 类型参考,用于持有转换后的泛型类型value- 值- 返回:
- 转换后的值
- 抛出:
ConvertException- 转换器不存在
-
convert
转换值为指定类型- 类型参数:
T- 目标类型- 参数:
type- 类型value- 值- 返回:
- 转换后的值
- 抛出:
ConvertException- 转换器不存在
-
convert
转换值为指定类型- 类型参数:
T- 目标类型- 参数:
type- 类型value- 值defaultValue- 默认值- 返回:
- 转换后的值
- 抛出:
ConvertException- 转换器不存在
-
convert
转换值为指定类型- 类型参数:
T- 目标类型- 参数:
type- 类型value- 值defaultValue- 默认值- 返回:
- 转换后的值
- 抛出:
ConvertException- 转换器不存在
-
convertQuietly
转换值为指定类型,不抛异常转换
当转换失败时返回null- 类型参数:
T- 目标类型- 参数:
type- 目标类型value- 值- 返回:
- 转换后的值,转换失败返回null
-
convertQuietly
转换值为指定类型,不抛异常转换
当转换失败时返回默认值- 类型参数:
T- 目标类型- 参数:
type- 目标类型value- 值defaultValue- 默认值- 返回:
- 转换后的值
-
toSBC
半角转全角- 参数:
input- String.- 返回:
- 全角字符串.
-
toSBC
半角转全角- 参数:
input- StringnotConvertSet- 不替换的字符集合- 返回:
- 全角字符串.
-
toDBC
全角转半角- 参数:
input- String.- 返回:
- 半角字符串
-
toDBC
替换全角为半角- 参数:
text- 文本notConvertSet- 不替换的字符集合- 返回:
- 替换后的字符
-
wrap
原始类转为包装类,非原始类返回原类- 参数:
clazz- 原始类- 返回:
- 包装类
- 另请参阅:
-
unWrap
包装类转为原始类,非包装类返回原类- 参数:
clazz- 包装类- 返回:
- 原始类
- 另请参阅:
-
intToByte
public static byte intToByte(int intValue) int转byte- 参数:
intValue- int值- 返回:
- byte值
-
byteToUnsignedInt
public static int byteToUnsignedInt(byte byteValue) byte转无符号int- 参数:
byteValue- byte值- 返回:
- 无符号int值
-
bytesToShort
public static short bytesToShort(byte[] bytes) byte数组转short- 参数:
bytes- byte数组- 返回:
- short值
-
shortToBytes
public static byte[] shortToBytes(short shortValue) short转byte数组- 参数:
shortValue- short值- 返回:
- byte数组
-
bytesToInt
public static int bytesToInt(byte[] bytes) byte[]转int值- 参数:
bytes- byte数组- 返回:
- int值
-
intToBytes
public static byte[] intToBytes(int intValue) int转byte数组- 参数:
intValue- int值- 返回:
- byte数组
-
longToBytes
public static byte[] longToBytes(long longValue) long转byte数组
from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java- 参数:
longValue- long值- 返回:
- byte数组
-
bytesToLong
public static long bytesToLong(byte[] bytes) byte数组转long
from: https://stackoverflow.com/questions/4485128/how-do-i-convert-long-to-byte-and-back-in-java- 参数:
bytes- byte数组- 返回:
- long值
-