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> T |
coalesce(T preferred,
T alternative)
Checks whether a preferred value is valid and returns an alternative value if not.
|
static boolean |
compareEqual(Object o1,
Object o2)
Compares two objects for equality
|
static <T> boolean |
contains(T[] array,
T item)
returns wheter or not a array contains a certain item
|
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 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 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 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 boolean |
isAssignmentCompatible(Class<?> target,
Class<?> source) |
static boolean |
isEmpty(Object o)
Checks whether an object has no value.
|
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.
|
public static final org.apache.empire.commons.ObjectUtils.NoValue NO_VALUE
public static boolean isEmpty(Object o)
o
- the object to checkpublic static boolean compareEqual(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 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 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)
public static <T> List<T> convert(Class<T> t, Collection<? extends T> source)
T
- the type of elementst
- the type classsource
- the source collectionpublic static String[] toStringArray(Object[] objArray, String defValue)
objArray
- the object array to convertdefValue
- default value which will be set for all null objectspublic static <T> boolean contains(T[] array, T item)
T
- the ype of the objects in the arrayarray
- the array to searchitem
- the item to search forCopyright © 2008–2017 Apache Software Foundation. All rights reserved.