public final class Converter extends Object
Modifier and Type | Method and Description |
---|---|
static <T> T |
convert(Object fromInstance,
Class<T> toType)
Turn the passed in value to the class indicated.
|
static AtomicBoolean |
convertToAtomicBoolean(Object fromInstance) |
static AtomicInteger |
convertToAtomicInteger(Object fromInstance) |
static AtomicLong |
convertToAtomicLong(Object fromInstance) |
static BigDecimal |
convertToBigDecimal(Object fromInstance) |
static BigInteger |
convertToBigInteger(Object fromInstance) |
static Boolean |
convertToBoolean(Object fromInstance) |
static Byte |
convertToByte(Object fromInstance) |
static Date |
convertToDate(Object fromInstance) |
static Double |
convertToDouble(Object fromInstance) |
static Float |
convertToFloat(Object fromInstance) |
static Integer |
convertToInteger(Object fromInstance) |
static Long |
convertToLong(Object fromInstance) |
static Short |
convertToShort(Object fromInstance) |
static Date |
convertToSqlDate(Object fromInstance) |
static String |
convertToString(Object fromInstance) |
static Timestamp |
convertToTimestamp(Object fromInstance) |
public static <T> T convert(Object fromInstance, Class<T> toType)
Examples: Long x = convert("35", Long.class); Date d = convert("2015/01/01", Date.class) int y = convert(45.0, int.class) String date = convert(date, String.class) String date = convert(calendar, String.class) Short t = convert(true, short.class); // returns (short) 1 or (short) 0 Long date = convert(calendar, long.class); // get calendar's time into long
fromInstance
- A value used to create the targetType, even though it may
not (most likely will not) be the same data type as the targetTypetoType
- Class which indicates the targeted (final) data type.
Please note that in addition to the 8 Java primitives, the targeted class
can also be Date.class, String.class, BigInteger.class, and BigDecimal.class.
The primitive class can be either primitive class or primitive wrapper class,
however, the returned value will always [obviously] be a primitive wrapper.public static BigDecimal convertToBigDecimal(Object fromInstance)
public static BigInteger convertToBigInteger(Object fromInstance)
public static AtomicInteger convertToAtomicInteger(Object fromInstance)
public static AtomicLong convertToAtomicLong(Object fromInstance)
public static AtomicBoolean convertToAtomicBoolean(Object fromInstance)
Copyright © 2019. All rights reserved.