public class ValueUtils extends Object
Modifier and Type | Field and Description |
---|---|
protected static String |
DATE_FORMAT |
protected static ThreadLocal<SimpleDateFormat> |
dateOnlyFormatter |
protected static String |
DATETIME_FORMAT |
protected static ThreadLocal<SimpleDateFormat> |
dateTimeFormatter |
Modifier | Constructor and Description |
---|---|
protected |
ValueUtils() |
Modifier and Type | Method and Description |
---|---|
int |
compare(Object o1,
Object o2)
Compares two objects for equality
|
boolean |
compareEqual(Object o1,
Object o2)
Compares two objects for equality
|
Object |
convertToData(DataType dataType,
Object value)
Converts a value to a specific DataType
The returned value is used for generating SQL statements
|
<T> T |
convertToJava(Class<T> c,
Object v)
Generic conversion function that will convert a object to another value type.
|
String |
enumToString(Enum<?> enumValue)
Converts an Enum to a String
|
Object |
enumToValue(Enum<?> enumValue,
boolean isNumeric)
Convert Enum to Object
|
String |
formatDate(Date date,
boolean withTime)
Formats a given date object to a standard ISO date string.
|
boolean |
isEmpty(Object o)
Checks whether an object has no value.
|
boolean |
isZero(Number value)
Checks whether a number is null or zero
|
int |
lengthOf(Object o)
returns the string length of an object
|
boolean |
toBoolean(Object v,
boolean defValue)
Converts an object value to a boolean.
|
Date |
toDate(Object v)
Converts an object value to a Date.
|
BigDecimal |
toDecimal(Object v)
converts an object to a decimal.
|
double |
toDouble(Object v)
converts an object to a double.
|
<T extends Enum<?>> |
toEnum(Class<T> enumType,
Object value)
Converts an object to an enum of the given type
|
<T extends Enum<?>> |
toEnumByName(Class<T> enumType,
String name)
find by name
|
int |
toInteger(Object v)
converts an object to an integer.
|
LocalDate |
toLocalDate(Object v)
Converts an object value to a Date.
|
LocalDateTime |
toLocalDateTime(Object v)
Converts an object value to a Date.
|
long |
toLong(Object v)
converts an object to a long.
|
String |
toString(Object value)
Converts an Object to a String
|
Timestamp |
toTimestamp(Object v)
Converts an object value to a Timestamp.
|
protected static final String DATE_FORMAT
protected static final String DATETIME_FORMAT
protected static final ThreadLocal<SimpleDateFormat> dateOnlyFormatter
protected static final ThreadLocal<SimpleDateFormat> dateTimeFormatter
public boolean isEmpty(Object o)
o
- the object to checkpublic boolean isZero(Number value)
value
- the number to checkpublic boolean compareEqual(Object o1, Object o2)
o1
- the first objecto2
- the second objectpublic int compare(Object o1, Object o2)
o1
- the first objecto2
- the second objectpublic int toInteger(Object v)
v
- the value to convertpublic long toLong(Object v)
v
- the value to convertpublic double toDouble(Object v)
v
- the value to convertpublic BigDecimal toDecimal(Object v)
v
- the value to convertpublic boolean toBoolean(Object v, boolean defValue)
If the object value supplied is empty then the defValue is returned Numbers are considered true if they are not equal to zero String are considered true only if the string is "Y" or "true"
v
- the object to convertdefValue
- the default valuepublic <T extends Enum<?>> T toEnum(Class<T> enumType, Object value)
T
- the type of the enumenumType
- the enum typevalue
- the value to convertpublic <T extends Enum<?>> T toEnumByName(Class<T> enumType, String name)
T
- the type of the enumenumType
- the enum typename
- the enum namepublic Object enumToValue(Enum<?> enumValue, boolean isNumeric)
enumValue
- the enumisNumeric
- flag if number or string is requiredpublic String enumToString(Enum<?> enumValue)
enumValue
- the enumpublic String toString(Object value)
value
- the value to convertpublic int lengthOf(Object o)
o
- the object to checkpublic Date toDate(Object v) throws ParseException
v
- the object to convertParseException
- exception if date cannot be parsed from stringpublic LocalDate toLocalDate(Object v)
v
- the object to convertpublic LocalDateTime toLocalDateTime(Object v)
v
- the object to convertpublic Timestamp toTimestamp(Object v)
v
- the object to convertpublic String formatDate(Date date, boolean withTime)
date
- the date to be formatedwithTime
- indicates whether the date string should include the time or notpublic <T> T convertToJava(Class<T> c, Object v) throws ClassCastException
T
- the java typec
- the class type to convert tov
- the value to convertClassCastException
- if the object is not null and is not assignable to the type T.Copyright © 2008–2023 Apache Software Foundation. All rights reserved.