public final class Converter extends Object
`Converter.convert2*()` methods: If `null` passed in, primitive 'logical zero' is returned. Example: `Converter.convert(null, boolean.class)` returns `false`.
`Converter.convertTo*()` methods: if `null` passed in, `null` is returned. Allows "tri-state" Boolean. Example: `Converter.convert(null, Boolean.class)` returns `null`.
`Converter.convert()` converts using `convertTo*()` methods for primitive wrappers, and `convert2*()` methods for primitives.
Modifier and Type | Class and Description |
---|---|
protected static interface |
Converter.Work<T> |
Modifier and Type | Field and Description |
---|---|
static BigDecimal |
BIG_DECIMAL_ZERO |
static BigInteger |
BIG_INTEGER_ZERO |
static Byte |
BYTE_ONE |
static Byte |
BYTE_ZERO |
static Double |
DOUBLE_ONE |
static Double |
DOUBLE_ZERO |
static Float |
FLOAT_ONE |
static Float |
FLOAT_ZERO |
static Integer |
INTEGER_ONE |
static Integer |
INTEGER_ZERO |
static Long |
LONG_ONE |
static Long |
LONG_ZERO |
static Short |
SHORT_ONE |
static Short |
SHORT_ZERO |
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 |
convert2AtomicBoolean(Object fromInstance)
Convert from the passed in instance to an AtomicBoolean.
|
static AtomicInteger |
convert2AtomicInteger(Object fromInstance)
Convert from the passed in instance to an AtomicInteger.
|
static AtomicLong |
convert2AtomicLong(Object fromInstance)
Convert from the passed in instance to an AtomicLong.
|
static BigDecimal |
convert2BigDecimal(Object fromInstance)
Convert from the passed in instance to a BigDecimal.
|
static BigInteger |
convert2BigInteger(Object fromInstance)
Convert from the passed in instance to a BigInteger.
|
static boolean |
convert2boolean(Object fromInstance)
Convert from the passed in instance to a boolean.
|
static byte |
convert2byte(Object fromInstance)
Convert from the passed in instance to a byte.
|
static char |
convert2char(Object fromInstance)
Convert from the passed in instance to a char.
|
static double |
convert2double(Object fromInstance)
Convert from the passed in instance to a double.
|
static float |
convert2float(Object fromInstance)
Convert from the passed in instance to a float.
|
static int |
convert2int(Object fromInstance)
Convert from the passed in instance to an int.
|
static long |
convert2long(Object fromInstance)
Convert from the passed in instance to an long.
|
static short |
convert2short(Object fromInstance)
Convert from the passed in instance to a short.
|
static String |
convert2String(Object fromInstance)
Convert from the passed in instance to a String.
|
static AtomicBoolean |
convertToAtomicBoolean(Object fromInstance)
Convert from the passed in instance to an AtomicBoolean.
|
static AtomicInteger |
convertToAtomicInteger(Object fromInstance)
Convert from the passed in instance to an AtomicInteger.
|
static AtomicLong |
convertToAtomicLong(Object fromInstance)
Convert from the passed in instance to an AtomicLong.
|
static BigDecimal |
convertToBigDecimal(Object fromInstance)
Convert from the passed in instance to a BigDecimal.
|
static BigInteger |
convertToBigInteger(Object fromInstance)
Convert from the passed in instance to a BigInteger.
|
static Boolean |
convertToBoolean(Object fromInstance)
Convert from the passed in instance to a Boolean.
|
static Byte |
convertToByte(Object fromInstance)
Convert from the passed in instance to a Byte.
|
static Calendar |
convertToCalendar(Object fromInstance)
Convert from the passed in instance to a Calendar.
|
static Character |
convertToCharacter(Object fromInstance)
Convert from the passed in instance to a Character.
|
static Date |
convertToDate(Object fromInstance)
Convert from the passed in instance to a Date.
|
static Double |
convertToDouble(Object fromInstance)
Convert from the passed in instance to a Double.
|
static Float |
convertToFloat(Object fromInstance)
Convert from the passed in instance to a Float.
|
static Integer |
convertToInteger(Object fromInstance)
Convert from the passed in instance to an Integer.
|
static LocalDate |
convertToLocalDate(Object fromInstance) |
static LocalDateTime |
convertToLocalDateTime(Object fromInstance) |
static Long |
convertToLong(Object fromInstance)
Convert from the passed in instance to a Long.
|
static Short |
convertToShort(Object fromInstance)
Convert from the passed in instance to a Short.
|
static Date |
convertToSqlDate(Object fromInstance)
Convert from the passed in instance to a java.sql.Date.
|
static String |
convertToString(Object fromInstance)
Convert from the passed in instance to a String.
|
static Timestamp |
convertToTimestamp(Object fromInstance)
Convert from the passed in instance to a Timestamp.
|
static ZonedDateTime |
convertToZonedDateTime(Object fromInstance) |
static long |
localDateTimeToMillis(LocalDateTime localDateTime) |
static long |
localDateToMillis(LocalDate localDate) |
static long |
zonedDateTimeToMillis(ZonedDateTime zonedDateTime) |
public static final Byte BYTE_ZERO
public static final Byte BYTE_ONE
public static final Short SHORT_ZERO
public static final Short SHORT_ONE
public static final Integer INTEGER_ZERO
public static final Integer INTEGER_ONE
public static final Long LONG_ZERO
public static final Long LONG_ONE
public static final Float FLOAT_ZERO
public static final Float FLOAT_ONE
public static final Double DOUBLE_ZERO
public static final Double DOUBLE_ONE
public static final BigDecimal BIG_DECIMAL_ZERO
public static final BigInteger BIG_INTEGER_ZERO
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, BigDecimal.class, and
the Atomic classes. 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 String convert2String(Object fromInstance)
public static String convertToString(Object fromInstance)
public static BigDecimal convert2BigDecimal(Object fromInstance)
public static BigDecimal convertToBigDecimal(Object fromInstance)
public static BigInteger convert2BigInteger(Object fromInstance)
public static BigInteger convertToBigInteger(Object fromInstance)
public static Date convertToSqlDate(Object fromInstance)
public static Timestamp convertToTimestamp(Object fromInstance)
public static Date convertToDate(Object fromInstance)
public static LocalDateTime convertToLocalDateTime(Object fromInstance)
public static ZonedDateTime convertToZonedDateTime(Object fromInstance)
public static Calendar convertToCalendar(Object fromInstance)
public static char convert2char(Object fromInstance)
public static Character convertToCharacter(Object fromInstance)
public static byte convert2byte(Object fromInstance)
public static Byte convertToByte(Object fromInstance)
public static short convert2short(Object fromInstance)
public static Short convertToShort(Object fromInstance)
public static int convert2int(Object fromInstance)
public static Integer convertToInteger(Object fromInstance)
public static long convert2long(Object fromInstance)
public static Long convertToLong(Object fromInstance)
public static float convert2float(Object fromInstance)
public static Float convertToFloat(Object fromInstance)
public static double convert2double(Object fromInstance)
public static Double convertToDouble(Object fromInstance)
public static boolean convert2boolean(Object fromInstance)
public static Boolean convertToBoolean(Object fromInstance)
public static AtomicInteger convert2AtomicInteger(Object fromInstance)
public static AtomicInteger convertToAtomicInteger(Object fromInstance)
public static AtomicLong convert2AtomicLong(Object fromInstance)
public static AtomicLong convertToAtomicLong(Object fromInstance)
public static AtomicBoolean convert2AtomicBoolean(Object fromInstance)
public static AtomicBoolean convertToAtomicBoolean(Object fromInstance)
public static long localDateToMillis(LocalDate localDate)
localDate
- A Java LocalDatepublic static long localDateTimeToMillis(LocalDateTime localDateTime)
localDateTime
- A Java LocalDateTimepublic static long zonedDateTimeToMillis(ZonedDateTime zonedDateTime)
zonedDateTime
- A Java ZonedDateTimeCopyright © 2023. All rights reserved.