public final class ObjectUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static org.apache.empire.commons.ObjectUtils.NoValue |
NO_VALUE
Constant that defines a object of type NoValue.
|
| Modifier and Type | Method and Description |
|---|---|
static <T> List<T> |
arrayToList(Class<T> t,
T[] array)
Converts an array to a list
|
static <T> T |
coalesce(T preferred,
T alternative)
Checks whether a preferred value is valid and returns an alternative value if not.
|
static <T> T[] |
combine(T[] left,
T[] right)
combines two arrays
|
static int |
compare(Object o1,
Object o2)
Compares two objects for equality
|
static boolean |
compareEqual(ColumnExpr expr,
ColumnExpr other)
Compares two ColumnExpr for equality
|
static boolean |
compareEqual(Object[] array1,
Object[] array2)
Compares two arrays for equality
|
static boolean |
compareEqual(Object o1,
Object o2)
Compares two objects for equality
|
static <T> boolean |
contains(T[] array,
T item)
returns whether or not a array contains a certain item
performs a simple (==) comparison (fast)
|
static <T> List<T> |
convert(Class<T> t,
Collection<? extends T> source)
Generic conversion function that will convert a list to another list type.
|
static <T> T |
convert(Class<T> c,
Object v)
Generic conversion function that will convert a object to another value type.
|
static String |
formatDate(Date date,
boolean withTime)
Formats a given date object to a standard ISO date string.
|
static boolean |
getBoolean(Object v)
Converts an object value to a boolean.
|
static Date |
getDate(Object v)
Converts an object value to a Date.
|
static Date |
getDate(Object v,
Locale locale)
Converts an object value to a Date.
|
static BigDecimal |
getDecimal(Object v)
Converts an object value to a BigDecimal.
|
static BigDecimal |
getDecimal(Object v,
BigDecimal defValue)
Converts an object value to a BigDecimal.
|
static double |
getDouble(Object v)
Converts an object value to a double.
|
static double |
getDouble(Object v,
double defValue)
Converts an object value to a double.
|
static <T extends Enum<?>> |
getEnum(Class<T> enumType,
Object value)
Converts an object to an enum of the given type
|
static <T extends Enum<?>> |
getEnumByName(Class<T> enumType,
String name)
find by name
|
static Object |
getEnumValue(Enum<?> enumValue,
boolean isNumeric)
Convert Enum to Object
|
static int |
getInteger(Object v)
Converts an object value to an integer.
|
static int |
getInteger(Object v,
int defValue)
Converts an object value to an integer.
|
static LocalDate |
getLocalDate(Object v)
Converts an object value to a Date.
|
static LocalDateTime |
getLocalDateTime(Object v)
Converts an object value to a Date.
|
static long |
getLong(Object v)
Converts an object value to a long.
|
static long |
getLong(Object v,
long defValue)
Converts an object value to a long.
|
static String |
getString(Enum<?> enumValue)
Converts an Enum to a String
|
static String |
getString(Object value)
Converts an Object to a String
|
static <T> int |
indexOf(T[] array,
T item)
returns whether or not a array contains a certain item
performs a simple (==) comparison (fast)
|
static boolean |
isAssignmentCompatible(Class<?> target,
Class<?> source)
Checks if a class is assignment compatible with another class
|
static boolean |
isEmpty(Object o)
Checks whether an object has no value.
|
static boolean |
isNonZero(Number value)
Checks whether a number is NOT null or zero
|
static boolean |
isNotEmpty(Object o)
Checks whether an object has a value.
|
static boolean |
isWrapper(Object object)
Checks whether a object implements the Unwrappable interface and is also a wrapper
If the object does not Implement the Interface or is not a wrapper then false is returned
|
static boolean |
isZero(Number value)
Checks whether a number is null or zero
|
static int |
lengthOf(Object o)
returns the string length of an object
|
static <T> T[] |
toArray(Class<T> t,
T... values)
Converts varArgs to an array
|
static Date |
toDate(Object v)
Converts an object value to a Date.
|
static BigDecimal |
toDecimal(Object v)
converts an object to a decimal.
|
static double |
toDouble(Object v)
converts an object to a double.
|
static int |
toInteger(Object v)
converts an object to an integer.
|
static long |
toLong(Object v)
converts an object to a long.
|
static String[] |
toStringArray(Object[] objArray,
String defValue)
Converts an Object array to a String array.
|
static <T> T |
unwrap(T object)
Unwraps an object implementing the Unwrappable interface
If the object does not Implement the Interface or is not a wrapper then the object itself is returned
|
public static final org.apache.empire.commons.ObjectUtils.NoValue NO_VALUE
public static boolean isEmpty(Object o)
o - the object to checkpublic static boolean isNotEmpty(Object o)
o - the object to checkpublic static boolean isZero(Number value)
value - the number to checkpublic static boolean isNonZero(Number value)
value - the number to checkpublic static int lengthOf(Object o)
o - the object to checkpublic static boolean compareEqual(Object o1, Object o2)
o1 - the first objecto2 - the second objectpublic static boolean compareEqual(Object[] array1, Object[] array2)
array1 - the first arrayarray2 - the second arraypublic static boolean compareEqual(ColumnExpr expr, ColumnExpr other)
expr - a column expressionother - a column expressionpublic static int compare(Object o1, Object o2)
o1 - the first objecto2 - the second objectpublic static <T> T coalesce(T preferred,
T alternative)
T - the type of the valuespreferred - the preferred return valuealternative - the alternative return value used if the preferred value is nullpublic static int toInteger(Object v)
v - the value to convertpublic static int getInteger(Object v, int defValue)
If the object value supplied is null or if conversion is not possible then the default value is returned.
v - the obect to convertdefValue - the default value if o is null or conversion is not possiblepublic static int getInteger(Object v)
If the object value supplied is null or if conversion is not possible then 0 is returned.
v - the object value to convertpublic static long toLong(Object v)
v - the value to convertpublic static long getLong(Object v, long defValue)
If the object value supplied is null or if conversion is not possible then the default value is returned.
v - the obect to convertdefValue - the default value if o is null or conversion is not possiblepublic static long getLong(Object v)
If the object value supplied is null or if conversion is not possible then 0 is returned.
v - the object value to convertpublic static double toDouble(Object v)
v - the value to convertpublic static double getDouble(Object v, double defValue)
If the object value supplied is null or if conversion is not possible then defValue is returned.
v - the object value to convertdefValue - the default valuepublic static double getDouble(Object v)
If the object value supplied is null or if conversion is not possible then 0.0 is returned.
v - the object value to convertpublic static BigDecimal toDecimal(Object v)
v - the value to convertpublic static BigDecimal getDecimal(Object v, BigDecimal defValue)
If the object value supplied is null or if conversion is not possible then defValue is returned.
v - the object value to convertdefValue - the default valuepublic static BigDecimal getDecimal(Object v)
If the object value supplied is null or if conversion is not possible then 0.0 is returned.
v - the object value to convertpublic static boolean getBoolean(Object v)
If the object value supplied is null or if conversion is not possible then false is returned.
v - the object to convertpublic static <T extends Enum<?>> T getEnum(Class<T> enumType, Object value)
T - the type of the enumenumType - the enum typevalue - the value to convertpublic static <T extends Enum<?>> T getEnumByName(Class<T> enumType, String name)
T - the type of the enumenumType - the enum typename - the enum namepublic static Object getEnumValue(Enum<?> enumValue, boolean isNumeric)
enumValue - the enumisNumeric - flag if number or string is requiredpublic static String getString(Enum<?> enumValue)
enumValue - the enumpublic static String getString(Object value)
value - the value to convertpublic static Date toDate(Object v) throws ParseException
v - the object to convertParseExceptionpublic static Date getDate(Object v, Locale locale)
If the object value supplied is null or if conversion is not possible then null is returned.
v - the object to convertlocale - the locale used for conversionpublic static Date getDate(Object v)
v - the object to convertpublic static LocalDate getLocalDate(Object v)
v - the object to convertpublic static LocalDateTime getLocalDateTime(Object v)
v - the object to convertpublic static String formatDate(Date date, boolean withTime)
date - the date to be formatedwithTime - indicates whether the date string should include the time or notpublic static <T> T convert(Class<T> c, Object v) throws ClassCastException
T - the type to convert toc - the class type to convert tov - the object to convertClassCastException - if the object is not null and is not assignable to the type T.public static boolean isAssignmentCompatible(Class<?> target, Class<?> source)
target - the target classsource - the source classpublic static <T> List<T> convert(Class<T> t, Collection<? extends T> source)
T - the type of elementst - the type classsource - the source collection@SafeVarargs public static <T> T[] toArray(Class<T> t, T... values)
T - the type of elementst - the type of the arrayvalues - the array valuespublic static <T> List<T> arrayToList(Class<T> t, T[] array)
T - the type of elementst - the type of the list itemsarray - the array to be convertedpublic static String[] toStringArray(Object[] objArray, String defValue)
objArray - the object array to convertdefValue - default value which will be set for all null objectspublic static boolean isWrapper(Object object)
object - the object to checkpublic static <T> T unwrap(T object)
T - the type of the objectobject - the object to unwrappublic static <T> int indexOf(T[] array,
T item)
T - the type of the objectarray - the array to searchitem - the item to search forpublic static <T> boolean contains(T[] array,
T item)
T - the type of elementsarray - the array to searchitem - the item to search forpublic static <T> T[] combine(T[] left,
T[] right)
T - the type of the array itemsleft - the left arrayright - the right arrayCopyright © 2008–2023 Apache Software Foundation. All rights reserved.